Skip to content

replace gray-matter and deprecated remark plugins #984

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 6 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
169 changes: 9 additions & 160 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"fuse.js": "^6.4.3",
"gentype": "^3.44.0",
"glob": "^7.1.4",
"gray-matter": "^4.0.3",
"highlight.js": "^11.9.0",
"highlightjs-rescript": "^0.2.2",
"lz-string": "^1.4.4",
Expand All @@ -49,7 +48,7 @@
"remark-gfm": "^3.0.1",
"remark-mdx-frontmatter": "^3.0.0",
"remark-parse": "^10.0.2",
"remark-slug": "^5.1.2",
"remark-rehype": "^11.1.1",
"remark-stringify": "^7.0.3",
"request": "^2.88.0",
"rescript": "^11.1.0",
Expand Down
64 changes: 3 additions & 61 deletions scripts/extract-indices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,19 @@
* - Module names (h1)
* - function names (```res sig)
*/
import unified from "unified";
import markdown from "remark-parse";
import stringify from "remark-stringify";
import slug from "remark-slug";
import glob from "glob";
import path from "path";
import fs from "fs";
import { URL } from 'url';

import { defaultProcessor } from "./markdown.js";

const pathname = new URL('.', import.meta.url).pathname;
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)

const headers = options => (tree, file) => {
const headers = [];
let mainHeader;
tree.children.forEach(child => {
if (child.type === "heading" && child.depth === 1) {
if (child.children.length > 0) {
mainHeader = child.children.map(element => element.value).join("");
}
}
if (child.type === "heading" && child.depth === 2) {
if (child.children.length > 0) {
const id = child.data.id || "";
const name = child.children.map(element => element.value).join("");
headers.push({ name, href: id });
}
}
});

file.data = Object.assign({}, file.data, { headers, mainHeader });
};

const codeblocks = options => (tree, file) => {
const { children } = tree;
const codeblocks = {};

const formatter = value => {
// Strip newlines and weird spacing
return value
.replace(/\n/g, " ")
.replace(/\s+/g, " ")
.replace(/\(\s+/g, "(")
.replace(/\s+\)/g, ")");
};

children.forEach(child => {
if (child.type === "code" && child.value) {
const { meta, lang } = child;
if (meta === "sig" && lang === "re") {
if (codeblocks[lang] == null) {
codeblocks[lang] = [];
}
codeblocks[lang].push(formatter(child.value));
}
}
});

file.data = Object.assign({}, file.data, { codeblocks });
};

const processor = unified()
.use(markdown, { gfm: true })
.use(slug)
.use(stringify)
.use(headers)
.use(codeblocks);

const processFile = filepath => {
const content = fs.readFileSync(filepath, "utf8");
const result = processor.processSync(content);
const result = defaultProcessor.processSync(content);

const pagesPath = path.resolve("./pages");
const relFilepath = path.relative(pagesPath, filepath);
Expand Down
Loading
Loading