14
14
*
15
15
*/
16
16
17
- import { writeFileSync , readdirSync , existsSync , readFileSync , mkdirSync } from "fs" ;
17
+ import { writeFileSync , readdirSync , existsSync , mkdirSync } from "fs" ;
18
18
import { join } from "path" ;
19
19
import * as assert from "assert" ;
20
20
import { read as readMarkdownFile } from "gray-matter" ;
@@ -23,8 +23,6 @@ import * as prettier from "prettier";
23
23
import * as remark from "remark" ;
24
24
import * as remarkHTML from "remark-html" ;
25
25
26
- const parseMarkdown = ( md : string ) => remark ( ) . use ( remarkHTML ) . processSync ( md ) ;
27
-
28
26
const languages = readdirSync ( join ( __dirname , ".." , "copy" ) ) . filter ( ( f ) => ! f . startsWith ( "." ) ) ;
29
27
30
28
const outputDir = join ( __dirname , ".." , "output" ) ;
@@ -34,6 +32,7 @@ languages.forEach((lang) => {
34
32
const locale = join ( __dirname , ".." , "copy" , lang ) ;
35
33
const fallbackLocale = join ( __dirname , ".." , "copy" , "en" ) ;
36
34
35
+ const languageMeta = { terms : [ ] } ;
37
36
const markdownChunks : string [ ] = [ ] ;
38
37
39
38
const glossaryTerms = readdirSync ( join ( __dirname , ".." , "copy" , "en" ) ) . filter (
@@ -65,19 +64,26 @@ languages.forEach((lang) => {
65
64
const md = readMarkdownFile ( glossaryMdPath ) ;
66
65
assert . ok ( md . data . display , "No display data for term: " + filename ) ;
67
66
68
- markdownChunks . push ( `\n### ${ md . data . display } ` ) ;
67
+ const termID = filename . split ( "." ) [ 0 ] . toLowerCase ( ) ;
68
+ const termDisplay = md . data . display ;
69
+ languageMeta . terms . push ( { display : termDisplay , id : termID } ) ;
70
+
71
+ const title = `<h3 id='${ termID } ' ><a href='#${ termID } ' name='${ termDisplay } ' aria-label="Link to the section ${ termDisplay } " aria-labelledby='${ termID } '>#</a> ${ termDisplay } </h3>` ;
72
+ markdownChunks . push ( title ) ;
73
+
69
74
markdownChunks . push ( md . content ) ;
70
75
} ) ;
71
76
} ) ;
72
77
} ) ;
73
78
74
- // const intro = parseMarkdown(readFileSync(getPathInLocale("intro.md"), "utf8"));
75
- // markdownChunks.push(intro + "\n");
76
-
77
79
// Write the Markdown and JSON
78
80
const markdown = prettier . format ( markdownChunks . join ( "\n" ) , { filepath : "index.md" } ) ;
79
81
const mdPath = join ( __dirname , ".." , "output" , lang + ".md" ) ;
80
82
writeFileSync ( mdPath , markdown ) ;
83
+
84
+ const jsonInfo = prettier . format ( JSON . stringify ( languageMeta ) , { filepath : "index.json" } ) ;
85
+ const jsonPath = join ( __dirname , ".." , "output" , lang + ".json" ) ;
86
+ writeFileSync ( jsonPath , jsonInfo ) ;
81
87
} ) ;
82
88
83
89
writeFileSync ( join ( __dirname , ".." , "output" , "languages.json" ) , JSON . stringify ( { languages } ) ) ;
0 commit comments