docusaurus-theme-docdive 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +21 -2
- package/package.json +34 -4
- package/src/client.js +11 -0
- package/src/index.cjs +44 -0
- package/src/theme/Mermaid/index.js +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thibaud Navarre
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# docusaurus-theme-docdive
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[docdive](https://github.com/thibaudnavarre/docdive) adapter for Docusaurus 3: renders Mermaid fences as interactive
|
|
4
|
+
`<docdive-diagram>` elements and, after the build, writes the index and assets to `build/docdive/`.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install docusaurus-theme-docdive
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
// docusaurus.config.js
|
|
12
|
+
module.exports = {
|
|
13
|
+
markdown: { mermaid: true },
|
|
14
|
+
// docdive must come after theme-mermaid
|
|
15
|
+
themes: ["@docusaurus/theme-mermaid", "docusaurus-theme-docdive"],
|
|
16
|
+
};
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Remove the theme line and the site falls back to the native Mermaid component. The docs folder is taken from the docs
|
|
20
|
+
plugin. Optional theme option: `src` (repo root that `src:` frontmatter paths are relative to, relative to the site dir).
|
|
21
|
+
|
|
22
|
+
Peers: `@docusaurus/core` and `@docusaurus/theme-mermaid` ^3.10, `mermaid` >=11.6 <13. Requires Node >= 22.12. MIT.
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-docdive",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Docusaurus theme that renders Mermaid fences as interactive docdive diagrams.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Thibaud Navarre",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/thibaudnavarre/docdive.git",
|
|
10
|
+
"directory": "packages/docusaurus-theme-docdive"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"docusaurus",
|
|
14
|
+
"docusaurus-theme",
|
|
15
|
+
"mermaid"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./src/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.12"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"docdive": "^0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@docusaurus/core": "^3.10.0",
|
|
32
|
+
"@docusaurus/theme-mermaid": "^3.10.0",
|
|
33
|
+
"mermaid": ">=11.6 <13",
|
|
34
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import siteConfig from "@generated/docusaurus.config";
|
|
2
|
+
|
|
3
|
+
// The element is a standalone ESM bundle that `docdive build` copies to <outDir>/docdive/ at build time.
|
|
4
|
+
// Hand it the site's own Mermaid so only one copy is on the page; the element never initializes it.
|
|
5
|
+
if (typeof window !== "undefined") {
|
|
6
|
+
const url = `${siteConfig.baseUrl}docdive/docdive-element.js`;
|
|
7
|
+
window.__docdiveLoad = import(/* webpackIgnore: true */ url).then((element) => {
|
|
8
|
+
element.setMermaid(() => import("mermaid"));
|
|
9
|
+
return element;
|
|
10
|
+
});
|
|
11
|
+
}
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// CommonJS on purpose: Docusaurus loads theme modules through jiti, which cannot evaluate `import.meta`.
|
|
2
|
+
const { execFileSync } = require("node:child_process");
|
|
3
|
+
const { mkdirSync, writeFileSync } = require("node:fs");
|
|
4
|
+
const { dirname, join, relative, resolve, sep } = require("node:path");
|
|
5
|
+
|
|
6
|
+
const docdiveCli = join(dirname(require.resolve("docdive/package.json")), "dist", "cli.js");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* docdive adapter for Docusaurus. A theme (not a plain plugin), listed after @docusaurus/theme-mermaid so its
|
|
10
|
+
* Mermaid component wraps @theme-init/Mermaid. Data only: the product logic lives in the `docdive` CLI.
|
|
11
|
+
*
|
|
12
|
+
* Options: `src` (repo root for `src:` frontmatter paths, relative to the site dir; optional).
|
|
13
|
+
*/
|
|
14
|
+
module.exports = function docdiveTheme(context, options = {}) {
|
|
15
|
+
let docsDir;
|
|
16
|
+
let docMap = {};
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
name: "docusaurus-theme-docdive",
|
|
20
|
+
getThemePath: () => join(__dirname, "theme"),
|
|
21
|
+
getClientModules: () => [join(__dirname, "client.js")],
|
|
22
|
+
|
|
23
|
+
// doc path (relative to the docs dir) -> permalink, which already includes baseUrl.
|
|
24
|
+
allContentLoaded({ allContent }) {
|
|
25
|
+
const version = allContent["docusaurus-plugin-content-docs"]?.default?.loadedVersions?.[0];
|
|
26
|
+
docsDir = version?.contentPath;
|
|
27
|
+
docMap = {};
|
|
28
|
+
for (const doc of version?.docs ?? []) {
|
|
29
|
+
const abs = resolve(context.siteDir, doc.source.replace(/^@site\//, ""));
|
|
30
|
+
docMap[relative(docsDir, abs).split(sep).join("/")] = doc.permalink;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
async postBuild({ outDir }) {
|
|
35
|
+
if (!docsDir) throw new Error("docusaurus-theme-docdive: the docs plugin has no content to index");
|
|
36
|
+
const dest = join(outDir, "docdive");
|
|
37
|
+
const args = [docdiveCli, "build", docsDir, "--out", dest];
|
|
38
|
+
if (options.src) args.push("--src", resolve(context.siteDir, options.src));
|
|
39
|
+
execFileSync(process.execPath, args, { stdio: "inherit" });
|
|
40
|
+
mkdirSync(dest, { recursive: true });
|
|
41
|
+
writeFileSync(join(dest, "docdive-map.json"), JSON.stringify(docMap, null, 2) + "\n");
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import Mermaid from "@theme-init/Mermaid";
|
|
3
|
+
|
|
4
|
+
// Renders <docdive-diagram> from the fence source. If the element bundle fails to load,
|
|
5
|
+
// fall back to the native Docusaurus Mermaid component.
|
|
6
|
+
export default function DocdiveMermaid(props) {
|
|
7
|
+
const [failed, setFailed] = useState(false);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
window.__docdiveLoad?.catch(() => setFailed(true));
|
|
10
|
+
}, []);
|
|
11
|
+
if (failed) return React.createElement(Mermaid, props);
|
|
12
|
+
return React.createElement("docdive-diagram", { source: props.value });
|
|
13
|
+
}
|