chore: migrate to biomejs

This commit is contained in:
BennyKok
2024-01-20 20:09:28 +08:00
parent c98a16a2dd
commit e400966117
20 changed files with 63 additions and 150 deletions
+10 -10
View File
@@ -27,13 +27,13 @@ function rehypeShiki() {
visit(tree, "element", (node) => {
if (node.tagName === "pre" && node.children[0]?.tagName === "code") {
let codeNode = node.children[0];
let textNode = codeNode.children[0];
const codeNode = node.children[0];
const textNode = codeNode.children[0];
node.properties.code = textNode.value;
if (node.properties.language) {
let tokens = highlighter.codeToThemedTokens(
const tokens = highlighter.codeToThemedTokens(
textNode.value,
node.properties.language
);
@@ -53,7 +53,7 @@ function rehypeShiki() {
function rehypeSlugify() {
return (tree) => {
let slugify = slugifyWithCounter();
const slugify = slugifyWithCounter();
visit(tree, "element", (node) => {
if (node.tagName === "h2" && !node.properties.id) {
node.properties.id = slugify(toString(node));
@@ -64,10 +64,10 @@ function rehypeSlugify() {
function rehypeAddMDXExports(getExports) {
return (tree) => {
let exports = Object.entries(getExports(tree));
const exports = Object.entries(getExports(tree));
for (let [name, value] of exports) {
for (let node of tree.children) {
for (const [name, value] of exports) {
for (const node of tree.children) {
if (
node.type === "mdxjsEsm" &&
new RegExp(`export\\s+const\\s+${name}\\s*=`).test(node.value)
@@ -76,7 +76,7 @@ function rehypeAddMDXExports(getExports) {
}
}
let exportStr = `export const ${name} = ${value}`;
const exportStr = `export const ${name} = ${value}`;
tree.children.push({
type: "mdxjsEsm",
@@ -93,9 +93,9 @@ function rehypeAddMDXExports(getExports) {
}
function getSections(node) {
let sections = [];
const sections = [];
for (let child of node.children ?? []) {
for (const child of node.children ?? []) {
if (child.type === "element" && child.tagName === "h2") {
sections.push(`{
title: ${JSON.stringify(toString(child))},