1
1
const fs = require ( 'fs' )
2
2
const path = require ( 'path' )
3
- const matter = require ( 'gray-matter' )
4
3
const 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)
5
7
6
- // Get list of all article and commentary folders
7
8
const articles = fs
8
9
. readdirSync ( path . join ( process . cwd ( ) , 'articles' ) )
9
10
. filter ( ( p ) => p . match ( / ^ [ \w | \d | - ] + $ / ) )
@@ -12,18 +13,17 @@ const commentary = fs
12
13
. readdirSync ( path . join ( process . cwd ( ) , 'commentary' ) )
13
14
. filter ( ( p ) => p . match ( / ^ [ \w | \d | - ] + $ / ) )
14
15
15
- // Helper function to get metadata for articles and commentary
16
16
const getMetadata = ( ids , folder ) => {
17
17
const directory = path . join ( process . cwd ( ) , folder )
18
18
return ids
19
19
. map ( ( id ) => {
20
20
const source = fs . readFileSync ( path . join ( directory , `${ id } /index.md` ) )
21
21
let references
22
22
try {
23
- const referencesBuffer = fs . readFileSync (
23
+ references = fs . readFileSync (
24
24
path . join ( directory , `${ id } /references.json` )
25
25
)
26
- references = JSON . parse ( referencesBuffer . toString ( ) )
26
+ references = JSON . parse ( references )
27
27
} catch {
28
28
references = { }
29
29
}
@@ -36,9 +36,7 @@ const getMetadata = (ids, folder) => {
36
36
path : `${ directory } /${ id } /index.md` ,
37
37
}
38
38
} )
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 ) )
42
40
. map ( ( meta , idx ) => ( { ...meta , number : ids . length - 1 - idx } ) )
43
41
}
44
42
0 commit comments