···55import { VERCEL_REVALIDATE } from '@/next.constants.mjs';
66import { dynamicRouter } from '@/next.dynamic.mjs';
77import { defaultLocale } from '@/next.locales.mjs';
88+import { parseRichTextIntoPlainText } from '@/util/stringUtils';
89910// This is the Route Handler for the `GET` method which handles the request
1011// for a digest and metadata of all existing pages on Node.js Website
···3031 // grabs the markdown content and cleanses it by removing HTML/JSX tags
3132 // removing empty/blank lines or lines just with spaces and trims each line
3233 // from leading and trailing paddings/spaces
3333- const cleanedContent = matter(source)
3434- .content.replace(/<[^>]+>/gm, '')
3535- .replace(/^\s*\n/gm, '')
3636- .replace(/^[ ]+|[ ]+$/gm, '');
3434+ const cleanedContent = parseRichTextIntoPlainText(matter(source).content);
37353836 // Deflates a String into a base64 string-encoded (zlib compressed)
3937 const deflatedSource = deflateSync(cleanedContent).toString('base64');
+20
util/stringUtils.ts
···11export const getAcronymFromString = (str: string) =>
22 [...(str.trim().match(/\b(\w)/g) || '')].join('').toUpperCase();
33+44+export const parseRichTextIntoPlainText = (richText: string) =>
55+ richText
66+ // replaces JSX and HTML and their properties with an empty string
77+ // keeping only the content left
88+ .replace(/<[^>]+>/gm, '')
99+ // replaces Markdown links with their text content
1010+ .replace(/\[([^\]]+)\]\([^)]+\)/gm, '$1')
1111+ // replaces Markdown lists with their content
1212+ .replace(/^[*-] (.*)$/gm, '$1')
1313+ // replaces Markdown headings with their content
1414+ .replace(/^#+ (.*)$/gm, '$1')
1515+ // replaces Markdown underscore, bold and italic with their content
1616+ .replace(/[_*]{1,2}(.*)[_*]{1,2}/gm, '$1')
1717+ // replaces Markdown multiline codeblocks with their content
1818+ .replace(/```.+?```/gms, '')
1919+ // replaces emppty lines or lines just with spaces with an empty string
2020+ .replace(/^\s*\n/gm, '')
2121+ // replaces leading and trailing spaces from each line with an empty string
2222+ .replace(/^[ ]+|[ ]+$/gm, '');