docusaurus-theme-docdive 0.0.0-stage → 0.2.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 +28 -2
- package/package.json +34 -4
- package/src/client.js +11 -0
- package/src/index.cjs +70 -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,29 @@
|
|
|
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
|
+
## Dev mode
|
|
23
|
+
|
|
24
|
+
`docusaurus start` works with no extra config. The theme runs `docdive watch` on the docs folder, writes its output to
|
|
25
|
+
`.docusaurus/docdive/` and serves it at `<baseUrl>docdive/`. Diagrams are interactive right away. After you edit a
|
|
26
|
+
Markdown file, reload the page to see the new data (no auto-reload). A build error in the docs is logged and the last
|
|
27
|
+
good data is kept. `docusaurus build` is unchanged.
|
|
28
|
+
|
|
29
|
+
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.2.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.2.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,70 @@
|
|
|
1
|
+
// CommonJS on purpose: Docusaurus loads theme modules through jiti, which cannot evaluate `import.meta`.
|
|
2
|
+
const { execFileSync, spawn } = 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
|
+
let watcherStarted = false;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* docdive adapter for Docusaurus. A theme (not a plain plugin), listed after @docusaurus/theme-mermaid so its
|
|
12
|
+
* Mermaid component wraps @theme-init/Mermaid. Data only: the product logic lives in the `docdive` CLI.
|
|
13
|
+
*
|
|
14
|
+
* Options: `src` (repo root for `src:` frontmatter paths, relative to the site dir; optional).
|
|
15
|
+
*/
|
|
16
|
+
module.exports = function docdiveTheme(context, options = {}) {
|
|
17
|
+
let docsDir;
|
|
18
|
+
let docMap = {};
|
|
19
|
+
const devDir = join(context.generatedFilesDir, "docdive");
|
|
20
|
+
const srcArgs = () => (options.src ? ["--src", resolve(context.siteDir, options.src)] : []);
|
|
21
|
+
const writeMap = (dir) => {
|
|
22
|
+
mkdirSync(dir, { recursive: true });
|
|
23
|
+
writeFileSync(join(dir, "docdive-map.json"), JSON.stringify(docMap, null, 2) + "\n");
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: "docusaurus-theme-docdive",
|
|
28
|
+
getThemePath: () => join(__dirname, "theme"),
|
|
29
|
+
getClientModules: () => [join(__dirname, "client.js")],
|
|
30
|
+
|
|
31
|
+
// doc path (relative to the docs dir) -> permalink, which already includes baseUrl.
|
|
32
|
+
allContentLoaded({ allContent }) {
|
|
33
|
+
const version = allContent["docusaurus-plugin-content-docs"]?.default?.loadedVersions?.[0];
|
|
34
|
+
docsDir = version?.contentPath;
|
|
35
|
+
docMap = {};
|
|
36
|
+
for (const doc of version?.docs ?? []) {
|
|
37
|
+
const abs = resolve(context.siteDir, doc.source.replace(/^@site\//, ""));
|
|
38
|
+
docMap[relative(docsDir, abs).split(sep).join("/")] = doc.permalink;
|
|
39
|
+
}
|
|
40
|
+
// Re-runs on every docs reload under `docusaurus start`, which keeps the dev map fresh.
|
|
41
|
+
writeMap(devDir);
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
// `devServer` is only read by webpack-dev-server, so `docusaurus build` is unaffected.
|
|
45
|
+
configureWebpack(_config, isServer) {
|
|
46
|
+
if (isServer) return {};
|
|
47
|
+
return {
|
|
48
|
+
devServer: {
|
|
49
|
+
static: [{ directory: devDir, publicPath: `${context.baseUrl}docdive`, watch: false }],
|
|
50
|
+
// onListening is only called by webpack-dev-server. Never define setupMiddlewares here: Docusaurus does.
|
|
51
|
+
onListening() {
|
|
52
|
+
if (watcherStarted || !docsDir) return;
|
|
53
|
+
watcherStarted = true;
|
|
54
|
+
const child = spawn(process.execPath, [docdiveCli, "watch", docsDir, "--out", devDir, ...srcArgs()], {
|
|
55
|
+
stdio: "inherit",
|
|
56
|
+
});
|
|
57
|
+
process.on("exit", () => child.kill());
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
async postBuild({ outDir }) {
|
|
64
|
+
if (!docsDir) throw new Error("docusaurus-theme-docdive: the docs plugin has no content to index");
|
|
65
|
+
const dest = join(outDir, "docdive");
|
|
66
|
+
execFileSync(process.execPath, [docdiveCli, "build", docsDir, "--out", dest, ...srcArgs()], { stdio: "inherit" });
|
|
67
|
+
writeMap(dest);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -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
|
+
}
|