Skip to content

Commit 4084821

Browse files
committed
replace gray-matter and deprecated remark plugins
1 parent 6ac474c commit 4084821

File tree

8 files changed

+143
-266
lines changed

8 files changed

+143
-266
lines changed

package-lock.json

Lines changed: 9 additions & 160 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"fuse.js": "^6.4.3",
3434
"gentype": "^3.44.0",
3535
"glob": "^7.1.4",
36-
"gray-matter": "^4.0.3",
3736
"highlight.js": "^11.9.0",
3837
"highlightjs-rescript": "^0.2.2",
3938
"lz-string": "^1.4.4",
@@ -49,7 +48,7 @@
4948
"remark-gfm": "^3.0.1",
5049
"remark-mdx-frontmatter": "^3.0.0",
5150
"remark-parse": "^10.0.2",
52-
"remark-slug": "^5.1.2",
51+
"remark-rehype": "^11.1.1",
5352
"remark-stringify": "^7.0.3",
5453
"request": "^2.88.0",
5554
"rescript": "^11.1.0",

scripts/extract-indices.mjs

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,19 @@
55
* - Module names (h1)
66
* - function names (```res sig)
77
*/
8-
import unified from "unified";
9-
import markdown from "remark-parse";
10-
import stringify from "remark-stringify";
11-
import slug from "remark-slug";
128
import glob from "glob";
139
import path from "path";
1410
import fs from "fs";
1511
import { URL } from 'url';
1612

13+
import { defaultProcessor } from "./markdown.js";
14+
1715
const pathname = new URL('.', import.meta.url).pathname;
1816
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
1917

20-
const headers = options => (tree, file) => {
21-
const headers = [];
22-
let mainHeader;
23-
tree.children.forEach(child => {
24-
if (child.type === "heading" && child.depth === 1) {
25-
if (child.children.length > 0) {
26-
mainHeader = child.children.map(element => element.value).join("");
27-
}
28-
}
29-
if (child.type === "heading" && child.depth === 2) {
30-
if (child.children.length > 0) {
31-
const id = child.data.id || "";
32-
const name = child.children.map(element => element.value).join("");
33-
headers.push({ name, href: id });
34-
}
35-
}
36-
});
37-
38-
file.data = Object.assign({}, file.data, { headers, mainHeader });
39-
};
40-
41-
const codeblocks = options => (tree, file) => {
42-
const { children } = tree;
43-
const codeblocks = {};
44-
45-
const formatter = value => {
46-
// Strip newlines and weird spacing
47-
return value
48-
.replace(/\n/g, " ")
49-
.replace(/\s+/g, " ")
50-
.replace(/\(\s+/g, "(")
51-
.replace(/\s+\)/g, ")");
52-
};
53-
54-
children.forEach(child => {
55-
if (child.type === "code" && child.value) {
56-
const { meta, lang } = child;
57-
if (meta === "sig" && lang === "re") {
58-
if (codeblocks[lang] == null) {
59-
codeblocks[lang] = [];
60-
}
61-
codeblocks[lang].push(formatter(child.value));
62-
}
63-
}
64-
});
65-
66-
file.data = Object.assign({}, file.data, { codeblocks });
67-
};
68-
69-
const processor = unified()
70-
.use(markdown, { gfm: true })
71-
.use(slug)
72-
.use(stringify)
73-
.use(headers)
74-
.use(codeblocks);
75-
7618
const processFile = filepath => {
7719
const content = fs.readFileSync(filepath, "utf8");
78-
const result = processor.processSync(content);
20+
const result = defaultProcessor.processSync(content);
7921

8022
const pagesPath = path.resolve("./pages");
8123
const relFilepath = path.relative(pagesPath, filepath);

0 commit comments

Comments
 (0)