Skip to content

Commit

Permalink
fix(blog): ignore hidden code blocks when calculating read time (#9302)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Jul 14, 2023
1 parent 8cc92f1 commit 9f237bd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ import { DEFAULT_LOCALE } from "../libs/constants/index.js";
import { memoize } from "../content/utils.js";

const READ_TIME_FILTER = /[\w<>.,!?]+/;
const HIDDEN_CODE_BLOCK_MATCH = /```.*hidden[\s\S]*?```/g;

function calculateReadTime(copy: string): number {
return Math.max(
1,
Math.round(
copy.split(/\s+/).filter((w) => READ_TIME_FILTER.test(w)).length / 220
copy
.replace(HIDDEN_CODE_BLOCK_MATCH, "")
.split(/\s+/)
.filter((w) => READ_TIME_FILTER.test(w)).length / 220
)
);
}
Expand Down

0 comments on commit 9f237bd

Please sign in to comment.