11const fs = require ( 'fs' )
22const path = require ( 'path' )
3- const matter = require ( 'gray-matter' )
43const glob = require ( 'glob' )
4+ const matter = require ( 'gray-matter' )
5+
6+ // We generate this at build to allow us to access from edge functions like dynamic OG images (og.js)
57
6- // Get list of all article and commentary folders
78const articles = fs
89 . readdirSync ( path . join ( process . cwd ( ) , 'articles' ) )
910 . filter ( ( p ) => p . match ( / ^ [ \w | \d | - ] + $ / ) )
@@ -12,18 +13,17 @@ const commentary = fs
1213 . readdirSync ( path . join ( process . cwd ( ) , 'commentary' ) )
1314 . filter ( ( p ) => p . match ( / ^ [ \w | \d | - ] + $ / ) )
1415
15- // Helper function to get metadata for articles and commentary
1616const getMetadata = ( ids , folder ) => {
1717 const directory = path . join ( process . cwd ( ) , folder )
1818 return ids
1919 . map ( ( id ) => {
2020 const source = fs . readFileSync ( path . join ( directory , `${ id } /index.md` ) )
2121 let references
2222 try {
23- const referencesBuffer = fs . readFileSync (
23+ references = fs . readFileSync (
2424 path . join ( directory , `${ id } /references.json` )
2525 )
26- references = JSON . parse ( referencesBuffer . toString ( ) )
26+ references = JSON . parse ( references )
2727 } catch {
2828 references = { }
2929 }
@@ -36,9 +36,7 @@ const getMetadata = (ids, folder) => {
3636 path : `${ directory } /${ id } /index.md` ,
3737 }
3838 } )
39- . sort ( ( a , b ) => {
40- return new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( )
41- } )
39+ . sort ( ( a , b ) => new Date ( b . date ) - new Date ( a . date ) )
4240 . map ( ( meta , idx ) => ( { ...meta , number : ids . length - 1 - idx } ) )
4341}
4442
0 commit comments