Skip to content

Commit

Permalink
Support provider docs
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Jun 25, 2023
1 parent c74e4d3 commit 47e8288
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
7 changes: 6 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]} */
Expand Down
2 changes: 1 addition & 1 deletion scripts/brick-packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions scripts/pre-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,38 @@ ${
<BrickDocMethods methods={${JSON.stringify(brick.methods)}} />`
: ""
}
`;
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";
<BrickTagName name=${JSON.stringify(provider.name)} isProvider />
${brickDoc}
`;
await writeFile(targetFilePath, content);
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/BrickTagName/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className={styles.tagName}>
<code>&lt;{name}&gt;</code>
{isProvider && <span className="badge badge--warning">provider</span>}
</div>
);
}
12 changes: 10 additions & 2 deletions src/components/BrickTagName/style.module.css
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,3 +15,7 @@
font-size: 20px;
color: var(--ifm-color-emphasis-600);
}

.tagName > :global(.badge) {
margin-left: 1em;
}

0 comments on commit 47e8288

Please sign in to comment.