Skip to content

Commit

Permalink
fix(*): update read time
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed May 25, 2024
1 parent c251728 commit 476dd14
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Components/Article/MainContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const MainContainer = (props) => {
<GrayText>{timeFormater}</GrayText>
<span>&nbsp;&#183;&nbsp;</span>
<DisplayItem>
{readTime} min read &nbsp; <AiFillStar />
{readTime > 60 ? Math.floor((readTime / 60)) + " Hours " + (readTime % 60) : readTime } min read &nbsp; <AiFillStar />
</DisplayItem>
<span>&nbsp;&#183;&nbsp;</span>
<TextToSpeech text={markdown} />
Expand Down
3 changes: 2 additions & 1 deletion src/Pages/Articles/Article/Article.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RightColumn from "../../../Components/Article/RightColumn";
import MainContainer from "../../../Components/Article/MainContainer";
import { BlogContent } from "../../../Layout/Container/styledArticle";
import axios from "axios";
import { countWords } from "../../../Utils/helperFunctions";

const ArticleItem = () => {
const params = useParams();
Expand Down Expand Up @@ -50,7 +51,7 @@ const ArticleItem = () => {

const timeFormater = moment.utc(createdAt).format("MMMM Do YYYY");
const avgWordsMinRead = 238;
const wordCount = markdown.length + 700;
const wordCount = countWords(markdown);
const readTime = Math.round(wordCount / avgWordsMinRead);
return (
<>
Expand Down
8 changes: 7 additions & 1 deletion src/Utils/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,11 @@ const getBasicAuth = (username, password) => {
return auth;
};

function countWords(text) {
text = text.trim();
const words = text.split(/\s+/);
const wordCount = words.filter((word) => word.length > 0).length;
return wordCount;
}

export { copyTextToClipboard, responsive, sleep, truncate, getBasicAuth };
export { copyTextToClipboard, responsive, sleep, truncate, getBasicAuth, countWords };

0 comments on commit 476dd14

Please sign in to comment.