From 47e82887bb218eb00f1ffddfb321eb5907363661 Mon Sep 17 00:00:00 2001 From: weareoutman Date: Sun, 25 Jun 2023 18:47:41 +0800 Subject: [PATCH] Support provider docs --- docusaurus.config.js | 7 ++++- scripts/brick-packages.mjs | 2 +- scripts/pre-build.mjs | 32 ++++++++++++++++++++ src/components/BrickTagName/index.tsx | 9 +++++- src/components/BrickTagName/style.module.css | 12 ++++++-- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index 99533601..dd8fc580 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -12,9 +12,14 @@ const bricksDir = getBricksDir(); const baseUrl = "/"; -/** @type {{brickPackages: any[]}} */ +/** @type {{brickPackages: any[]; settings: any;}} */ const bootstrapJson = { brickPackages: [], + settings: { + misc: { + weather_api_key: "9e08e5e99e0c4b4c89023605231804", + }, + }, }; /** @type {string[]} */ diff --git a/scripts/brick-packages.mjs b/scripts/brick-packages.mjs index a88b768b..2f739fdd 100644 --- a/scripts/brick-packages.mjs +++ b/scripts/brick-packages.mjs @@ -16,7 +16,7 @@ await Promise.all( const manifestJsonPath = path.join(pkgPath, "dist/manifest.json"); if (existsSync(manifestJsonPath)) { const manifest = (await import(manifestJsonPath, { assert: { type: "json" } })).default; - if (manifest.bricks.length > 0) { + if (manifest.bricks.length > 0 || (manifest.providers ?? []).length > 0) { packages.push({ path: pkgPath, manifest diff --git a/scripts/pre-build.mjs b/scripts/pre-build.mjs index 51e7b263..231b7ea6 100644 --- a/scripts/pre-build.mjs +++ b/scripts/pre-build.mjs @@ -103,6 +103,38 @@ ${ ` : "" } +`; + await writeFile(targetFilePath, content); + } + + for (const provider of manifest.providers ?? []) { + const nameParts = provider.name.split("."); + const lastName = nameParts.pop(); + const targetFilePath = path.join(targetDir, `${lastName}.mdx`); + + const srcFilePath = path.join(srcDocsDir, `${provider.name}.md`); + const srcFilePathAlt = path.join(srcDocsDir, `${lastName}.md`); + + /** @type {string} */ + let brickDoc; + if (existsSync(srcFilePath)) { + brickDoc = handleExamplesInMarkdown(await readFile(srcFilePath, "utf-8"), manifests); + } else if (existsSync(srcFilePathAlt)) { + brickDoc = handleExamplesInMarkdown(await readFile(srcFilePathAlt, "utf-8"), manifests); + } else { + continue; + } + + const content = +`--- +description: ${JSON.stringify(`<${provider.name}>`)} +--- + +import BrickTagName from "@site/src/components/BrickTagName"; + + + +${brickDoc} `; await writeFile(targetFilePath, content); } diff --git a/src/components/BrickTagName/index.tsx b/src/components/BrickTagName/index.tsx index a54d4a7a..52ddf1a1 100644 --- a/src/components/BrickTagName/index.tsx +++ b/src/components/BrickTagName/index.tsx @@ -1,10 +1,17 @@ import React from "react"; import styles from "./style.module.css"; -export default function BrickTagName({ name }: { name: string }): JSX.Element { +export default function BrickTagName({ + name, + isProvider, +}: { + name: string; + isProvider?: boolean; +}): JSX.Element { return (
<{name}> + {isProvider && provider}
); } diff --git a/src/components/BrickTagName/style.module.css b/src/components/BrickTagName/style.module.css index 9a8130d4..63caae2c 100644 --- a/src/components/BrickTagName/style.module.css +++ b/src/components/BrickTagName/style.module.css @@ -1,6 +1,10 @@ .tagName { - margin-top: calc(0.5rem - var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading)) !important; - margin-bottom: calc(var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading)); + margin-top: calc( + 0.5rem - var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading) + ) !important; + margin-bottom: calc( + var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading) + ); } .tagName code { @@ -11,3 +15,7 @@ font-size: 20px; color: var(--ifm-color-emphasis-600); } + +.tagName > :global(.badge) { + margin-left: 1em; +}