Skip to content

Syntax lookup dynamic include #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion misc_docs/syntax/controlflow_ifelse.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
test: "foo"
id: "if-else"
keywords: ["if", "else"]
name: "if / else"
summary: "This is the `if / else` control flow."
category: "controlflow"
---

Use `if / else` expressions to express a value trough a `true` / `false` condition.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"test": "node scripts/test-examples.js && node scripts/test-hrefs.js",
"check-dead-code": "reanalyze -dce",
"check-for-exceptions": "reanalyze -exception",
"update-index": "node scripts/extract-indices.js && node scripts/extract-tocs.js && node -r esm scripts/generate_feed.js > public/blog/feed.xml",
"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",
"now-build": "yarn run build",
"export": "next export",
"start": "next start -p $PORT",
Expand Down
37 changes: 37 additions & 0 deletions scripts/extract-syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const matter = require("gray-matter");
const glob = require("glob");
const path = require("path");
const fs = require("fs");

const processFile = filepath => {
const raw = fs.readFileSync(filepath, "utf8");
const { data } = matter(raw);

const syntaxPath = path.resolve("./misc_docs/syntax");
const relFilePath = path.relative(syntaxPath, filepath);
const parsedPath = path.parse(relFilePath);

if (data.id && data.keywords && data.name && data.summary && data.category) {
return {
file: parsedPath.name,
id: data.id,
keywords: data.keywords,
name: data.name,
summary: data.summary,
category: data.category
}
}

console.error("Metadata missing in " + parsedPath.name + ".mdx")
return null;
};

const extractSyntax = async version => {
const SYNTAX_MD_DIR = path.join(__dirname, "../misc_docs/syntax");
const SYNTAX_INDEX_FILE = path.join(__dirname, "../index_data/syntax_index.json");
const syntaxFiles = glob.sync(`${SYNTAX_MD_DIR}/*.md?(x)`);
const syntaxIndex = syntaxFiles.map(processFile).filter(Boolean).sort((a, b) => a.name.localeCompare(b.name))
fs.writeFileSync(SYNTAX_INDEX_FILE, JSON.stringify(syntaxIndex), "utf8");
};

extractSyntax()
206 changes: 37 additions & 169 deletions src/components/SyntaxLookupWidget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading