Skip to content

Commit c5551ab

Browse files
authoredJan 5, 2021
Merge pull request #170 from kevanstannard/syntax-lookup-dynamic-include
Syntax lookup dynamic include
2 parents bd2a478 + f4c479b commit c5551ab

File tree

5 files changed

+125
-312
lines changed

5 files changed

+125
-312
lines changed
 

‎misc_docs/syntax/controlflow_ifelse.mdx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
---
2-
test: "foo"
2+
id: "if-else"
3+
keywords: ["if", "else"]
4+
name: "if / else"
5+
summary: "This is the `if / else` control flow."
6+
category: "controlflow"
37
---
48

59
Use `if / else` expressions to express a value trough a `true` / `false` condition.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"test": "node scripts/test-examples.js && node scripts/test-hrefs.js",
4444
"check-dead-code": "reanalyze -dce",
4545
"check-for-exceptions": "reanalyze -exception",
46-
"update-index": "node scripts/extract-indices.js && node scripts/extract-tocs.js && node -r esm scripts/generate_feed.js > public/blog/feed.xml",
46+
"update-index": "node scripts/extract-indices.js && node scripts/extract-tocs.js && node scripts/extract-syntax.js && node -r esm scripts/generate_feed.js > public/blog/feed.xml",
4747
"now-build": "yarn run build",
4848
"export": "next export",
4949
"start": "next start -p $PORT",

‎scripts/extract-syntax.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const matter = require("gray-matter");
2+
const glob = require("glob");
3+
const path = require("path");
4+
const fs = require("fs");
5+
6+
const processFile = filepath => {
7+
const raw = fs.readFileSync(filepath, "utf8");
8+
const { data } = matter(raw);
9+
10+
const syntaxPath = path.resolve("./misc_docs/syntax");
11+
const relFilePath = path.relative(syntaxPath, filepath);
12+
const parsedPath = path.parse(relFilePath);
13+
14+
if (data.id && data.keywords && data.name && data.summary && data.category) {
15+
return {
16+
file: parsedPath.name,
17+
id: data.id,
18+
keywords: data.keywords,
19+
name: data.name,
20+
summary: data.summary,
21+
category: data.category
22+
}
23+
}
24+
25+
console.error("Metadata missing in " + parsedPath.name + ".mdx")
26+
return null;
27+
};
28+
29+
const extractSyntax = async version => {
30+
const SYNTAX_MD_DIR = path.join(__dirname, "../misc_docs/syntax");
31+
const SYNTAX_INDEX_FILE = path.join(__dirname, "../index_data/syntax_index.json");
32+
const syntaxFiles = glob.sync(`${SYNTAX_MD_DIR}/*.md?(x)`);
33+
const syntaxIndex = syntaxFiles.map(processFile).filter(Boolean).sort((a, b) => a.name.localeCompare(b.name))
34+
fs.writeFileSync(SYNTAX_INDEX_FILE, JSON.stringify(syntaxIndex), "utf8");
35+
};
36+
37+
extractSyntax()

‎src/components/SyntaxLookupWidget.js

+37-169
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.