rspress-plugin-graph-view 0.1.1

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +161 -0
  3. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Rspress contributors
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 ADDED
@@ -0,0 +1,161 @@
1
+ # rspress-plugin-graph-view
2
+
3
+ Interactive graph visualization for [Rspress](https://rspress.dev/) documentation sites. Automatically extracts internal markdown links and renders them as a navigable force-directed graph — like Obsidian's graph view for your docs.
4
+
5
+ ![Version](https://img.shields.io/npm/v/rspress-plugin-graph-view)
6
+ ![License](https://img.shields.io/npm/l/rspress-plugin-graph-view)
7
+
8
+ ## Features
9
+
10
+ - **Automatic link detection** — uses MDAST parsing to extract all markdown link formats (inline, reference, autolinks) while ignoring links inside code blocks
11
+ - **Click to navigate** — click any node to jump to that page
12
+ - **Dark mode** — seamlessly adapts to light and dark themes
13
+ - **Build caching** — incremental rebuilds with mtime-based cache invalidation
14
+ - **Large graph optimization** — automatically disables expensive visual effects for graphs with 80+ nodes
15
+ - **Build profiling** — optional diagnostics to measure graph build performance
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ bun add rspress-plugin-graph-view
21
+ # or
22
+ npm install rspress-plugin-graph-view
23
+ # or
24
+ pnpm add rspress-plugin-graph-view
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Add the plugin to your `rspress.config.ts`:
30
+
31
+ ```ts
32
+ import { defineConfig } from "@rspress/core";
33
+ import graphView from "rspress-plugin-graph-view";
34
+
35
+ export default defineConfig({
36
+ // ...your config
37
+ plugins: [graphView()],
38
+ });
39
+ ```
40
+
41
+ That's it. A floating action button will appear in the bottom-right corner of your docs site. Click it to open the graph view.
42
+
43
+ ### Options
44
+
45
+ ```ts
46
+ graphView({
47
+ // Open the graph panel by default (default: false)
48
+ defaultOpen: true,
49
+
50
+ // Log build timing diagnostics (default: false)
51
+ profileBuild: true,
52
+ })
53
+ ```
54
+
55
+ You can also enable profiling temporarily with the `RSPRESS_GRAPH_VIEW_PROFILE=1` environment variable.
56
+
57
+ ### Peer Dependencies
58
+
59
+ This plugin requires the following peer dependencies, which should already be installed if you're using Rspress:
60
+
61
+ | Package | Version |
62
+ | --- | --- |
63
+ | `@rspress/core` | `^2.0.7` |
64
+ | `react` | `>=19` |
65
+ | `react-dom` | `>=19` |
66
+ | `react-force-graph-2d` | `^1.29.1` |
67
+
68
+ ## How It Works
69
+
70
+ 1. **Build time**: The plugin collects all route metadata, reads each markdown file, parses the content into an MDAST syntax tree, extracts internal link references, and builds a graph data structure.
71
+ 2. **Runtime**: A virtual module (`virtual-graph-data`) injects the graph data into the client. `react-force-graph-2d` renders an interactive force-directed graph with custom canvas drawing.
72
+ 3. **Caching**: File mtime + size signatures enable incremental rebuilds — unchanged files skip parsing entirely.
73
+
74
+ ## Architecture
75
+
76
+ ```
77
+ src/
78
+ index.ts ← Plugin entry point (RspressPlugin)
79
+ types.ts ← Core shared types (GraphNode, GraphLink, GraphData)
80
+ build/
81
+ index.ts ← Public API: buildGraphModule, createGraphBuildCache
82
+ types.ts ← Build-time types (CollectedRoute, GraphBuildOptions)
83
+ cache.ts ← Cache management, pruning, signatures, logging
84
+ graph-builder.ts ← Graph construction, route resolution, file aliases
85
+ link-extractor.ts ← MDAST parsing, link/title extraction
86
+ runtime/
87
+ GraphPanel.tsx ← Floating panel with FAB, zoom controls, keyboard a11y
88
+ GraphView.tsx ← Canvas renderer via react-force-graph-2d, error boundary
89
+ canvas/
90
+ colors.ts ← Light/dark color palettes, theme merging
91
+ deriveGraphViewData.ts ← View data derivation (current page + neighbors)
92
+ virtual-modules.d.ts ← TypeScript declaration for virtual-graph-data
93
+ ```
94
+
95
+ ### Build Pipeline
96
+
97
+ ```
98
+ routeGenerated hook → collect routes → buildGraphModule()
99
+ ├── pruneStaleDocuments() — remove deleted routes from cache
100
+ ├── stat() — check mtime + size for each file
101
+ ├── cache hit? — reuse parsed data, skip expensive work
102
+ ├── extractDisplayTitle() — read frontmatter title or first heading
103
+ ├── extractMarkdownLinks() — MDAST parsing → internal link targets
104
+ ├── createGraphSignature() — content hash for module-level caching
105
+ ├── buildGraphData() — resolve links → build adjacency graph
106
+ └── serialize → virtual-graph-data module
107
+ ```
108
+
109
+ ### Runtime Pipeline
110
+
111
+ ```
112
+ GraphPanel mounts → lazy-loads react-force-graph-2d
113
+ ├── useLocation() → current route path
114
+ ├── deriveGraphViewData() → filter graph to current node neighborhood
115
+ ├── useTheme() → MutationObserver detects dark mode changes
116
+ ├── canvas rendering → custom nodeCanvasObject with gradients, shadows, hover effects
117
+ └── onNodeClick → navigate() to target route
118
+ ```
119
+
120
+ ## Development
121
+
122
+ ```bash
123
+ # Install dependencies
124
+ bun install
125
+
126
+ # Typecheck
127
+ bun run build
128
+
129
+ # Run tests
130
+ bun test
131
+
132
+ # Start docs dev server
133
+ bun run docs:dev
134
+
135
+ # Benchmark graph build performance
136
+ bun run bench:graph --pages=1000 --links=6 --iterations=5
137
+ ```
138
+
139
+ ## Contributing
140
+
141
+ 1. Fork the repository
142
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
143
+ 3. Make your changes
144
+ 4. Run tests (`bun test`) and typecheck (`bun run build`)
145
+ 5. Commit using [Conventional Commits](https://www.conventionalcommits.org/) (e.g., `feat:`, `fix:`, `docs:`)
146
+ 6. Push and open a Pull Request
147
+
148
+ ### Commit Convention
149
+
150
+ This project uses semantic-release for automated versioning. Commit messages must follow [Conventional Commits](https://www.conventionalcommits.org/):
151
+
152
+ - `feat:` — new feature (triggers minor version bump)
153
+ - `fix:` — bug fix (triggers patch version bump)
154
+ - `docs:` — documentation only
155
+ - `refactor:` — code change that neither fixes a bug nor adds a feature
156
+ - `chore:` — maintenance tasks
157
+ - `ci:` — CI/CD configuration changes
158
+
159
+ ## License
160
+
161
+ MIT
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "rspress-plugin-graph-view",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Interactive graph visualization for Rspress documentation sites — visualize your knowledge base connections like Obsidian",
6
+ "files": [
7
+ "dist",
8
+ "README.md"
9
+ ],
10
+ "keywords": [
11
+ "rspress",
12
+ "plugin",
13
+ "graphview"
14
+ ],
15
+ "homepage": "https://github.com/Jacob-Valor/rspress-plugin-graph-view",
16
+ "bugs": {
17
+ "url": "https://github.com/Jacob-Valor/rspress-plugin-graph-view/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/Jacob-Valor/rspress-plugin-graph-view.git"
22
+ },
23
+ "license": "MIT",
24
+ "author": "Jacob-Valor <jacob-programmer@tuta.io> (https://github.com/Jacob-Valor)",
25
+ "main": "dist/index.js",
26
+ "types": "dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./src/index.ts",
30
+ "default": "./src/index.ts"
31
+ },
32
+ "./runtime/*": {
33
+ "import": "./src/runtime/*",
34
+ "default": "./src/runtime/*"
35
+ }
36
+ },
37
+ "scripts": {
38
+ "bench:graph": "bun scripts/bench-graph-build.ts",
39
+ "build": "tsc --declarationMap false",
40
+ "dev": "tsc -w",
41
+ "docs:build": "rspress build",
42
+ "docs:dev": "rspress dev",
43
+ "test": "bun test",
44
+ "prepublishOnly": "bun run build && bun run test"
45
+ },
46
+ "devDependencies": {
47
+ "@types/bun": "latest",
48
+ "@types/react": "^19.2.14",
49
+ "@types/react-dom": "^19.2.3",
50
+ "semantic-release": "^25.0.3",
51
+ "typescript": "^6.0.2"
52
+ },
53
+ "peerDependencies": {
54
+ "@rspress/core": "^2.0.7",
55
+ "react": "^19.2.4",
56
+ "react-dom": "^19.2.4",
57
+ "react-force-graph-2d": "^1.29.1"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "typescript": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "dependencies": {
65
+ "rspress-plugin-devkit": "^1.0.0"
66
+ }
67
+ }