The Node.js® Website
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: updated string replacement for page-dfata

+22 -4
+2 -4
app/[locale]/next-data/page-data/route.ts
··· 5 5 import { VERCEL_REVALIDATE } from '@/next.constants.mjs'; 6 6 import { dynamicRouter } from '@/next.dynamic.mjs'; 7 7 import { defaultLocale } from '@/next.locales.mjs'; 8 + import { parseRichTextIntoPlainText } from '@/util/stringUtils'; 8 9 9 10 // This is the Route Handler for the `GET` method which handles the request 10 11 // for a digest and metadata of all existing pages on Node.js Website ··· 30 31 // grabs the markdown content and cleanses it by removing HTML/JSX tags 31 32 // removing empty/blank lines or lines just with spaces and trims each line 32 33 // from leading and trailing paddings/spaces 33 - const cleanedContent = matter(source) 34 - .content.replace(/<[^>]+>/gm, '') 35 - .replace(/^\s*\n/gm, '') 36 - .replace(/^[ ]+|[ ]+$/gm, ''); 34 + const cleanedContent = parseRichTextIntoPlainText(matter(source).content); 37 35 38 36 // Deflates a String into a base64 string-encoded (zlib compressed) 39 37 const deflatedSource = deflateSync(cleanedContent).toString('base64');
+20
util/stringUtils.ts
··· 1 1 export const getAcronymFromString = (str: string) => 2 2 [...(str.trim().match(/\b(\w)/g) || '')].join('').toUpperCase(); 3 + 4 + export const parseRichTextIntoPlainText = (richText: string) => 5 + richText 6 + // replaces JSX and HTML and their properties with an empty string 7 + // keeping only the content left 8 + .replace(/<[^>]+>/gm, '') 9 + // replaces Markdown links with their text content 10 + .replace(/\[([^\]]+)\]\([^)]+\)/gm, '$1') 11 + // replaces Markdown lists with their content 12 + .replace(/^[*-] (.*)$/gm, '$1') 13 + // replaces Markdown headings with their content 14 + .replace(/^#+ (.*)$/gm, '$1') 15 + // replaces Markdown underscore, bold and italic with their content 16 + .replace(/[_*]{1,2}(.*)[_*]{1,2}/gm, '$1') 17 + // replaces Markdown multiline codeblocks with their content 18 + .replace(/```.+?```/gms, '') 19 + // replaces emppty lines or lines just with spaces with an empty string 20 + .replace(/^\s*\n/gm, '') 21 + // replaces leading and trailing spaces from each line with an empty string 22 + .replace(/^[ ]+|[ ]+$/gm, '');