Skip to content

Commit

Permalink
24/11/19
Browse files Browse the repository at this point in the history
Former-commit-id: 4665812
  • Loading branch information
WindRunnerMax committed Nov 19, 2024
1 parent 2f24372 commit c907fca
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 1,043 deletions.
16 changes: 0 additions & 16 deletions .scripts/constant.ts

This file was deleted.

47 changes: 0 additions & 47 deletions .scripts/generator.ts

This file was deleted.

76 changes: 76 additions & 0 deletions .scripts/overview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import path from "node:path";
import fs from "node:fs/promises";
import { glob } from "glob";
import { docs } from "./docs";
import { countWords } from "alfaaz";

const root = path.resolve(__dirname, `..`);

(async () => {
console.log("Calculating...");
const DOCS_GROUP = Object.keys(docs);
const group = await Promise.all(
DOCS_GROUP.map((group) => glob(path.join(root, `${group}`) + "/*.md"))
);
const files = group.flat(1);
const backup = await glob(path.join(root, `Backup`) + "/*.md");
const all = [...files, ...backup];
const count = all.length;
let lines = 0;
let words = 0;
let characters = 0;
for (const file of all) {
const content = await fs.readFile(file, "utf8");
const line = content.split("\n").length;
const character = content.length;
lines = lines + line;
characters = characters + character;
words = words + countWords(content.replace(/`/g, " "));
}

console.log("Processing README.md");
const content: string[] = [];
for (const [key, value] of Object.entries(docs)) {
content.push(`## ${key}`);
for (const item of value) {
const name = item.split("/").pop();
if (!name) continue;
content.push(`* [${name}](${item.replace(/ /g, "%20")}.md)`);
}
content.push("");
}
const summary = [
`版本库中共有\`${count}\`篇文章,总计\`${lines}\`行,\`${words}\`字,\`${characters}\`字符。`,
];
const readme = await fs.readFile(path.resolve(root, "README.md"), "utf-8");
const record: Record<string, string[]> = { summary, content };
const readmeFile: string[] = [];
const readmeLines = readme.split("\n");
const regexp = /<!-- (.+?) (.+?) -->/;
for (let i = 0; i < readmeLines.length; ++i) {
readmeFile.push(readmeLines[i]);
const start = regexp.exec(readmeLines[i].trim());
const key = start && start[1];
const value = start && start[2];
if (!key || !value || value !== "Start") {
continue;
}
for (let k = i + 1; k < readmeLines.length; ++k) {
const end = regexp.exec(readmeLines[k].trim());
const endKey = end && end[1];
const endValue = end && end[2];
if (!key || !endValue || endKey !== key || endValue !== "End") {
continue;
}
readmeFile.push(...record[key.toLocaleLowerCase()]);
readmeFile.push(`<!-- ${key} End -->`);
i = k;
break;
}
}
await fs.writeFile(
path.resolve(root, "README.md"),
readmeFile.join("\n"),
"utf-8"
);
})();
13 changes: 5 additions & 8 deletions .scripts/sync-blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import fs from "node:fs/promises";
import path from "node:path";
import { exec as aliasExec } from "node:child_process";
import { promisify } from "node:util";
import { DOCS_GROUP } from "./constant";
import { docs } from "./docs";

const root = path.resolve(__dirname, `..`);
const exec = promisify(aliasExec);
const root = path.resolve(__dirname, `..`);
const blog = path.resolve(root, `../Blog`);

(async () => {
console.log("Syncing Blog...");
const DOCS_GROUP = Object.keys(docs);
for (const group of DOCS_GROUP) {
console.log("Processing", group);
const from = path.resolve(root, group);
const to = path.resolve(root, `../Blog/`);
await exec(`cp -r ${from} ${to}`);
await exec(`cp -r ${from} ${blog}`);
}
const from = path.join(root, "Overview.md");
const to = path.join(root, "../Blog/");
await exec(`cp -r ${from} ${to}`);

console.log("Processing _sidebar.md");
const body: string[] = [];
Expand All @@ -32,5 +29,5 @@ const exec = promisify(aliasExec);
body.push("");
}
const content = body.join("\n");
await fs.writeFile(path.join(root, "../Blog/_sidebar.md"), content);
await fs.writeFile(path.join(blog, "_sidebar.md"), content);
})();
13 changes: 8 additions & 5 deletions .scripts/sync-ssg.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import path from "node:path";
import { exec as aliasExec } from "node:child_process";
import { promisify } from "node:util";
import { DOCS_GROUP } from "./constant";
import { docs } from "./docs";

const exec = promisify(aliasExec);
const root = path.resolve(__dirname, `..`);
const ssg = path.resolve(root, `../Blog-SSG`);

(async () => {
console.log("Syncing SSG...");
const DOCS_GROUP = Object.keys(docs);
for (const group of DOCS_GROUP) {
console.log("Processing", group);
const from = path.resolve(__dirname, `../${group}`);
const to = path.resolve(__dirname, `../../Blog-SSG/docs/zh-cn`);
const from = path.resolve(root, group);
const to = path.resolve(ssg, `docs/zh-cn`);
await exec(`cp -r ${from} ${to}`);
}

console.log("Processing", "I18N");
const from = path.resolve(__dirname, `../i18n/`);
const to = path.resolve(__dirname, `../../Blog-SSG/docs/en-us`);
const from = path.resolve(root, `i18n`);
const to = path.resolve(ssg, `docs/en-us`);
await exec(`cp -r ${from}/* ${to}`);

console.log("Processing", "sidebar.ts");
Expand Down
Loading

0 comments on commit c907fca

Please sign in to comment.