From 9f237bd5b16f4e4655e1ae783e598e0657b2d884 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Fri, 14 Jul 2023 13:39:08 +0100 Subject: [PATCH] fix(blog): ignore hidden code blocks when calculating read time (#9302) --- build/blog.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build/blog.ts b/build/blog.ts index 1f70ec89141e..17fb51b35a44 100644 --- a/build/blog.ts +++ b/build/blog.ts @@ -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 ) ); }