@riebeckite/plugin-folder-pages 0.0.0-stage → 0.0.16
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 +72 -2
- package/README_ja.md +73 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +325 -0
- package/dist/src/folder_pages.d.ts +4 -0
- package/dist/src/options.d.ts +5 -0
- package/dist/src/pages.d.ts +5 -0
- package/dist/src/types.d.ts +27 -0
- package/package.json +54 -3
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,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @riebeckite/plugin-folder-pages
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[日本語](./README_ja.md)
|
|
4
|
+
|
|
5
|
+
Folder Page support for Riebeckite. The plugin turns folder entry notes into the
|
|
6
|
+
folder's landing page and generates a listing page for folders that have no
|
|
7
|
+
entry note.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @riebeckite/plugin-folder-pages
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { folderPages } from "@riebeckite/plugin-folder-pages";
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
plugins: [folderPages()],
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Markdown-backed Folder Pages
|
|
26
|
+
|
|
27
|
+
A note at `<folder>/README.md` or `<folder>/index.md` becomes the folder's
|
|
28
|
+
landing page. Its resolved permalink is collapsed from `/folder/README` or
|
|
29
|
+
`/folder/index` to `/folder/`, and the old URL redirects to the new one.
|
|
30
|
+
|
|
31
|
+
The collapse never guesses a URL from the slug. It rewrites the permalink that
|
|
32
|
+
the location resolver already produced, so localized and custom permalinks stay
|
|
33
|
+
correct.
|
|
34
|
+
|
|
35
|
+
Only `README` and `index` are treated as folder entries. A note at
|
|
36
|
+
`<folder>.md` stays a normal content page.
|
|
37
|
+
|
|
38
|
+
When a folder contains both `README.md` and `index.md`, neither is collapsed:
|
|
39
|
+
the choice would be ambiguous, so the plugin leaves both notes at their default
|
|
40
|
+
locations.
|
|
41
|
+
|
|
42
|
+
## Generated Folder Pages
|
|
43
|
+
|
|
44
|
+
Folders without a markdown entry note but with discoverable content get an
|
|
45
|
+
automatically generated page at `/folder/`. The page lists only the folder's
|
|
46
|
+
direct children:
|
|
47
|
+
|
|
48
|
+
- **Pages**: direct public, discoverable notes.
|
|
49
|
+
- **Folders**: direct subfolders that contain discoverable content.
|
|
50
|
+
|
|
51
|
+
The listing is built from `manifest.discoverableEntries`, so unlisted, draft,
|
|
52
|
+
and scheduled notes never appear. Notes reachable only by URL stay hidden from
|
|
53
|
+
the navigation. The `folder.md` case is never confused with a folder entry.
|
|
54
|
+
|
|
55
|
+
## Ordering
|
|
56
|
+
|
|
57
|
+
Pages and folders are sorted by their resolved permalink, then by title, so the
|
|
58
|
+
output is deterministic regardless of plugin order.
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
| Option | Type | Default | Description |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `className` | `string` | `"rr-folder-page"` | Root CSS class for the rendered fragment. |
|
|
65
|
+
| `pagesLabel` | `string` | `"Pages"` | Heading for the page list. |
|
|
66
|
+
| `foldersLabel` | `string` | `"Folders"` | Heading for the folder list. |
|
|
67
|
+
|
|
68
|
+
## Plugin dependencies
|
|
69
|
+
|
|
70
|
+
The plugin declares an optional dependency on the `content.localization`
|
|
71
|
+
capability. When `@riebeckite/plugin-l10n` is enabled, the folder page location
|
|
72
|
+
rewrite runs after localization so the collapsed URLs and redirects use the
|
|
73
|
+
final, localized permalinks. Without l10n, the plugin still works on its own.
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @riebeckite/plugin-folder-pages
|
|
2
|
+
|
|
3
|
+
[English](./README.md)
|
|
4
|
+
|
|
5
|
+
Riebeckite の Folder Page を提供するプラグインです。フォルダの入口ノートを
|
|
6
|
+
フォルダのランディングページにし、入口ノートのないフォルダには一覧ページを
|
|
7
|
+
自動生成します。
|
|
8
|
+
|
|
9
|
+
## インストール
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @riebeckite/plugin-folder-pages
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使い方
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { folderPages } from "@riebeckite/plugin-folder-pages";
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
plugins: [folderPages()],
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Markdown ベースの Folder Page
|
|
26
|
+
|
|
27
|
+
`<folder>/README.md` または `<folder>/index.md` にあるノートは、そのフォルダの
|
|
28
|
+
ランディングページになります。解決済みの permalink を `/folder/README` や
|
|
29
|
+
`/folder/index` から `/folder/` へ畳み込み、元の URL から新しい URL へ
|
|
30
|
+
リダイレクトします。
|
|
31
|
+
|
|
32
|
+
畳み込みは slug から URL を推測しません。ロケーションリゾルバが確定させた
|
|
33
|
+
permalink を書き換えるため、l10n やカスタム permalink でも正しい URL を
|
|
34
|
+
維持します。
|
|
35
|
+
|
|
36
|
+
フォルダ入口として扱うのは `README` と `index` だけです。`<folder>.md` は
|
|
37
|
+
通常のコンテンツページのままです。
|
|
38
|
+
|
|
39
|
+
同じフォルダに `README.md` と `index.md` の両方がある場合は、どちらも
|
|
40
|
+
畳み込みません。暗黙に一方を選ぶと曖昧になるためです。
|
|
41
|
+
|
|
42
|
+
## 自動生成される Folder Page
|
|
43
|
+
|
|
44
|
+
入口ノートを持たず、公開されたコンテンツがあるフォルダには `/folder/` に
|
|
45
|
+
ページを自動生成します。表示するのはフォルダ直下の要素だけです。
|
|
46
|
+
|
|
47
|
+
- **Pages**: 直下の公開・discoverable なノート
|
|
48
|
+
- **Folders**: discoverable なコンテンツを持つ直下のサブフォルダ
|
|
49
|
+
|
|
50
|
+
一覧は `manifest.discoverableEntries` を基準に作るため、unlisted・draft・
|
|
51
|
+
scheduled のノートは表示されません。URL を知っていれば到達できるノートと、
|
|
52
|
+
自動ナビゲーションから発見できるノートを区別します。`folder.md` を
|
|
53
|
+
フォルダ入口と混同することもありません。
|
|
54
|
+
|
|
55
|
+
## 並び順
|
|
56
|
+
|
|
57
|
+
Pages と Folders は解決済み permalink、次に title で並べます。プラグインの
|
|
58
|
+
順序に依存せず、出力は常に決定的です。
|
|
59
|
+
|
|
60
|
+
## オプション
|
|
61
|
+
|
|
62
|
+
| オプション | 型 | 既定値 | 説明 |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `className` | `string` | `"rr-folder-page"` | 生成するフラグメントのルート CSS クラス。 |
|
|
65
|
+
| `pagesLabel` | `string` | `"Pages"` | ページ一覧の見出し。 |
|
|
66
|
+
| `foldersLabel` | `string` | `"Folders"` | フォルダ一覧の見出し。 |
|
|
67
|
+
|
|
68
|
+
## プラグイン依存
|
|
69
|
+
|
|
70
|
+
`content.localization` capability への任意依存を宣言しています。
|
|
71
|
+
`@riebeckite/plugin-l10n` を有効にすると、フォルダページのロケーション
|
|
72
|
+
書き換えがローカライズの後に実行され、畳み込み後の URL とリダイレクトが
|
|
73
|
+
最終的なローカライズ済み permalink を使います。l10n なしでも単独で動作します。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FolderPagesOptions } from "./src/types.js";
|
|
2
|
+
export { buildFolderPages, collapseFolderEntryLocations, } from "./src/folder_pages.js";
|
|
3
|
+
export { DEFAULT_FOLDER_PAGES_CLASS_NAME, DEFAULT_FOLDER_PAGES_FOLDERS_LABEL, DEFAULT_FOLDER_PAGES_PAGES_LABEL, resolveFolderPagesOptions, } from "./src/options.js";
|
|
4
|
+
export { renderFolderPage } from "./src/pages.js";
|
|
5
|
+
export type { FolderPage, FolderPageLink, FolderPagesModel, FolderPagesOptions, ResolvedFolderPagesOptions, } from "./src/types.js";
|
|
6
|
+
export declare const FOLDER_PAGES_PLUGIN_NAME = "folder-pages";
|
|
7
|
+
export declare function folderPages(options?: FolderPagesOptions): import("@riebeckite/core").RiebeckitePlugin<FolderPagesOptions>;
|
|
8
|
+
export declare const folderPagesPlugin: typeof folderPages;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
definePlugin
|
|
4
|
+
} from "@riebeckite/core";
|
|
5
|
+
|
|
6
|
+
// src/folder_pages.ts
|
|
7
|
+
import { resolveGeneratedFolderLocation } from "@riebeckite/core";
|
|
8
|
+
var ENTRY_BASENAMES = ["README", "index"];
|
|
9
|
+
function collapseFolderEntryLocations(locations) {
|
|
10
|
+
const owners = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const location of locations.values()) {
|
|
12
|
+
if (!owners.has(location.permalink)) {
|
|
13
|
+
owners.set(location.permalink, location.slug);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const byFolder = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const slug of locations.keys()) {
|
|
18
|
+
const basename = lastSegment(slug);
|
|
19
|
+
if (!isEntryBasename(basename)) continue;
|
|
20
|
+
const folder = parentFolder(slug);
|
|
21
|
+
const slugs = byFolder.get(folder);
|
|
22
|
+
if (slugs) slugs.push(slug);
|
|
23
|
+
else byFolder.set(folder, [slug]);
|
|
24
|
+
}
|
|
25
|
+
for (const slugs of byFolder.values()) {
|
|
26
|
+
if (slugs.length !== 1) continue;
|
|
27
|
+
const slug = slugs[0];
|
|
28
|
+
const location = locations.get(slug);
|
|
29
|
+
if (!location) continue;
|
|
30
|
+
const basename = lastSegment(slug);
|
|
31
|
+
if (!location.permalink.endsWith(`/${basename}`)) continue;
|
|
32
|
+
const target = location.permalink.slice(
|
|
33
|
+
0,
|
|
34
|
+
location.permalink.length - basename.length
|
|
35
|
+
);
|
|
36
|
+
if (!target.endsWith("/")) continue;
|
|
37
|
+
const owner = owners.get(target);
|
|
38
|
+
if (owner !== void 0 && owner !== slug) continue;
|
|
39
|
+
const redirects = [
|
|
40
|
+
...location.redirects ?? [],
|
|
41
|
+
{ path: location.permalink, status: 301 }
|
|
42
|
+
];
|
|
43
|
+
locations.set(slug, { ...location, permalink: target, redirects });
|
|
44
|
+
owners.delete(location.permalink);
|
|
45
|
+
owners.set(target, slug);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function buildFolderPages(manifest) {
|
|
49
|
+
const pagesByFolder = /* @__PURE__ */ new Map();
|
|
50
|
+
const subfoldersOf = /* @__PURE__ */ new Map();
|
|
51
|
+
const allFolders = /* @__PURE__ */ new Set();
|
|
52
|
+
const routableBySlug = /* @__PURE__ */ new Map();
|
|
53
|
+
const routablePermalinks = /* @__PURE__ */ new Set();
|
|
54
|
+
for (const entry of manifest.publicEntries) {
|
|
55
|
+
routableBySlug.set(entry.slug, entry);
|
|
56
|
+
routablePermalinks.add(stripTrailingSlash(entry.permalink));
|
|
57
|
+
}
|
|
58
|
+
const addSubfolder = (parent, child) => {
|
|
59
|
+
const subs = subfoldersOf.get(parent);
|
|
60
|
+
if (subs) subs.add(child);
|
|
61
|
+
else subfoldersOf.set(parent, /* @__PURE__ */ new Set([child]));
|
|
62
|
+
allFolders.add(parent);
|
|
63
|
+
allFolders.add(child);
|
|
64
|
+
};
|
|
65
|
+
for (const entry of manifest.discoverableEntries) {
|
|
66
|
+
const slug = entry.slug;
|
|
67
|
+
const basename = lastSegment(slug);
|
|
68
|
+
const parent = parentFolder(slug);
|
|
69
|
+
allFolders.add(parent);
|
|
70
|
+
if (!isEntryBasename(basename)) {
|
|
71
|
+
const pages2 = pagesByFolder.get(parent);
|
|
72
|
+
if (pages2) pages2.push(entry);
|
|
73
|
+
else pagesByFolder.set(parent, [entry]);
|
|
74
|
+
}
|
|
75
|
+
let child = parent;
|
|
76
|
+
while (child !== "") {
|
|
77
|
+
const grandparent = parentFolder(child);
|
|
78
|
+
addSubfolder(grandparent, child);
|
|
79
|
+
child = grandparent;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const hasRoutableOwner = (folder) => routableBySlug.has(`${folder}/README`) || routableBySlug.has(`${folder}/index`);
|
|
83
|
+
const hasRoutablePage = (folder) => routableBySlug.has(folder);
|
|
84
|
+
const sortedPages = (folder) => {
|
|
85
|
+
const subfolders = subfoldersOf.get(folder);
|
|
86
|
+
const pages2 = (pagesByFolder.get(folder) ?? []).filter(
|
|
87
|
+
(entry) => !subfolders?.has(entry.slug)
|
|
88
|
+
);
|
|
89
|
+
pages2.sort(compareEntries);
|
|
90
|
+
return pages2;
|
|
91
|
+
};
|
|
92
|
+
const navigableCache = /* @__PURE__ */ new Map();
|
|
93
|
+
const isNavigable = (folder) => {
|
|
94
|
+
const cached = navigableCache.get(folder);
|
|
95
|
+
if (cached !== void 0) return cached;
|
|
96
|
+
navigableCache.set(folder, false);
|
|
97
|
+
let result = sortedPages(folder).length > 0 || hasRoutableOwner(folder) || hasRoutablePage(folder);
|
|
98
|
+
if (!result) {
|
|
99
|
+
for (const sub of subfoldersOf.get(folder) ?? []) {
|
|
100
|
+
if (isListed(sub)) {
|
|
101
|
+
result = true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
navigableCache.set(folder, result);
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
const isListed = (folder) => hasRoutableOwner(folder) || hasRoutablePage(folder) || isNavigable(folder) && generatedPath(folder) !== null;
|
|
110
|
+
const generatedPath = (folder) => resolveGeneratedFolderLocation(manifest, folder);
|
|
111
|
+
const folderLink = (folder) => {
|
|
112
|
+
if (hasRoutableOwner(folder)) {
|
|
113
|
+
const owner = routableBySlug.get(`${folder}/README`) ?? routableBySlug.get(`${folder}/index`);
|
|
114
|
+
if (owner) return { title: owner.title, permalink: owner.permalink };
|
|
115
|
+
}
|
|
116
|
+
const page = routableBySlug.get(folder);
|
|
117
|
+
if (page) return { title: page.title, permalink: page.permalink };
|
|
118
|
+
const pathname = generatedPath(folder);
|
|
119
|
+
if (!pathname) return null;
|
|
120
|
+
return { title: lastSegment(folder), permalink: pathname };
|
|
121
|
+
};
|
|
122
|
+
const sortedSubfolders = (folder) => {
|
|
123
|
+
const subs = [...subfoldersOf.get(folder) ?? []].flatMap((sub) => {
|
|
124
|
+
if (!isListed(sub)) return [];
|
|
125
|
+
const link = folderLink(sub);
|
|
126
|
+
return link ? [{ folder: sub, link }] : [];
|
|
127
|
+
});
|
|
128
|
+
subs.sort((a, b) => compareLinks(a.link, b.link));
|
|
129
|
+
return subs;
|
|
130
|
+
};
|
|
131
|
+
const folders = [...allFolders].filter((folder) => folder !== "");
|
|
132
|
+
folders.sort(compareStrings);
|
|
133
|
+
const pages = [];
|
|
134
|
+
const takenPaths = /* @__PURE__ */ new Set();
|
|
135
|
+
for (const folder of folders) {
|
|
136
|
+
if (!isNavigable(folder)) continue;
|
|
137
|
+
if (hasRoutableOwner(folder)) continue;
|
|
138
|
+
if (hasRoutablePage(folder)) continue;
|
|
139
|
+
const pathname = generatedPath(folder);
|
|
140
|
+
if (!pathname) continue;
|
|
141
|
+
if (pathname === "/") continue;
|
|
142
|
+
if (routablePermalinks.has(stripTrailingSlash(pathname))) continue;
|
|
143
|
+
if (takenPaths.has(pathname)) continue;
|
|
144
|
+
takenPaths.add(pathname);
|
|
145
|
+
const folders_ = sortedSubfolders(folder);
|
|
146
|
+
pages.push({
|
|
147
|
+
folder,
|
|
148
|
+
pathname,
|
|
149
|
+
title: lastSegment(folder),
|
|
150
|
+
pages: sortedPages(folder).map(toLink),
|
|
151
|
+
folders: folders_.map((sub) => sub.link),
|
|
152
|
+
dependencies: [
|
|
153
|
+
{ type: "folder", folder },
|
|
154
|
+
...folders_.map((sub) => ({
|
|
155
|
+
type: "folder",
|
|
156
|
+
folder: sub.folder
|
|
157
|
+
}))
|
|
158
|
+
]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
pages.sort((a, b) => compareStrings(a.pathname, b.pathname));
|
|
162
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
163
|
+
for (const page of pages) byPath.set(page.pathname, page);
|
|
164
|
+
return { paths: pages.map((page) => page.pathname), byPath };
|
|
165
|
+
}
|
|
166
|
+
function isEntryBasename(basename) {
|
|
167
|
+
return ENTRY_BASENAMES.includes(basename);
|
|
168
|
+
}
|
|
169
|
+
function toLink(entry) {
|
|
170
|
+
return { title: entry.title, permalink: entry.permalink };
|
|
171
|
+
}
|
|
172
|
+
function lastSegment(path) {
|
|
173
|
+
const index = path.lastIndexOf("/");
|
|
174
|
+
return index === -1 ? path : path.slice(index + 1);
|
|
175
|
+
}
|
|
176
|
+
function parentFolder(path) {
|
|
177
|
+
const index = path.lastIndexOf("/");
|
|
178
|
+
return index === -1 ? "" : path.slice(0, index);
|
|
179
|
+
}
|
|
180
|
+
function stripTrailingSlash(url) {
|
|
181
|
+
if (url.length > 1 && url.endsWith("/")) return url.slice(0, -1);
|
|
182
|
+
return url;
|
|
183
|
+
}
|
|
184
|
+
function compareEntries(a, b) {
|
|
185
|
+
return compareStrings(a.permalink, b.permalink) || compareStrings(a.title, b.title) || compareStrings(a.slug, b.slug);
|
|
186
|
+
}
|
|
187
|
+
function compareLinks(a, b) {
|
|
188
|
+
return compareStrings(a.permalink, b.permalink) || compareStrings(a.title, b.title);
|
|
189
|
+
}
|
|
190
|
+
function compareStrings(a, b) {
|
|
191
|
+
if (a < b) return -1;
|
|
192
|
+
if (a > b) return 1;
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/options.ts
|
|
197
|
+
var DEFAULT_FOLDER_PAGES_CLASS_NAME = "rr-folder-page";
|
|
198
|
+
var DEFAULT_FOLDER_PAGES_PAGES_LABEL = "Pages";
|
|
199
|
+
var DEFAULT_FOLDER_PAGES_FOLDERS_LABEL = "Folders";
|
|
200
|
+
function resolveFolderPagesOptions(options = {}) {
|
|
201
|
+
return {
|
|
202
|
+
className: normalizeString(
|
|
203
|
+
options.className,
|
|
204
|
+
DEFAULT_FOLDER_PAGES_CLASS_NAME
|
|
205
|
+
),
|
|
206
|
+
pagesLabel: normalizeString(
|
|
207
|
+
options.pagesLabel,
|
|
208
|
+
DEFAULT_FOLDER_PAGES_PAGES_LABEL
|
|
209
|
+
),
|
|
210
|
+
foldersLabel: normalizeString(
|
|
211
|
+
options.foldersLabel,
|
|
212
|
+
DEFAULT_FOLDER_PAGES_FOLDERS_LABEL
|
|
213
|
+
)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function normalizeString(value, fallback) {
|
|
217
|
+
if (typeof value !== "string") return fallback;
|
|
218
|
+
const trimmed = value.trim();
|
|
219
|
+
return trimmed === "" ? fallback : trimmed;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/pages.ts
|
|
223
|
+
import { escapeHtml, escapeHtmlAttribute } from "@riebeckite/core";
|
|
224
|
+
function renderFolderPage(page, options) {
|
|
225
|
+
const className = escapeHtmlAttribute(options.className);
|
|
226
|
+
const parts = [
|
|
227
|
+
`<section class="${className}" data-rr-folder-page="${escapeHtmlAttribute(page.folder)}">`,
|
|
228
|
+
`<h1 class="${className}__title">${escapeHtml(page.title)}</h1>`
|
|
229
|
+
];
|
|
230
|
+
if (page.pages.length > 0) {
|
|
231
|
+
parts.push(
|
|
232
|
+
`<h2 class="${className}__heading">${escapeHtml(options.pagesLabel)}</h2>`,
|
|
233
|
+
`<ul class="${className}__pages">`
|
|
234
|
+
);
|
|
235
|
+
for (const link of page.pages) parts.push(renderLink(className, link));
|
|
236
|
+
parts.push("</ul>");
|
|
237
|
+
}
|
|
238
|
+
if (page.folders.length > 0) {
|
|
239
|
+
parts.push(
|
|
240
|
+
`<h2 class="${className}__heading">${escapeHtml(options.foldersLabel)}</h2>`,
|
|
241
|
+
`<ul class="${className}__folders">`
|
|
242
|
+
);
|
|
243
|
+
for (const link of page.folders) parts.push(renderLink(className, link));
|
|
244
|
+
parts.push("</ul>");
|
|
245
|
+
}
|
|
246
|
+
parts.push("</section>");
|
|
247
|
+
return { title: page.title, html: parts.join("") };
|
|
248
|
+
}
|
|
249
|
+
function renderLink(className, link) {
|
|
250
|
+
return `<li class="${className}__item"><a class="${className}__link" href="${escapeHtmlAttribute(link.permalink)}">${escapeHtml(link.title)}</a></li>`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// index.ts
|
|
254
|
+
var FOLDER_PAGES_PLUGIN_NAME = "folder-pages";
|
|
255
|
+
function folderPages(options = {}) {
|
|
256
|
+
const resolved = resolveFolderPagesOptions(options);
|
|
257
|
+
const models = /* @__PURE__ */ new WeakMap();
|
|
258
|
+
const modelFor = (manifest) => {
|
|
259
|
+
const cached = models.get(manifest);
|
|
260
|
+
if (cached) return cached;
|
|
261
|
+
const model = buildFolderPages(manifest);
|
|
262
|
+
models.set(manifest, model);
|
|
263
|
+
return model;
|
|
264
|
+
};
|
|
265
|
+
return definePlugin({
|
|
266
|
+
name: FOLDER_PAGES_PLUGIN_NAME,
|
|
267
|
+
provides: ["content.folder-pages"],
|
|
268
|
+
options,
|
|
269
|
+
optional: ["content.localization"],
|
|
270
|
+
validateOptions: validateFolderPagesOptions,
|
|
271
|
+
extendContentLocations: ({ locations }) => {
|
|
272
|
+
collapseFolderEntryLocations(locations);
|
|
273
|
+
},
|
|
274
|
+
onManifestCreated: ({ manifest }) => {
|
|
275
|
+
for (const page of modelFor(manifest).byPath.values()) {
|
|
276
|
+
manifest.folderLocations.set(page.folder, { pathname: page.pathname });
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
pageTypes: [
|
|
280
|
+
{
|
|
281
|
+
id: "folder-page",
|
|
282
|
+
directoryIndex: true,
|
|
283
|
+
paths: ({ manifest }) => modelFor(manifest).paths,
|
|
284
|
+
outputDependencies: ({ manifest, pathname }) => modelFor(manifest).byPath.get(pathname)?.dependencies ?? [
|
|
285
|
+
{ type: "unknown" }
|
|
286
|
+
],
|
|
287
|
+
resolve: ({ manifest, pathname }) => {
|
|
288
|
+
const page = modelFor(manifest).byPath.get(pathname);
|
|
289
|
+
if (!page) return null;
|
|
290
|
+
const rendered = renderFolderPage(page, resolved);
|
|
291
|
+
return {
|
|
292
|
+
type: "folder-page",
|
|
293
|
+
pathname: page.pathname,
|
|
294
|
+
title: rendered.title,
|
|
295
|
+
body: rendered.html
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
var folderPagesPlugin = folderPages;
|
|
303
|
+
function validateFolderPagesOptions(options) {
|
|
304
|
+
if (!options) return [];
|
|
305
|
+
const issues = [];
|
|
306
|
+
for (const key of ["className", "pagesLabel", "foldersLabel"]) {
|
|
307
|
+
const value = options[key];
|
|
308
|
+
if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
|
|
309
|
+
issues.push({ path: key, message: "Expected a non-empty string." });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return issues;
|
|
313
|
+
}
|
|
314
|
+
export {
|
|
315
|
+
DEFAULT_FOLDER_PAGES_CLASS_NAME,
|
|
316
|
+
DEFAULT_FOLDER_PAGES_FOLDERS_LABEL,
|
|
317
|
+
DEFAULT_FOLDER_PAGES_PAGES_LABEL,
|
|
318
|
+
FOLDER_PAGES_PLUGIN_NAME,
|
|
319
|
+
buildFolderPages,
|
|
320
|
+
collapseFolderEntryLocations,
|
|
321
|
+
folderPages,
|
|
322
|
+
folderPagesPlugin,
|
|
323
|
+
renderFolderPage,
|
|
324
|
+
resolveFolderPagesOptions
|
|
325
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ContentManifest, ContentPublicLocation } from "@riebeckite/core";
|
|
2
|
+
import type { FolderPagesModel } from "./types.js";
|
|
3
|
+
export declare function collapseFolderEntryLocations(locations: Map<string, ContentPublicLocation>): void;
|
|
4
|
+
export declare function buildFolderPages(manifest: ContentManifest): FolderPagesModel;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FolderPagesOptions, ResolvedFolderPagesOptions } from "./types.js";
|
|
2
|
+
export declare const DEFAULT_FOLDER_PAGES_CLASS_NAME = "rr-folder-page";
|
|
3
|
+
export declare const DEFAULT_FOLDER_PAGES_PAGES_LABEL = "Pages";
|
|
4
|
+
export declare const DEFAULT_FOLDER_PAGES_FOLDERS_LABEL = "Folders";
|
|
5
|
+
export declare function resolveFolderPagesOptions(options?: FolderPagesOptions): ResolvedFolderPagesOptions;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { OutputDependency } from "@riebeckite/core";
|
|
2
|
+
export type FolderPagesOptions = {
|
|
3
|
+
className?: string;
|
|
4
|
+
pagesLabel?: string;
|
|
5
|
+
foldersLabel?: string;
|
|
6
|
+
};
|
|
7
|
+
export type ResolvedFolderPagesOptions = {
|
|
8
|
+
className: string;
|
|
9
|
+
pagesLabel: string;
|
|
10
|
+
foldersLabel: string;
|
|
11
|
+
};
|
|
12
|
+
export type FolderPageLink = {
|
|
13
|
+
title: string;
|
|
14
|
+
permalink: string;
|
|
15
|
+
};
|
|
16
|
+
export type FolderPage = {
|
|
17
|
+
folder: string;
|
|
18
|
+
pathname: string;
|
|
19
|
+
title: string;
|
|
20
|
+
pages: FolderPageLink[];
|
|
21
|
+
folders: FolderPageLink[];
|
|
22
|
+
dependencies: OutputDependency[];
|
|
23
|
+
};
|
|
24
|
+
export type FolderPagesModel = {
|
|
25
|
+
paths: string[];
|
|
26
|
+
byPath: Map<string, FolderPage>;
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-folder-pages",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.16",
|
|
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
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@riebeckite/core": "0.0.16"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsx": "^4.22.4",
|
|
21
|
+
"@riebeckite/plugin-l10n": "0.0.16",
|
|
22
|
+
"@riebeckite/plugin-taxonomy": "0.0.16"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"README.md",
|
|
30
|
+
"README_ja.md",
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
36
|
+
"directory": "packages/plugins/folder-pages"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
41
|
+
},
|
|
42
|
+
"description": "Folder entry pages and generated folder listings for Riebeckite.",
|
|
43
|
+
"keywords": [
|
|
44
|
+
"riebeckite",
|
|
45
|
+
"plugin",
|
|
46
|
+
"folder",
|
|
47
|
+
"navigation"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
51
|
+
},
|
|
52
|
+
"sideEffects": false,
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "node ../../../scripts/build_package.mjs",
|
|
55
|
+
"test": "node --import tsx --test \"test/*.test.ts\""
|
|
56
|
+
}
|
|
6
57
|
}
|