From 977ae8b23c6f0976aea9c7e21ccb679e19a608e7 Mon Sep 17 00:00:00 2001 From: Ewen Le Bihan Date: Mon, 15 Apr 2024 19:17:39 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Use=20improved=20docs?= =?UTF-8?q?=20page=20for=20ortfo/db=20cli=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vitepress/config.mts | 14 ++++++++--- db/commands/[subcommand].data.js | 4 +-- db/commands/[subcommand].md | 2 +- db/commands/[subcommand].paths.js | 17 +++---------- db/commands/completion.md | 0 db/commands/global-options.data.js | 7 ------ db/commands/global-options.md | 5 ---- db/commands/transformer.js | 40 ------------------------------ ortfodb | 2 +- package.json | 2 +- 10 files changed, 18 insertions(+), 75 deletions(-) delete mode 100644 db/commands/completion.md delete mode 100644 db/commands/global-options.data.js delete mode 100644 db/commands/global-options.md delete mode 100644 db/commands/transformer.js diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 45c1561..f22e511 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -89,10 +89,16 @@ const ortfodbSidebar = [ collapsed: true, items: [ { text: "Global options", link: "/db/commands/global-options" }, - ...subcommand.paths().map(({ params: { subcommand } }) => ({ - text: subcommand.replace("-", " "), - link: `/db/commands/${subcommand}`, - })), + ...subcommand + .paths() + .filter( + ({ params: { subcommand } }) => + !["README", "global-options"].includes(subcommand) + ) + .map(({ params: { subcommand } }) => ({ + text: subcommand.replace("-", " "), + link: `/db/commands/${subcommand}`, + })), ], }, { diff --git a/db/commands/[subcommand].data.js b/db/commands/[subcommand].data.js index d76dbf0..1ca8292 100644 --- a/db/commands/[subcommand].data.js +++ b/db/commands/[subcommand].data.js @@ -1,7 +1,5 @@ import { createContentLoader } from "vitepress" -import transformer from "./transformer" -export default createContentLoader("ortfodb/docs/ortfodb_*.md", { +export default createContentLoader("ortfodb/docs/*.md", { render: true, - transform: transformer, }) diff --git a/db/commands/[subcommand].md b/db/commands/[subcommand].md index e3042af..655abf2 100644 --- a/db/commands/[subcommand].md +++ b/db/commands/[subcommand].md @@ -7,6 +7,6 @@ editLink: false
diff --git a/db/commands/[subcommand].paths.js b/db/commands/[subcommand].paths.js index 006fd4b..ff2cd9d 100644 --- a/db/commands/[subcommand].paths.js +++ b/db/commands/[subcommand].paths.js @@ -2,17 +2,8 @@ import { readdirSync } from "node:fs" import path from "node:path" export default { - paths() { - const files = readdirSync("ortfodb/docs") - .map((entry) => path.basename(entry)) - .filter((name) => name.startsWith("ortfodb_") && name.endsWith(".md")) - .map((name) => - path - .basename(name, ".md") - .replace(/^ortfodb_/, "") - .replace(/_/g, "-") - ) - - return files.map((file) => ({ params: { subcommand: file } })) - }, + paths: () => + readdirSync("ortfodb/docs").map((file) => ({ + params: { subcommand: path.basename(file, ".md") }, + })), } diff --git a/db/commands/completion.md b/db/commands/completion.md deleted file mode 100644 index e69de29..0000000 diff --git a/db/commands/global-options.data.js b/db/commands/global-options.data.js deleted file mode 100644 index c452910..0000000 --- a/db/commands/global-options.data.js +++ /dev/null @@ -1,7 +0,0 @@ -import { createContentLoader } from "vitepress" -import transformer from "./transformer" - -export default createContentLoader("ortfodb/docs/ortfodb.md", { - render: true, - transform: transformer, -}) diff --git a/db/commands/global-options.md b/db/commands/global-options.md deleted file mode 100644 index 0b31801..0000000 --- a/db/commands/global-options.md +++ /dev/null @@ -1,5 +0,0 @@ - - -
diff --git a/db/commands/transformer.js b/db/commands/transformer.js deleted file mode 100644 index 509cf9f..0000000 --- a/db/commands/transformer.js +++ /dev/null @@ -1,40 +0,0 @@ -import cheerio from "cheerio" - -/** - * - * @param {import("vitepress").ContentData[]} rawDatas - * @returns - */ -export default function transformer(rawDatas) { - return rawDatas.map((rawData) => { - // Load the HTML string - const $ = cheerio.load(rawData.html) - - ;[2, 3, 4, 5, 6].forEach((oldLevel) => { - // Find each occurrence of the old heading level - $(`h${oldLevel}`).each((index, element) => { - // Replace the old heading with the new one - $(element).replaceWith( - `${$(element).html()}` - ) - }) - }) - - // Update links - $("a").each((_, element) => { - if ($(element).attr("href") === "./ortfodb.html") { - $(element).attr("href", "./global-options") - return - } - const pattern = /^\.\/ortfodb_(.+)\.html$/ - const match = pattern.exec($(element).attr("href")) - if (!match) return - $(element).attr("href", `./${match[1].replace(/_/g, "-")}`) - }) - - return { - ...rawData, - html: $.html(), - } - }) -} diff --git a/ortfodb b/ortfodb index 2852387..7321adf 160000 --- a/ortfodb +++ b/ortfodb @@ -1 +1 @@ -Subproject commit 28523874a909807e3d99912e38ff805210e0a169 +Subproject commit 7321adfb1ef706039aeabd3d7851dbcefcee9200 diff --git a/package.json b/package.json index b10579a..9255d7f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "favicons:generate": "real-favicon generate favicon.json .favicon-data.json public/ ", "favicons:inject": "cp .vitepress/favicon.ts public/favicon.ts && real-favicon inject .favicon-data.json public favicon.ts && mv public/favicon.ts .vitepress/", "jsonschemas:copy": "./copy-all-schemas", - "submodules:pull": "git submodule update --init --recursive && git submodule foreach git pull origin main" + "submodules:pull": "git submodule sync" }, "devDependencies": { "@types/json-schema": "^7.0.15",