@@ -10,44 +10,52 @@ import { parseRichTextIntoPlainText } from '#site/util/string';
1010// for a digest and metadata of all existing pages on Node.js Website
1111// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers
1212export const GET = async ( ) => {
13+ // Retrieves all available routes for the default locale
1314 const allAvailbleRoutes = await dynamicRouter . getRoutesByLanguage (
1415 defaultLocale . code
1516 ) ;
1617
17- const availablePagesMetadata = allAvailbleRoutes
18- . filter ( route => ! route . startsWith ( 'blog' ) )
19- . map ( async pathname => {
20- const { source, filename } = await dynamicRouter . getMarkdownFile (
21- defaultLocale . code ,
22- pathname
23- ) ;
18+ // We exclude the blog routes from the available pages metadata
19+ // as they are generated separately and are not part of the static pages
20+ // and are not part of the static pages metadata
21+ const routesExceptBlog = allAvailbleRoutes . filter (
22+ route => ! route . startsWith ( 'blog' )
23+ ) ;
24+
25+ const availablePagesMetadata = routesExceptBlog . map ( async pathname => {
26+ const { source, filename } = await dynamicRouter . getMarkdownFile (
27+ defaultLocale . code ,
28+ pathname
29+ ) ;
30+
31+ // Gets the title and the Description from the Page Metadata
32+ const { title, description } = await dynamicRouter . getPageMetadata (
33+ defaultLocale . code ,
34+ pathname
35+ ) ;
2436
25- // Gets the title and the Description from the Page Metadata
26- const { title , description } = await dynamicRouter . getPageMetadata (
27- defaultLocale . code ,
28- pathname
29- ) ;
37+ // Parser the Markdown source with `gray-matter` and then only
38+ // grabs the markdown content and cleanses it by removing HTML/JSX tags
39+ // removing empty/blank lines or lines just with spaces and trims each line
40+ // from leading and trailing paddings/spaces
41+ const cleanedContent = parseRichTextIntoPlainText ( matter ( source ) . content ) ;
3042
31- // Parser the Markdown source with `gray-matter` and then only
32- // grabs the markdown content and cleanses it by removing HTML/JSX tags
33- // removing empty/blank lines or lines just with spaces and trims each line
34- // from leading and trailing paddings/spaces
35- const cleanedContent = parseRichTextIntoPlainText ( matter ( source ) . content ) ;
43+ // Deflates a String into a base64 string-encoded (zlib compressed)
44+ const content = deflateSync ( cleanedContent ) . toString ( 'base64' ) ;
3645
37- // Deflates a String into a base64 string-encoded (zlib compressed)
38- const content = deflateSync ( cleanedContent ) . toString ( 'base64' ) ;
46+ // Returns metadata of each page available on the Website
47+ return {
48+ filename,
49+ pathname,
50+ title,
51+ description,
52+ content,
53+ } ;
54+ } ) ;
3955
40- // Returns metadata of each page available on the Website
41- return {
42- filename,
43- pathname,
44- title,
45- description,
46- content,
47- } ;
48- } ) ;
56+ const data = await Promise . all ( availablePagesMetadata ) ;
4957
50- return Response . json ( await Promise . all ( availablePagesMetadata ) ) ;
58+ return Response . json ( data ) ;
5159} ;
5260
5361// This function generates the static paths that come from the dynamic segments
0 commit comments