@riebeckite/plugin-docs 0.0.0-stage → 0.0.23
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 +201 -0
- package/README.md +87 -2
- package/README_ja.md +88 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +31 -0
- package/dist/components/docs-prev-next.d.ts +8 -0
- package/dist/components/docs-sidebar.d.ts +8 -0
- package/dist/components/docs-sidebar.js +38 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +415 -0
- package/dist/src/docs-sidebar.client.d.ts +1 -0
- package/dist/src/navigation.d.ts +4 -0
- package/dist/src/render.d.ts +7 -0
- package/dist/src/types.d.ts +47 -0
- package/package.json +70 -3
- package/style.css +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright Rerurate_514
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @riebeckite/plugin-docs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- Generated from docs/docs/plugins/docs.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
|
|
4
|
+
|
|
5
|
+
Build-time docs navigation for Riebeckite. The plugin creates a sidebar and
|
|
6
|
+
previous/next links from a published Markdown subtree without adding a docs
|
|
7
|
+
router or recalculating public URLs from filesystem paths.
|
|
8
|
+
|
|
9
|
+
[日本語](./README_ja.md)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @riebeckite/plugin-docs
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Basic usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineConfig } from "@riebeckite/core";
|
|
21
|
+
import { docs } from "@riebeckite/plugin-docs";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
plugins: [
|
|
25
|
+
docs({
|
|
26
|
+
root: "docs",
|
|
27
|
+
sidebar: { auto: true },
|
|
28
|
+
prevNext: true,
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`root` is the content subtree to treat as docs. With `root: "docs"`, only
|
|
35
|
+
content below `content/docs/` is included; notes and blog posts outside that
|
|
36
|
+
subtree are left unchanged.
|
|
37
|
+
|
|
38
|
+
## Frontmatter
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
---
|
|
42
|
+
title: Installation
|
|
43
|
+
sidebar:
|
|
44
|
+
label: Install
|
|
45
|
+
order: 2
|
|
46
|
+
hidden: false
|
|
47
|
+
collapsed: false
|
|
48
|
+
---
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Supported sidebar metadata:
|
|
52
|
+
|
|
53
|
+
- `label` — label shown in navigation. Falls back to `title`, then filename.
|
|
54
|
+
- `order` — explicit deterministic order. Missing values sort after ordered
|
|
55
|
+
items by title and path.
|
|
56
|
+
- `hidden` — removes the page from sidebar and previous/next navigation.
|
|
57
|
+
- `collapsed` — exposes collapsed state through `data-docs-collapsed` for theme
|
|
58
|
+
or client enhancement.
|
|
59
|
+
|
|
60
|
+
All fields are optional. A page without `sidebar` frontmatter still appears in
|
|
61
|
+
the navigation: the hierarchy follows the folder structure, the label falls back
|
|
62
|
+
to `title`, and the order is title-based. `sidebar` is a Riebeckite extension, so
|
|
63
|
+
it lives with the content rather than in the site configuration. Add only the
|
|
64
|
+
fields you want to override and leave the rest of the vault untouched.
|
|
65
|
+
|
|
66
|
+
## Output and theme integration
|
|
67
|
+
|
|
68
|
+
The plugin provides React-like JSX components for site integration:
|
|
69
|
+
|
|
70
|
+
## l10n and publishing
|
|
71
|
+
|
|
72
|
+
When localization metadata from `@riebeckite/plugin-l10n` is present, each page
|
|
73
|
+
receives navigation for the current language only. The plugin always uses the
|
|
74
|
+
resolved manifest permalink, so permalink, alias, rename, and l10n URL behavior
|
|
75
|
+
remain owned by the content system.
|
|
76
|
+
|
|
77
|
+
Only published entries are included. Draft, private, excluded, hidden, and
|
|
78
|
+
outside-root content does not appear in the sidebar or previous/next sequence.
|
|
79
|
+
|
|
80
|
+
## Exports
|
|
81
|
+
|
|
82
|
+
- `docs(options)` / `docsPlugin(options)` — plugin factory
|
|
83
|
+
- `buildDocsNavigation(entries, options)` — build the framework-independent model
|
|
84
|
+
- `flattenDocsNavigation(items)` — derive the previous/next sequence
|
|
85
|
+
- `renderDocsSidebar(...)` and `renderDocsPrevNext(...)` — server HTML renderers
|
|
86
|
+
- `initDocsSidebar()` — browser init for the collapsible sidebar (also via
|
|
87
|
+
`@riebeckite/plugin-docs/client`)
|
|
88
|
+
- Types: `DocsOptions`, `ResolvedDocsOptions`, `DocsNavigationItem`
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @riebeckite/plugin-docs
|
|
2
|
+
|
|
3
|
+
<!-- Generated from docs/docs/plugins/docs.ja.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
|
|
4
|
+
|
|
5
|
+
Riebeckite の Markdown コンテンツから、Docs 用のサイドバーと前後ページリンクを
|
|
6
|
+
ビルド時に生成するプラグインです。Docs 専用の router は追加せず、公開 URL も
|
|
7
|
+
ファイルシステムのパスから再計算しません。
|
|
8
|
+
|
|
9
|
+
[English](./README.md)
|
|
10
|
+
|
|
11
|
+
## インストール
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @riebeckite/plugin-docs
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 基本設定
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineConfig } from "@riebeckite/core";
|
|
21
|
+
import { docs } from "@riebeckite/plugin-docs";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
plugins: [
|
|
25
|
+
docs({
|
|
26
|
+
root: "docs",
|
|
27
|
+
sidebar: { auto: true },
|
|
28
|
+
prevNext: true,
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`root` は Docs として扱うコンテンツサブツリーです。`root: "docs"` の場合、
|
|
35
|
+
`content/docs/` 配下だけが対象になり、`notes/` や `blog/` には Docs の UI を出しません。
|
|
36
|
+
|
|
37
|
+
## Frontmatter
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
---
|
|
41
|
+
title: Installation
|
|
42
|
+
sidebar:
|
|
43
|
+
label: Install
|
|
44
|
+
order: 2
|
|
45
|
+
hidden: false
|
|
46
|
+
collapsed: false
|
|
47
|
+
---
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
対応するメタデータは次の通りです。
|
|
51
|
+
|
|
52
|
+
- `label`: ナビゲーションに表示する名前。未指定なら `title`、さらに未指定ならファイル名。
|
|
53
|
+
- `order`: 明示的な並び順。未指定の項目は明示された order のあとを title、path の順に並びます。
|
|
54
|
+
- `hidden`: サイドバーと前後ページリンクから除外します。
|
|
55
|
+
- `collapsed`: Theme やクライアント側の拡張のために `data-docs-collapsed` として出力します。
|
|
56
|
+
|
|
57
|
+
これらのフィールドはすべて任意です。`sidebar` frontmatter のないページも
|
|
58
|
+
ナビゲーションに表示されます。階層はフォルダ構造に従い、ラベルは `title`、
|
|
59
|
+
並び順はタイトル順になります。`sidebar` は Riebeckite 独自の拡張であり、サイト
|
|
60
|
+
設定ではなくコンテンツ側に置きます。上書きしたいフィールドだけを指定し、それ
|
|
61
|
+
以外は Vault に手を入れないでください。
|
|
62
|
+
|
|
63
|
+
## Theme との統合
|
|
64
|
+
|
|
65
|
+
Plugin は React ライクな JSX コンポーネントをサイト統合に提供します。
|
|
66
|
+
|
|
67
|
+
- `<DocsSidebar items={...} currentPermalink? label? />` は `nav.rr-docs-sidebar` を描画
|
|
68
|
+
- `<DocsPrevNext previous? next? />` は `nav.rr-docs-prev-next` を描画
|
|
69
|
+
|
|
70
|
+
クライアント `initDocsSidebar` はフッタリング可能なサイドバー動作のためにそのまま残ります。
|
|
71
|
+
|
|
72
|
+
## l10n と公開の境界
|
|
73
|
+
|
|
74
|
+
`@riebeckite/plugin-l10n` のメタデータがある場合、現在の言語に対応する項目だけで
|
|
75
|
+
ナビゲーションを作ります。URL は manifest の解決済み permalink をそのまま使うため、
|
|
76
|
+
permalink / alias / rename / l10n の責務を壊しません。
|
|
77
|
+
|
|
78
|
+
公開対象の項目だけを含めます。draft、private、excluded、hidden、root 外のコンテンツは
|
|
79
|
+
サイドバーと前後ページリンクに出ません。
|
|
80
|
+
|
|
81
|
+
## エクスポート
|
|
82
|
+
|
|
83
|
+
- `docs(options)` / `docsPlugin(options)`: プラグインファクトリ
|
|
84
|
+
- `buildDocsNavigation(entries, options)`: フレームワークに依存しないナビゲーションモデル
|
|
85
|
+
- `flattenDocsNavigation(items)`: 前後ページリンク用の並び
|
|
86
|
+
- `renderDocsSidebar(...)` / `renderDocsPrevNext(...)`: サーバー側の HTML レンダラー
|
|
87
|
+
- `initDocsSidebar()`: 畳めるサイドバーのブラウザ側初期化(`@riebeckite/plugin-docs/client` からも読み込める)
|
|
88
|
+
- 型: `DocsOptions`、`ResolvedDocsOptions`、`DocsNavigationItem`
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initDocsSidebar } from "./src/docs-sidebar.client.js";
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/docs-sidebar.client.ts
|
|
2
|
+
var COLLAPSIBLE_PROPERTY = "--rb-docs-sidebar-collapsible";
|
|
3
|
+
function initDocsSidebar() {
|
|
4
|
+
const details = Array.from(
|
|
5
|
+
document.querySelectorAll(
|
|
6
|
+
"[data-docs-sidebar-details]"
|
|
7
|
+
)
|
|
8
|
+
);
|
|
9
|
+
const first = details[0];
|
|
10
|
+
if (!first) return;
|
|
11
|
+
let collapsible = isCollapsible(first);
|
|
12
|
+
const apply = (value) => {
|
|
13
|
+
for (const element of details) {
|
|
14
|
+
element.open = !value;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
apply(collapsible);
|
|
18
|
+
const sync = () => {
|
|
19
|
+
const next = isCollapsible(first);
|
|
20
|
+
if (next === collapsible) return;
|
|
21
|
+
collapsible = next;
|
|
22
|
+
apply(next);
|
|
23
|
+
};
|
|
24
|
+
window.addEventListener("resize", sync, { passive: true });
|
|
25
|
+
}
|
|
26
|
+
function isCollapsible(element) {
|
|
27
|
+
return getComputedStyle(element).getPropertyValue(COLLAPSIBLE_PROPERTY).trim() !== "0";
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
initDocsSidebar
|
|
31
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DocsNavigationLink } from "../src/types.js";
|
|
2
|
+
export type DocsPrevNextProps = {
|
|
3
|
+
readonly previous?: DocsNavigationLink;
|
|
4
|
+
readonly next?: DocsNavigationLink;
|
|
5
|
+
readonly language?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const DocsPrevNext: ({ previous, next, language, }: Readonly<DocsPrevNextProps>) => import("hono/jsx/jsx-dev-runtime").JSX.Element;
|
|
8
|
+
export default DocsPrevNext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DocsNavigationItem } from "../src/types.js";
|
|
2
|
+
export type DocsSidebarProps = {
|
|
3
|
+
readonly items: readonly DocsNavigationItem[];
|
|
4
|
+
readonly currentPermalink?: string;
|
|
5
|
+
readonly label?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const DocsSidebar: ({ items, currentPermalink, label, }: Readonly<DocsSidebarProps>) => import("hono/jsx/jsx-dev-runtime").JSX.Element;
|
|
8
|
+
export default DocsSidebar;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// components/docs-sidebar.tsx
|
|
2
|
+
import { jsx, jsxs } from "hono/jsx/jsx-runtime";
|
|
3
|
+
var DocsSidebar = (({
|
|
4
|
+
items,
|
|
5
|
+
currentPermalink,
|
|
6
|
+
label = "Docs navigation"
|
|
7
|
+
}) => {
|
|
8
|
+
if (items.length === 0) return null;
|
|
9
|
+
return /* @__PURE__ */ jsx("nav", { class: "rr-docs-sidebar", "aria-label": label, children: /* @__PURE__ */ jsx("ol", { class: "rr-docs-sidebar__list", children: items.map((item) => /* @__PURE__ */ jsx(
|
|
10
|
+
DocsSidebarItem,
|
|
11
|
+
{
|
|
12
|
+
item,
|
|
13
|
+
currentPermalink
|
|
14
|
+
},
|
|
15
|
+
`${item.slug ?? item.title}`
|
|
16
|
+
)) }) });
|
|
17
|
+
});
|
|
18
|
+
function DocsSidebarItem({
|
|
19
|
+
item,
|
|
20
|
+
currentPermalink
|
|
21
|
+
}) {
|
|
22
|
+
const current = item.href === currentPermalink;
|
|
23
|
+
return /* @__PURE__ */ jsxs("li", { class: "rr-docs-sidebar__item", children: [
|
|
24
|
+
item.href ? /* @__PURE__ */ jsx("a", { href: item.href, "aria-current": current ? "page" : void 0, children: item.title }) : /* @__PURE__ */ jsx("span", { children: item.title }),
|
|
25
|
+
item.children.length > 0 ? /* @__PURE__ */ jsx("ol", { class: "rr-docs-sidebar__list", children: item.children.map((child) => /* @__PURE__ */ jsx(
|
|
26
|
+
DocsSidebarItem,
|
|
27
|
+
{
|
|
28
|
+
item: child,
|
|
29
|
+
currentPermalink
|
|
30
|
+
},
|
|
31
|
+
`${child.slug ?? child.title}`
|
|
32
|
+
)) }) : null
|
|
33
|
+
] });
|
|
34
|
+
}
|
|
35
|
+
var docs_sidebar_default = DocsSidebar;
|
|
36
|
+
export {
|
|
37
|
+
docs_sidebar_default as default
|
|
38
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type PluginDataHelper, type PublicContentView } from "@riebeckite/core";
|
|
2
|
+
import type { DocsNavigationItem, DocsNavigationLink, DocsOptions } from "./src/types.js";
|
|
3
|
+
export type { DocsPrevNextProps } from "./components/docs-prev-next.js";
|
|
4
|
+
export { default as DocsPrevNext } from "./components/docs-prev-next.js";
|
|
5
|
+
export type { DocsSidebarProps } from "./components/docs-sidebar.js";
|
|
6
|
+
export { default as DocsSidebar } from "./components/docs-sidebar.js";
|
|
7
|
+
export { initDocsSidebar } from "./src/docs-sidebar.client.js";
|
|
8
|
+
export { buildDocsNavigation, flattenDocsNavigation, resolveDocsOptions, } from "./src/navigation.js";
|
|
9
|
+
export { renderDocsPrevNext, renderDocsSidebar } from "./src/render.js";
|
|
10
|
+
export type { DocsNavigationItem, DocsOptions, DocsSidebarFrontmatter, ResolvedDocsOptions, } from "./src/types.js";
|
|
11
|
+
export declare const getDocsNavigation: PluginDataHelper<{
|
|
12
|
+
view: PublicContentView;
|
|
13
|
+
entrySlug: string;
|
|
14
|
+
options: DocsOptions;
|
|
15
|
+
}, readonly DocsNavigationItem[]>;
|
|
16
|
+
export declare const getDocsPrevNext: PluginDataHelper<{
|
|
17
|
+
items: readonly DocsNavigationItem[];
|
|
18
|
+
slug: string;
|
|
19
|
+
}, {
|
|
20
|
+
readonly previous?: DocsNavigationLink;
|
|
21
|
+
readonly next?: DocsNavigationLink;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const DOCS_PLUGIN_NAME = "docs";
|
|
24
|
+
export declare function docs(options: DocsOptions): import("@riebeckite/core").RiebeckitePlugin<DocsOptions>;
|
|
25
|
+
export declare const docsPlugin: typeof docs;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
createClientEntry,
|
|
4
|
+
createStyleAsset,
|
|
5
|
+
definePlugin
|
|
6
|
+
} from "@riebeckite/core";
|
|
7
|
+
|
|
8
|
+
// src/navigation.ts
|
|
9
|
+
var ROOT_SEGMENT = "";
|
|
10
|
+
function resolveDocsOptions(options) {
|
|
11
|
+
return {
|
|
12
|
+
root: normalizeRoot(options.root),
|
|
13
|
+
sidebar: {
|
|
14
|
+
auto: options.sidebar?.auto ?? true,
|
|
15
|
+
label: options.sidebar?.label ?? "Docs navigation"
|
|
16
|
+
},
|
|
17
|
+
prevNext: options.prevNext ?? true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function buildDocsNavigation(entries, options) {
|
|
21
|
+
if (!options.sidebar.auto) return [];
|
|
22
|
+
const docsEntries = entries.map((entry) => toNavigationEntry(entry, options.root)).filter((entry) => Boolean(entry)).filter((entry) => !entry.hidden);
|
|
23
|
+
const root = createTreeNode(ROOT_SEGMENT);
|
|
24
|
+
for (const entry of docsEntries) addEntry(root, entry);
|
|
25
|
+
const rootIndex = root.index;
|
|
26
|
+
const items = buildItems(root, []);
|
|
27
|
+
if (!rootIndex) return items;
|
|
28
|
+
return [toItem(rootIndex, []), ...items];
|
|
29
|
+
}
|
|
30
|
+
function flattenDocsNavigation(items) {
|
|
31
|
+
return items.flatMap((item) => {
|
|
32
|
+
const current = item.href && item.slug ? [{ title: item.title, href: item.href, slug: item.slug }] : [];
|
|
33
|
+
return [...current, ...flattenDocsNavigation(item.children)];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function normalizeRoot(root) {
|
|
37
|
+
return root.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
38
|
+
}
|
|
39
|
+
function toNavigationEntry(entry, root) {
|
|
40
|
+
const relativePath = resolveRelativeDocsPath(entry, root);
|
|
41
|
+
if (!relativePath) return null;
|
|
42
|
+
const segments = relativePath.split("/").filter(Boolean);
|
|
43
|
+
const isIndex = ["index", "README"].includes(segments.at(-1) ?? "");
|
|
44
|
+
const sidebar = readSidebarFrontmatter(
|
|
45
|
+
"frontmatter" in entry ? entry.frontmatter.sidebar : void 0
|
|
46
|
+
);
|
|
47
|
+
return {
|
|
48
|
+
entry,
|
|
49
|
+
relativePath,
|
|
50
|
+
segments,
|
|
51
|
+
isIndex,
|
|
52
|
+
title: resolveTitle(entry, sidebar),
|
|
53
|
+
order: sidebar.order,
|
|
54
|
+
hidden: sidebar.hidden ?? false,
|
|
55
|
+
collapsed: sidebar.collapsed
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function resolveRelativeDocsPath(entry, root) {
|
|
59
|
+
if (entry.slug === root) return "index";
|
|
60
|
+
if (!entry.slug.startsWith(`${root}/`)) return null;
|
|
61
|
+
return stripFilenameLanguage(
|
|
62
|
+
entry.slug.slice(root.length + 1),
|
|
63
|
+
entry.publicLocation.language
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
function stripFilenameLanguage(path, language) {
|
|
67
|
+
if (!language) return path;
|
|
68
|
+
const segments = path.split("/");
|
|
69
|
+
const last = segments.at(-1);
|
|
70
|
+
if (last === void 0) return path;
|
|
71
|
+
segments[segments.length - 1] = last.replace(
|
|
72
|
+
new RegExp(`[._-]${escapeRegExp(language)}$`, "i"),
|
|
73
|
+
""
|
|
74
|
+
);
|
|
75
|
+
return segments.join("/");
|
|
76
|
+
}
|
|
77
|
+
function escapeRegExp(value) {
|
|
78
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
79
|
+
}
|
|
80
|
+
function readSidebarFrontmatter(value) {
|
|
81
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
82
|
+
const record = value;
|
|
83
|
+
return {
|
|
84
|
+
...typeof record.label === "string" && record.label.trim() ? { label: record.label.trim() } : {},
|
|
85
|
+
...typeof record.order === "number" && Number.isFinite(record.order) ? { order: record.order } : {},
|
|
86
|
+
...typeof record.hidden === "boolean" ? { hidden: record.hidden } : {},
|
|
87
|
+
...typeof record.collapsed === "boolean" ? { collapsed: record.collapsed } : {}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function resolveTitle(entry, sidebar) {
|
|
91
|
+
if (sidebar.label) return sidebar.label;
|
|
92
|
+
if (entry.title.trim()) return entry.title.trim();
|
|
93
|
+
return titleFromSegment(entry.slug.split("/").at(-1) ?? entry.slug);
|
|
94
|
+
}
|
|
95
|
+
function addEntry(root, entry) {
|
|
96
|
+
const path = entry.isIndex ? entry.segments.slice(0, -1) : entry.segments;
|
|
97
|
+
let node = root;
|
|
98
|
+
for (const segment of path) {
|
|
99
|
+
const child = node.children.get(segment) ?? createTreeNode(segment);
|
|
100
|
+
node.children.set(segment, child);
|
|
101
|
+
node = child;
|
|
102
|
+
}
|
|
103
|
+
if (entry.isIndex) node.index = entry;
|
|
104
|
+
else node.page = entry;
|
|
105
|
+
}
|
|
106
|
+
function buildItems(node, path) {
|
|
107
|
+
return [...node.children.values()].toSorted(compareNodes).map((child) => nodeToItem(child, [...path, child.segment]));
|
|
108
|
+
}
|
|
109
|
+
function nodeToItem(node, path) {
|
|
110
|
+
const primary = node.index ?? node.page;
|
|
111
|
+
const children = [
|
|
112
|
+
...node.index && node.page ? [toItem(node.page, [])] : [],
|
|
113
|
+
...buildItems(node, path)
|
|
114
|
+
];
|
|
115
|
+
if (primary) return toItem(primary, children);
|
|
116
|
+
return {
|
|
117
|
+
title: titleFromSegment(node.segment),
|
|
118
|
+
children
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function toItem(entry, children) {
|
|
122
|
+
return {
|
|
123
|
+
title: entry.title,
|
|
124
|
+
href: entry.entry.permalink,
|
|
125
|
+
slug: entry.entry.slug,
|
|
126
|
+
...entry.order === void 0 ? {} : { order: entry.order },
|
|
127
|
+
...entry.collapsed === void 0 ? {} : { collapsed: entry.collapsed },
|
|
128
|
+
children
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function compareNodes(a, b) {
|
|
132
|
+
const left = a.index ?? a.page;
|
|
133
|
+
const right = b.index ?? b.page;
|
|
134
|
+
return compareNavigationKeys(
|
|
135
|
+
left?.order,
|
|
136
|
+
left?.title ?? titleFromSegment(a.segment),
|
|
137
|
+
a.segment,
|
|
138
|
+
right?.order,
|
|
139
|
+
right?.title ?? titleFromSegment(b.segment),
|
|
140
|
+
b.segment
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
function compareNavigationKeys(leftOrder, leftTitle, leftPath, rightOrder, rightTitle, rightPath) {
|
|
144
|
+
if (leftOrder !== void 0 || rightOrder !== void 0) {
|
|
145
|
+
if (leftOrder === void 0) return 1;
|
|
146
|
+
if (rightOrder === void 0) return -1;
|
|
147
|
+
const order = leftOrder - rightOrder;
|
|
148
|
+
if (order !== 0) return order;
|
|
149
|
+
}
|
|
150
|
+
const title = leftTitle.localeCompare(rightTitle, "en", {
|
|
151
|
+
sensitivity: "base"
|
|
152
|
+
});
|
|
153
|
+
if (title !== 0) return title;
|
|
154
|
+
return leftPath.localeCompare(rightPath, "en", { sensitivity: "base" });
|
|
155
|
+
}
|
|
156
|
+
function createTreeNode(segment) {
|
|
157
|
+
return { segment, children: /* @__PURE__ */ new Map() };
|
|
158
|
+
}
|
|
159
|
+
function titleFromSegment(segment) {
|
|
160
|
+
return segment.replace(/[-_]+/g, " ").replace(/\b\p{L}/gu, (letter) => letter.toLocaleUpperCase("en"));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// components/docs-prev-next.tsx
|
|
164
|
+
import { jsx, jsxs } from "hono/jsx/jsx-runtime";
|
|
165
|
+
var DocsPrevNext = (({
|
|
166
|
+
previous,
|
|
167
|
+
next,
|
|
168
|
+
language
|
|
169
|
+
}) => {
|
|
170
|
+
if (!previous && !next) return null;
|
|
171
|
+
const labels = language === "ja" ? { nav: "前後のドキュメント", previous: "前へ", next: "次へ" } : {
|
|
172
|
+
nav: "Previous and next docs pages",
|
|
173
|
+
previous: "Previous",
|
|
174
|
+
next: "Next"
|
|
175
|
+
};
|
|
176
|
+
return /* @__PURE__ */ jsxs("nav", { class: "rb-docs-prev-next", "aria-label": labels.nav, "data-docs-prev-next": true, children: [
|
|
177
|
+
previous ? /* @__PURE__ */ jsxs(
|
|
178
|
+
"a",
|
|
179
|
+
{
|
|
180
|
+
class: "rb-docs-prev-next__link rb-docs-prev-next__link--previous",
|
|
181
|
+
rel: "prev",
|
|
182
|
+
href: previous.href,
|
|
183
|
+
"data-docs-previous": true,
|
|
184
|
+
children: [
|
|
185
|
+
/* @__PURE__ */ jsx("span", { class: "rb-docs-prev-next__label", children: labels.previous }),
|
|
186
|
+
/* @__PURE__ */ jsxs("span", { class: "rb-docs-prev-next__title", children: [
|
|
187
|
+
"← ",
|
|
188
|
+
previous.title
|
|
189
|
+
] })
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
) : /* @__PURE__ */ jsx("span", { class: "rb-docs-prev-next__spacer", "aria-hidden": "true" }),
|
|
193
|
+
next ? /* @__PURE__ */ jsxs(
|
|
194
|
+
"a",
|
|
195
|
+
{
|
|
196
|
+
class: "rb-docs-prev-next__link rb-docs-prev-next__link--next",
|
|
197
|
+
rel: "next",
|
|
198
|
+
href: next.href,
|
|
199
|
+
"data-docs-next": true,
|
|
200
|
+
children: [
|
|
201
|
+
/* @__PURE__ */ jsx("span", { class: "rb-docs-prev-next__label", children: labels.next }),
|
|
202
|
+
/* @__PURE__ */ jsxs("span", { class: "rb-docs-prev-next__title", children: [
|
|
203
|
+
next.title,
|
|
204
|
+
" →"
|
|
205
|
+
] })
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
) : null
|
|
209
|
+
] });
|
|
210
|
+
});
|
|
211
|
+
var docs_prev_next_default = DocsPrevNext;
|
|
212
|
+
|
|
213
|
+
// components/docs-sidebar.tsx
|
|
214
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "hono/jsx/jsx-runtime";
|
|
215
|
+
var DocsSidebar = (({
|
|
216
|
+
items,
|
|
217
|
+
currentPermalink,
|
|
218
|
+
label = "Docs navigation"
|
|
219
|
+
}) => {
|
|
220
|
+
if (items.length === 0) return null;
|
|
221
|
+
return /* @__PURE__ */ jsx2("nav", { class: "rr-docs-sidebar", "aria-label": label, children: /* @__PURE__ */ jsx2("ol", { class: "rr-docs-sidebar__list", children: items.map((item) => /* @__PURE__ */ jsx2(
|
|
222
|
+
DocsSidebarItem,
|
|
223
|
+
{
|
|
224
|
+
item,
|
|
225
|
+
currentPermalink
|
|
226
|
+
},
|
|
227
|
+
`${item.slug ?? item.title}`
|
|
228
|
+
)) }) });
|
|
229
|
+
});
|
|
230
|
+
function DocsSidebarItem({
|
|
231
|
+
item,
|
|
232
|
+
currentPermalink
|
|
233
|
+
}) {
|
|
234
|
+
const current = item.href === currentPermalink;
|
|
235
|
+
return /* @__PURE__ */ jsxs2("li", { class: "rr-docs-sidebar__item", children: [
|
|
236
|
+
item.href ? /* @__PURE__ */ jsx2("a", { href: item.href, "aria-current": current ? "page" : void 0, children: item.title }) : /* @__PURE__ */ jsx2("span", { children: item.title }),
|
|
237
|
+
item.children.length > 0 ? /* @__PURE__ */ jsx2("ol", { class: "rr-docs-sidebar__list", children: item.children.map((child) => /* @__PURE__ */ jsx2(
|
|
238
|
+
DocsSidebarItem,
|
|
239
|
+
{
|
|
240
|
+
item: child,
|
|
241
|
+
currentPermalink
|
|
242
|
+
},
|
|
243
|
+
`${child.slug ?? child.title}`
|
|
244
|
+
)) }) : null
|
|
245
|
+
] });
|
|
246
|
+
}
|
|
247
|
+
var docs_sidebar_default = DocsSidebar;
|
|
248
|
+
|
|
249
|
+
// src/docs-sidebar.client.ts
|
|
250
|
+
var COLLAPSIBLE_PROPERTY = "--rb-docs-sidebar-collapsible";
|
|
251
|
+
function initDocsSidebar() {
|
|
252
|
+
const details = Array.from(
|
|
253
|
+
document.querySelectorAll(
|
|
254
|
+
"[data-docs-sidebar-details]"
|
|
255
|
+
)
|
|
256
|
+
);
|
|
257
|
+
const first = details[0];
|
|
258
|
+
if (!first) return;
|
|
259
|
+
let collapsible = isCollapsible(first);
|
|
260
|
+
const apply = (value) => {
|
|
261
|
+
for (const element of details) {
|
|
262
|
+
element.open = !value;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
apply(collapsible);
|
|
266
|
+
const sync = () => {
|
|
267
|
+
const next = isCollapsible(first);
|
|
268
|
+
if (next === collapsible) return;
|
|
269
|
+
collapsible = next;
|
|
270
|
+
apply(next);
|
|
271
|
+
};
|
|
272
|
+
window.addEventListener("resize", sync, { passive: true });
|
|
273
|
+
}
|
|
274
|
+
function isCollapsible(element) {
|
|
275
|
+
return getComputedStyle(element).getPropertyValue(COLLAPSIBLE_PROPERTY).trim() !== "0";
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/render.ts
|
|
279
|
+
function renderDocsSidebar(context) {
|
|
280
|
+
if (context.items.length === 0) return "";
|
|
281
|
+
const label = escapeAttribute(context.label);
|
|
282
|
+
return `<details class="rb-docs-sidebar-details" data-docs-sidebar-details open><summary class="rb-docs-sidebar-summary">${label}</summary><nav class="rb-docs-sidebar" aria-label="${label}" data-docs-sidebar>${renderItems(context.items, context.currentPermalink, 1)}</nav></details>`;
|
|
283
|
+
}
|
|
284
|
+
function renderDocsPrevNext(sequence, currentPermalink, language) {
|
|
285
|
+
const index = sequence.findIndex((item) => item.href === currentPermalink);
|
|
286
|
+
if (index < 0) return "";
|
|
287
|
+
const previous = sequence[index - 1];
|
|
288
|
+
const next = sequence[index + 1];
|
|
289
|
+
if (!previous && !next) return "";
|
|
290
|
+
const labels = prevNextLabels(language);
|
|
291
|
+
return `<nav class="rb-docs-prev-next" aria-label="${escapeAttribute(labels.nav)}" data-docs-prev-next>${renderPrevNextLink(previous, "previous", labels)} ${renderPrevNextLink(next, "next", labels)}</nav>`;
|
|
292
|
+
}
|
|
293
|
+
function renderItems(items, currentPermalink, level) {
|
|
294
|
+
return `<ul class="rb-docs-sidebar__list rb-docs-sidebar__list--level-${level}" data-docs-level="${level}">${items.map((item) => renderItem(item, currentPermalink, level)).join("")}</ul>`;
|
|
295
|
+
}
|
|
296
|
+
function renderItem(item, currentPermalink, level) {
|
|
297
|
+
const isCurrent = item.href === currentPermalink;
|
|
298
|
+
const isCurrentBranch = item.children.some(
|
|
299
|
+
(child) => containsPermalink(child, currentPermalink)
|
|
300
|
+
);
|
|
301
|
+
const children = item.children.length > 0 ? renderItems(item.children, currentPermalink, level + 1) : "";
|
|
302
|
+
const collapsed = item.collapsed === true && !isCurrent && !isCurrentBranch;
|
|
303
|
+
const state = item.children.length > 0 ? ` data-docs-collapsed="${collapsed ? "true" : "false"}"` : "";
|
|
304
|
+
return `<li class="rb-docs-sidebar__item rb-docs-sidebar__item--level-${level}" data-docs-level="${level}"${state}>${renderItemLabel(item, isCurrent)}${children}</li>`;
|
|
305
|
+
}
|
|
306
|
+
function containsPermalink(item, currentPermalink) {
|
|
307
|
+
return item.href === currentPermalink || item.children.some((child) => containsPermalink(child, currentPermalink));
|
|
308
|
+
}
|
|
309
|
+
function renderItemLabel(item, isCurrent) {
|
|
310
|
+
const current = isCurrent ? ' aria-current="page"' : "";
|
|
311
|
+
if (!item.href)
|
|
312
|
+
return `<span class="rb-docs-sidebar__section" data-docs-section>${escapeHtml(item.title)}</span>`;
|
|
313
|
+
return `<a class="rb-docs-sidebar__link" href="${escapeAttribute(item.href)}" data-docs-link${current}>${escapeHtml(item.title)}</a>`;
|
|
314
|
+
}
|
|
315
|
+
function renderPrevNextLink(item, rel, labels) {
|
|
316
|
+
if (!item)
|
|
317
|
+
return `<span class="rb-docs-prev-next__spacer" aria-hidden="true"></span>`;
|
|
318
|
+
const label = rel === "previous" ? labels.previous : labels.next;
|
|
319
|
+
const arrow = rel === "previous" ? "←" : "→";
|
|
320
|
+
return `<a class="rb-docs-prev-next__link rb-docs-prev-next__link--${rel}" href="${escapeAttribute(item.href)}" data-docs-${rel}><span class="rb-docs-prev-next__label">${label}</span><span class="rb-docs-prev-next__title">${rel === "previous" ? `${arrow} ` : ""}${escapeHtml(item.title)}${rel === "next" ? ` ${arrow}` : ""}</span></a>`;
|
|
321
|
+
}
|
|
322
|
+
var PREV_NEXT_LABELS = {
|
|
323
|
+
en: {
|
|
324
|
+
nav: "Previous and next docs pages",
|
|
325
|
+
previous: "Previous",
|
|
326
|
+
next: "Next"
|
|
327
|
+
},
|
|
328
|
+
ja: {
|
|
329
|
+
nav: "前後のドキュメント",
|
|
330
|
+
previous: "前へ",
|
|
331
|
+
next: "次へ"
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
function prevNextLabels(language) {
|
|
335
|
+
if (language === "ja") return PREV_NEXT_LABELS.ja;
|
|
336
|
+
return PREV_NEXT_LABELS.en;
|
|
337
|
+
}
|
|
338
|
+
function escapeHtml(value) {
|
|
339
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
340
|
+
}
|
|
341
|
+
function escapeAttribute(value) {
|
|
342
|
+
return escapeHtml(value);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// index.ts
|
|
346
|
+
var getDocsNavigation = ({ view, entrySlug, options }) => {
|
|
347
|
+
const entry = view.findRoutableBySlug(entrySlug);
|
|
348
|
+
if (!entry) return [];
|
|
349
|
+
const localized = view.discoverableEntries.filter(
|
|
350
|
+
(candidate) => candidate.publicLocation.language === entry.publicLocation.language
|
|
351
|
+
);
|
|
352
|
+
return buildDocsNavigation(localized, resolveDocsOptions(options));
|
|
353
|
+
};
|
|
354
|
+
var getDocsPrevNext = ({ items, slug }) => {
|
|
355
|
+
const sequence = flattenDocsNavigation(items);
|
|
356
|
+
const index = sequence.findIndex((item) => item.slug === slug);
|
|
357
|
+
if (index < 0) return {};
|
|
358
|
+
return {
|
|
359
|
+
...sequence[index - 1] ? { previous: sequence[index - 1] } : {},
|
|
360
|
+
...sequence[index + 1] ? { next: sequence[index + 1] } : {}
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
var DOCS_PLUGIN_NAME = "docs";
|
|
364
|
+
function docs(options) {
|
|
365
|
+
const resolved = resolveDocsOptions(options);
|
|
366
|
+
return definePlugin({
|
|
367
|
+
name: `${DOCS_PLUGIN_NAME}:${resolved.root}`,
|
|
368
|
+
order: 300,
|
|
369
|
+
contentOutputDependencies: [{ type: "global" }],
|
|
370
|
+
options,
|
|
371
|
+
validateOptions: validateDocsOptions,
|
|
372
|
+
assets: [
|
|
373
|
+
createStyleAsset(DOCS_PLUGIN_NAME, "@riebeckite/plugin-docs/style.css")
|
|
374
|
+
],
|
|
375
|
+
clientEntries: [
|
|
376
|
+
createClientEntry(
|
|
377
|
+
DOCS_PLUGIN_NAME,
|
|
378
|
+
"@riebeckite/plugin-docs/client",
|
|
379
|
+
"initDocsSidebar"
|
|
380
|
+
)
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
var docsPlugin = docs;
|
|
385
|
+
function validateDocsOptions(options) {
|
|
386
|
+
const issues = [];
|
|
387
|
+
if (!options || typeof options !== "object") {
|
|
388
|
+
return [{ path: "docs", message: "Expected docs options." }];
|
|
389
|
+
}
|
|
390
|
+
if (typeof options.root !== "string" || options.root.trim() === "") {
|
|
391
|
+
issues.push({ path: "root", message: "Expected a non-empty string." });
|
|
392
|
+
}
|
|
393
|
+
if (options.sidebar !== void 0 && typeof options.sidebar !== "object") {
|
|
394
|
+
issues.push({ path: "sidebar", message: "Expected an object." });
|
|
395
|
+
}
|
|
396
|
+
if (options.prevNext !== void 0 && typeof options.prevNext !== "boolean") {
|
|
397
|
+
issues.push({ path: "prevNext", message: "Expected a boolean." });
|
|
398
|
+
}
|
|
399
|
+
return issues;
|
|
400
|
+
}
|
|
401
|
+
export {
|
|
402
|
+
DOCS_PLUGIN_NAME,
|
|
403
|
+
docs_prev_next_default as DocsPrevNext,
|
|
404
|
+
docs_sidebar_default as DocsSidebar,
|
|
405
|
+
buildDocsNavigation,
|
|
406
|
+
docs,
|
|
407
|
+
docsPlugin,
|
|
408
|
+
flattenDocsNavigation,
|
|
409
|
+
getDocsNavigation,
|
|
410
|
+
getDocsPrevNext,
|
|
411
|
+
initDocsSidebar,
|
|
412
|
+
renderDocsPrevNext,
|
|
413
|
+
renderDocsSidebar,
|
|
414
|
+
resolveDocsOptions
|
|
415
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initDocsSidebar(): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DocsContentEntry, DocsNavigationItem, DocsNavigationLink, DocsOptions, ResolvedDocsOptions } from "./types.js";
|
|
2
|
+
export declare function resolveDocsOptions(options: DocsOptions): ResolvedDocsOptions;
|
|
3
|
+
export declare function buildDocsNavigation(entries: readonly DocsContentEntry[], options: ResolvedDocsOptions): readonly DocsNavigationItem[];
|
|
4
|
+
export declare function flattenDocsNavigation(items: readonly DocsNavigationItem[]): readonly DocsNavigationLink[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DocsNavigationItem, DocsNavigationLink } from "./types.js";
|
|
2
|
+
export declare function renderDocsSidebar(context: {
|
|
3
|
+
readonly items: readonly DocsNavigationItem[];
|
|
4
|
+
readonly currentPermalink: string;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function renderDocsPrevNext(sequence: readonly DocsNavigationLink[], currentPermalink: string, language?: string): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ContentManifestEntry, PublicContentEntry } from "@riebeckite/core";
|
|
2
|
+
export type DocsContentEntry = ContentManifestEntry | PublicContentEntry;
|
|
3
|
+
export type DocsOptions = {
|
|
4
|
+
readonly root: string;
|
|
5
|
+
readonly sidebar?: {
|
|
6
|
+
readonly auto?: boolean;
|
|
7
|
+
readonly label?: string;
|
|
8
|
+
};
|
|
9
|
+
readonly prevNext?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ResolvedDocsOptions = {
|
|
12
|
+
readonly root: string;
|
|
13
|
+
readonly sidebar: {
|
|
14
|
+
readonly auto: boolean;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
};
|
|
17
|
+
readonly prevNext: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type DocsSidebarFrontmatter = {
|
|
20
|
+
readonly label?: string;
|
|
21
|
+
readonly order?: number;
|
|
22
|
+
readonly hidden?: boolean;
|
|
23
|
+
readonly collapsed?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type DocsNavigationItem = {
|
|
26
|
+
readonly title: string;
|
|
27
|
+
readonly href?: string;
|
|
28
|
+
readonly slug?: string;
|
|
29
|
+
readonly order?: number;
|
|
30
|
+
readonly collapsed?: boolean;
|
|
31
|
+
readonly children: readonly DocsNavigationItem[];
|
|
32
|
+
};
|
|
33
|
+
export type DocsNavigationEntry = {
|
|
34
|
+
readonly entry: DocsContentEntry;
|
|
35
|
+
readonly relativePath: string;
|
|
36
|
+
readonly segments: readonly string[];
|
|
37
|
+
readonly isIndex: boolean;
|
|
38
|
+
readonly title: string;
|
|
39
|
+
readonly order: number | undefined;
|
|
40
|
+
readonly hidden: boolean;
|
|
41
|
+
readonly collapsed: boolean | undefined;
|
|
42
|
+
};
|
|
43
|
+
export type DocsNavigationLink = {
|
|
44
|
+
readonly title: string;
|
|
45
|
+
readonly href: string;
|
|
46
|
+
readonly slug: string;
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-docs",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.23",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"source": "./index.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client.d.ts",
|
|
17
|
+
"import": "./dist/client.js",
|
|
18
|
+
"source": "./client.ts",
|
|
19
|
+
"default": "./dist/client.js"
|
|
20
|
+
},
|
|
21
|
+
"./components": {
|
|
22
|
+
"types": "./dist/components/docs-sidebar.d.ts",
|
|
23
|
+
"import": "./dist/components/docs-sidebar.js",
|
|
24
|
+
"source": "./components/docs-sidebar.tsx",
|
|
25
|
+
"default": "./dist/components/docs-sidebar.js"
|
|
26
|
+
},
|
|
27
|
+
"./style.css": "./style.css"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"hono": "^4.12.25",
|
|
31
|
+
"@riebeckite/core": "0.0.23"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsx": "^4.22.4",
|
|
35
|
+
"@riebeckite/test": "0.0.23"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"README.md",
|
|
43
|
+
"README_ja.md",
|
|
44
|
+
"dist",
|
|
45
|
+
"style.css"
|
|
46
|
+
],
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
50
|
+
"directory": "packages/plugins/docs"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
55
|
+
},
|
|
56
|
+
"description": "Build-time docs sidebar and previous/next navigation for Riebeckite.",
|
|
57
|
+
"keywords": [
|
|
58
|
+
"riebeckite",
|
|
59
|
+
"plugin",
|
|
60
|
+
"docs",
|
|
61
|
+
"navigation"
|
|
62
|
+
],
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
65
|
+
},
|
|
66
|
+
"sideEffects": [
|
|
67
|
+
"./style.css"
|
|
68
|
+
],
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "node ../../../scripts/build_package.mjs",
|
|
71
|
+
"test": "node --import tsx --test \"test/*.test.ts\""
|
|
72
|
+
}
|
|
6
73
|
}
|
package/style.css
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
.rb-docs-sidebar-details {
|
|
2
|
+
--rb-docs-sidebar-collapsible: 1;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.rb-docs-sidebar-details > .rb-docs-sidebar-summary {
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
font-size: 0.95rem;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (min-width: 88rem) {
|
|
11
|
+
.rb-docs-sidebar-details {
|
|
12
|
+
--rb-docs-sidebar-collapsible: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.rb-docs-sidebar-details > .rb-docs-sidebar-summary {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.rb-docs-sidebar {
|
|
21
|
+
font-size: 0.95rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.rb-docs-sidebar__list {
|
|
25
|
+
list-style: none;
|
|
26
|
+
margin: 0;
|
|
27
|
+
padding: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.rb-docs-sidebar__list--level-2,
|
|
31
|
+
.rb-docs-sidebar__list--level-3,
|
|
32
|
+
.rb-docs-sidebar__list--level-4 {
|
|
33
|
+
margin-block-start: 0.25rem;
|
|
34
|
+
padding-inline-start: 1rem;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.rb-docs-sidebar__item + .rb-docs-sidebar__item {
|
|
38
|
+
margin-block-start: 0.25rem;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.rb-docs-sidebar__item[data-docs-collapsed="true"] > .rb-docs-sidebar__list {
|
|
42
|
+
display: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rb-docs-sidebar__link,
|
|
46
|
+
.rb-docs-sidebar__section {
|
|
47
|
+
display: block;
|
|
48
|
+
color: inherit;
|
|
49
|
+
text-decoration: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.rb-docs-sidebar__link[aria-current="page"] {
|
|
53
|
+
font-weight: 700;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.rb-docs-prev-next {
|
|
57
|
+
display: flex;
|
|
58
|
+
flex-wrap: wrap;
|
|
59
|
+
justify-content: space-between;
|
|
60
|
+
gap: 1rem;
|
|
61
|
+
margin-block-start: var(--rb-space-6, 3rem);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.rb-docs-prev-next__link {
|
|
65
|
+
flex: 1 1 14rem;
|
|
66
|
+
min-width: 0;
|
|
67
|
+
color: inherit;
|
|
68
|
+
overflow-wrap: anywhere;
|
|
69
|
+
text-decoration: none;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.rb-docs-prev-next__link--next {
|
|
73
|
+
margin-inline-start: auto;
|
|
74
|
+
text-align: end;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.rb-docs-prev-next__label {
|
|
78
|
+
display: block;
|
|
79
|
+
font-size: 0.75em;
|
|
80
|
+
opacity: 0.72;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.rb-docs-prev-next__spacer {
|
|
84
|
+
flex: 1 1 14rem;
|
|
85
|
+
}
|