@riebeckite/plugin-folder-pages 0.0.45 → 0.0.48

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/README.md CHANGED
@@ -28,6 +28,12 @@ export default {
28
28
  };
29
29
  ```
30
30
 
31
+ Show dates and tags in generated listings:
32
+
33
+ ```ts
34
+ folderPages({ showDate: true, showTags: true });
35
+ ```
36
+
31
37
  ## Markdown-backed Folder Pages
32
38
 
33
39
  A note at `<folder>/README.md` or `<folder>/index.md` becomes the folder's
@@ -67,9 +73,22 @@ output is deterministic regardless of plugin order.
67
73
 
68
74
  | Option | Type | Default | Description |
69
75
  | --- | --- | --- | --- |
76
+ | `exclude` | `string[]` | `[]` | Omit matching slug paths and their descendants from generated listings. |
70
77
  | `className` | `string` | `"rr-folder-page"` | Root CSS class for the rendered fragment. |
71
78
  | `pagesLabel` | `string` | `"Pages"` | Heading for the page list. |
72
79
  | `foldersLabel` | `string` | `"Folders"` | Heading for the folder list. |
80
+ | `showDate` | `boolean` | `false` | Show each listed note's `published`, `date`, or `created` property on the right. |
81
+ | `showTags` | `boolean` | `false` | Show each listed note's `tags` property on the right. |
82
+ | `layout` | `"article" \| "wide"` | `"article"` | Width of generated pages. `"article"` uses the theme article width; `"wide"` uses the page width. |
83
+
84
+ `exclude` uses logical content slugs, not display labels or glob patterns. For
85
+ example, `exclude: ["Config"]` omits `Config` and `Config/internal` while
86
+ leaving their published URLs unchanged.
87
+
88
+ Generated Folder Pages use the theme's article width by default. Set
89
+ `layout: "wide"` to use the page width. When either metadata option is enabled,
90
+ the note title stays on the left and its date and/or tags are placed on the
91
+ right of the listing row.
73
92
 
74
93
  ## Plugin dependencies
75
94
 
package/README_ja.md CHANGED
@@ -28,6 +28,12 @@ export default {
28
28
  };
29
29
  ```
30
30
 
31
+ 自動生成一覧に日付とタグを表示する場合は、次のように設定します。
32
+
33
+ ```ts
34
+ folderPages({ showDate: true, showTags: true });
35
+ ```
36
+
31
37
  ## Markdown ベースの Folder Page
32
38
 
33
39
  `<folder>/README.md` または `<folder>/index.md` にあるノートは、そのフォルダの
@@ -67,9 +73,20 @@ Pages と Folders は解決済みパーマリンク、次にタイトルで並
67
73
 
68
74
  | オプション | 型 | 既定値 | 説明 |
69
75
  | --- | --- | --- | --- |
76
+ | `exclude` | `string[]` | `[]` | 一致する slug パスと子孫を自動生成一覧から除外する。 |
70
77
  | `className` | `string` | `"rr-folder-page"` | 生成するフラグメントのルート CSS クラス。 |
71
78
  | `pagesLabel` | `string` | `"Pages"` | ページ一覧の見出し。 |
72
79
  | `foldersLabel` | `string` | `"Folders"` | フォルダ一覧の見出し。 |
80
+ | `showDate` | `boolean` | `false` | 各ノートの `published`・`date`・`created` プロパティを右側に表示する。 |
81
+ | `showTags` | `boolean` | `false` | 各ノートの `tags` プロパティを右側に表示する。 |
82
+ | `layout` | `"article" \| "wide"` | `"article"` | 生成ページの幅。`"article"` はテーマの記事幅、`"wide"` はページ幅を使います。 |
83
+
84
+ `exclude` は表示ラベルや glob ではなく論理コンテンツ slug を使います。たとえば
85
+ `exclude: ["Config"]` は `Config` と `Config/internal` を除外しますが、公開 URL はそのままです。
86
+
87
+ 自動生成される Folder Page は既定でテーマの article 幅で表示します。`layout: "wide"` を
88
+ 設定するとページ幅を使います。メタデータ表示を有効にすると、一覧行の左側にノートのタイトル、
89
+ 右側に日付・タグを表示します。
73
90
 
74
91
  ## プラグイン依存
75
92
 
package/dist/index.js CHANGED
@@ -1,10 +1,15 @@
1
1
  // index.ts
2
2
  import {
3
+ createStyleAsset,
3
4
  definePlugin
4
5
  } from "@riebeckite/core";
5
6
 
6
7
  // src/folder_pages.ts
7
- import { escapeRegExp, resolveGeneratedFolderLocation } from "@riebeckite/core";
8
+ import {
9
+ escapeRegExp,
10
+ resolveEntryCalendarDate,
11
+ resolveGeneratedFolderLocation
12
+ } from "@riebeckite/core";
8
13
  var ENTRY_BASENAMES = ["README", "index"];
9
14
  function collapseFolderEntryLocations(locations) {
10
15
  const owners = /* @__PURE__ */ new Map();
@@ -46,11 +51,12 @@ function collapseFolderEntryLocations(locations) {
46
51
  owners.set(target, slug);
47
52
  }
48
53
  }
49
- function buildFolderPages(manifest) {
54
+ function buildFolderPages(manifest, excludedSlugs = []) {
50
55
  const folderIcons = manifest.icons?.folders ?? {};
51
56
  const routableBySlug = /* @__PURE__ */ new Map();
52
57
  const routablePermalinks = /* @__PURE__ */ new Set();
53
58
  for (const entry of manifest.publicEntries) {
59
+ if (isExcludedEntry(entry, excludedSlugs)) continue;
54
60
  routableBySlug.set(entry.slug, entry);
55
61
  routablePermalinks.add(stripTrailingSlash(entry.permalink));
56
62
  }
@@ -84,6 +90,7 @@ function buildFolderPages(manifest) {
84
90
  else byLanguage.set(language, /* @__PURE__ */ new Set([child]));
85
91
  };
86
92
  for (const entry of manifest.discoverableEntries) {
93
+ if (isExcludedEntry(entry, excludedSlugs)) continue;
87
94
  const language = entry.publicLocation.language;
88
95
  const folder = parentFolder(entry.slug);
89
96
  allFolders.add(folder);
@@ -99,6 +106,7 @@ function buildFolderPages(manifest) {
99
106
  }
100
107
  const owners = /* @__PURE__ */ new Map();
101
108
  for (const entry of manifest.publicEntries) {
109
+ if (isExcludedEntry(entry, excludedSlugs)) continue;
102
110
  const language = entry.publicLocation.language;
103
111
  const basename = entryBaseSegment(entry.slug, language);
104
112
  if (!isEntryBasename(basename)) continue;
@@ -204,6 +212,12 @@ function buildFolderPages(manifest) {
204
212
  function languageKey(folder, language) {
205
213
  return `${folder}\0${language ?? ""}`;
206
214
  }
215
+ function isExcludedEntry(entry, excludedSlugs) {
216
+ const slug = entry.slug;
217
+ return excludedSlugs.some(
218
+ (excluded) => slug === excluded || slug.startsWith(`${excluded}/`)
219
+ );
220
+ }
207
221
  function entryBaseSegment(slug, language) {
208
222
  const segment = lastSegment(slug);
209
223
  if (!language) return segment;
@@ -226,10 +240,14 @@ function isEntryBasename(basename) {
226
240
  }
227
241
  function toLink(entry, fallbackIcon) {
228
242
  const icon = entry.icon ?? fallbackIcon;
243
+ const date = resolveEntryCalendarDate(entry.frontmatter);
244
+ const tags = entry.tags;
229
245
  return {
230
246
  title: entry.title,
231
247
  permalink: entry.permalink,
232
- ...icon ? { icon } : {}
248
+ ...icon ? { icon } : {},
249
+ ...date ? { date } : {},
250
+ ...tags.length > 0 ? { tags } : {}
233
251
  };
234
252
  }
235
253
  function lastSegment(path) {
@@ -262,6 +280,8 @@ var DEFAULT_FOLDER_PAGES_PAGES_LABEL = "Pages";
262
280
  var DEFAULT_FOLDER_PAGES_FOLDERS_LABEL = "Folders";
263
281
  function resolveFolderPagesOptions(options = {}) {
264
282
  return {
283
+ layout: options.layout === "wide" ? "wide" : "article",
284
+ exclude: options.exclude ?? [],
265
285
  className: normalizeString(
266
286
  options.className,
267
287
  DEFAULT_FOLDER_PAGES_CLASS_NAME
@@ -273,7 +293,9 @@ function resolveFolderPagesOptions(options = {}) {
273
293
  foldersLabel: normalizeString(
274
294
  options.foldersLabel,
275
295
  DEFAULT_FOLDER_PAGES_FOLDERS_LABEL
276
- )
296
+ ),
297
+ showDate: options.showDate ?? false,
298
+ showTags: options.showTags ?? false
277
299
  };
278
300
  }
279
301
  function normalizeString(value, fallback) {
@@ -295,7 +317,8 @@ function renderFolderPage(page, options) {
295
317
  `<h2 class="${className}__heading">${escapeHtml(options.pagesLabel)}</h2>`,
296
318
  `<ul class="${className}__pages">`
297
319
  );
298
- for (const link of page.pages) parts.push(renderLink(className, link));
320
+ for (const link of page.pages)
321
+ parts.push(renderLink(className, link, options));
299
322
  parts.push("</ul>");
300
323
  }
301
324
  if (page.folders.length > 0) {
@@ -303,14 +326,29 @@ function renderFolderPage(page, options) {
303
326
  `<h2 class="${className}__heading">${escapeHtml(options.foldersLabel)}</h2>`,
304
327
  `<ul class="${className}__folders">`
305
328
  );
306
- for (const link of page.folders) parts.push(renderLink(className, link));
329
+ for (const link of page.folders)
330
+ parts.push(renderLink(className, link, options));
307
331
  parts.push("</ul>");
308
332
  }
309
333
  parts.push("</section>");
310
334
  return { title: page.title, html: parts.join("") };
311
335
  }
312
- function renderLink(className, link) {
313
- return `<li class="${className}__item"><a class="${className}__link" href="${escapeHtmlAttribute(link.permalink)}">${renderIcon(link.icon)}${escapeHtml(link.title)}</a></li>`;
336
+ function renderLink(className, link, options) {
337
+ return `<li class="${className}__item"><a class="${className}__link" href="${escapeHtmlAttribute(link.permalink)}"><span class="${className}__link-title">${renderIcon(link.icon)}${escapeHtml(link.title)}</span>${renderMetadata(className, link, options)}</a></li>`;
338
+ }
339
+ function renderMetadata(className, link, options) {
340
+ const parts = [];
341
+ if (options.showDate && link.date) {
342
+ parts.push(
343
+ `<time class="${className}__date" datetime="${escapeHtmlAttribute(link.date)}">${escapeHtml(link.date)}</time>`
344
+ );
345
+ }
346
+ if (options.showTags && link.tags && link.tags.length > 0) {
347
+ parts.push(
348
+ `<span class="${className}__tags">${link.tags.map((tag) => `<span class="${className}__tag">#${escapeHtml(tag)}</span>`).join("")}</span>`
349
+ );
350
+ }
351
+ return parts.length > 0 ? `<span class="${className}__meta">${parts.join("")}</span>` : "";
314
352
  }
315
353
  function renderIcon(icon) {
316
354
  return icon ? `<span class="rr-folder-page__icon">${icon.html}</span>` : "";
@@ -324,7 +362,7 @@ function folderPages(options = {}) {
324
362
  const modelFor = (manifest) => {
325
363
  const cached = models.get(manifest);
326
364
  if (cached) return cached;
327
- const model = buildFolderPages(manifest);
365
+ const model = buildFolderPages(manifest, resolved.exclude);
328
366
  models.set(manifest, model);
329
367
  return model;
330
368
  };
@@ -333,6 +371,12 @@ function folderPages(options = {}) {
333
371
  provides: ["content.folder-pages"],
334
372
  options,
335
373
  optional: ["content.localization"],
374
+ assets: [
375
+ createStyleAsset(
376
+ FOLDER_PAGES_PLUGIN_NAME,
377
+ "@riebeckite/plugin-folder-pages/style.css"
378
+ )
379
+ ],
336
380
  validateOptions: validateFolderPagesOptions,
337
381
  extendContentLocations: ({ locations }) => {
338
382
  collapseFolderEntryLocations(locations);
@@ -367,6 +411,7 @@ function folderPages(options = {}) {
367
411
  const rendered = renderFolderPage(page, resolved);
368
412
  return {
369
413
  type: "folder-page",
414
+ layout: resolved.layout,
370
415
  pathname: page.pathname,
371
416
  title: rendered.title,
372
417
  body: rendered.html,
@@ -379,6 +424,7 @@ function folderPages(options = {}) {
379
424
  const rendered = renderFolderPage(page, resolved);
380
425
  return {
381
426
  type: "folder-page",
427
+ layout: resolved.layout,
382
428
  pathname: page.pathname,
383
429
  title: rendered.title,
384
430
  body: rendered.html,
@@ -392,12 +438,34 @@ function folderPages(options = {}) {
392
438
  function validateFolderPagesOptions(options) {
393
439
  if (!options) return [];
394
440
  const issues = [];
441
+ if (options.layout !== void 0 && options.layout !== "article" && options.layout !== "wide") {
442
+ issues.push({ path: "layout", message: 'Expected "article" or "wide".' });
443
+ }
395
444
  for (const key of ["className", "pagesLabel", "foldersLabel"]) {
396
445
  const value = options[key];
397
446
  if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
398
447
  issues.push({ path: key, message: "Expected a non-empty string." });
399
448
  }
400
449
  }
450
+ for (const key of ["showDate", "showTags"]) {
451
+ if (options[key] !== void 0 && typeof options[key] !== "boolean") {
452
+ issues.push({ path: key, message: "Expected a boolean." });
453
+ }
454
+ }
455
+ if (!Array.isArray(options.exclude)) {
456
+ if (options.exclude !== void 0) {
457
+ issues.push({ path: "exclude", message: "Expected an array." });
458
+ }
459
+ } else {
460
+ options.exclude.forEach((slug, index) => {
461
+ if (typeof slug !== "string" || slug.trim() === "") {
462
+ issues.push({
463
+ path: `exclude[${index}]`,
464
+ message: "Expected a non-empty string."
465
+ });
466
+ }
467
+ });
468
+ }
401
469
  return issues;
402
470
  }
403
471
  export {
@@ -1,4 +1,4 @@
1
1
  import type { ContentManifest, ContentPublicLocation } from "@riebeckite/core";
2
2
  import type { FolderPagesModel } from "./types.js";
3
3
  export declare function collapseFolderEntryLocations(locations: Map<string, ContentPublicLocation>): void;
4
- export declare function buildFolderPages(manifest: ContentManifest): FolderPagesModel;
4
+ export declare function buildFolderPages(manifest: ContentManifest, excludedSlugs?: readonly string[]): FolderPagesModel;
@@ -1,18 +1,28 @@
1
1
  import type { ContentIcon, OutputDependency } from "@riebeckite/core";
2
2
  export type FolderPagesOptions = {
3
+ layout?: "article" | "wide";
4
+ exclude?: readonly string[];
3
5
  className?: string;
4
6
  pagesLabel?: string;
5
7
  foldersLabel?: string;
8
+ showDate?: boolean;
9
+ showTags?: boolean;
6
10
  };
7
11
  export type ResolvedFolderPagesOptions = {
12
+ layout: "article" | "wide";
13
+ exclude: readonly string[];
8
14
  className: string;
9
15
  pagesLabel: string;
10
16
  foldersLabel: string;
17
+ showDate: boolean;
18
+ showTags: boolean;
11
19
  };
12
20
  export type FolderPageLink = {
13
21
  title: string;
14
22
  permalink: string;
15
23
  icon?: ContentIcon;
24
+ date?: string;
25
+ tags?: string[];
16
26
  };
17
27
  export type FolderPage = {
18
28
  folder: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-folder-pages",
3
- "version": "0.0.45",
3
+ "version": "0.0.48",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,15 +11,16 @@
11
11
  "import": "./dist/index.js",
12
12
  "source": "./index.ts",
13
13
  "default": "./dist/index.js"
14
- }
14
+ },
15
+ "./style.css": "./style.css"
15
16
  },
16
17
  "dependencies": {
17
- "@riebeckite/core": "0.0.45"
18
+ "@riebeckite/core": "0.0.48"
18
19
  },
19
20
  "devDependencies": {
20
21
  "tsx": "^4.22.4",
21
- "@riebeckite/plugin-taxonomy": "0.0.45",
22
- "@riebeckite/plugin-l10n": "0.0.45"
22
+ "@riebeckite/plugin-taxonomy": "0.0.48",
23
+ "@riebeckite/plugin-l10n": "0.0.48"
23
24
  },
24
25
  "publishConfig": {
25
26
  "access": "public"
@@ -28,7 +29,8 @@
28
29
  "LICENSE",
29
30
  "README.md",
30
31
  "README_ja.md",
31
- "dist"
32
+ "dist",
33
+ "style.css"
32
34
  ],
33
35
  "repository": {
34
36
  "type": "git",
@@ -49,7 +51,9 @@
49
51
  "engines": {
50
52
  "node": "^20.19.0 || >=22.12.0"
51
53
  },
52
- "sideEffects": false,
54
+ "sideEffects": [
55
+ "./style.css"
56
+ ],
53
57
  "scripts": {
54
58
  "build": "node ../../../scripts/build_package.mjs",
55
59
  "test": "node --import tsx --test \"test/*.test.ts\""
package/style.css ADDED
@@ -0,0 +1,78 @@
1
+ @layer components {
2
+ .rr-folder-page {
3
+ padding-block: 2rem;
4
+ }
5
+
6
+ .rr-folder-page__title {
7
+ margin-block: 0 2rem;
8
+ }
9
+
10
+ .rr-folder-page__heading {
11
+ margin-block: 2rem 0.75rem;
12
+ }
13
+
14
+ .rr-folder-page__pages,
15
+ .rr-folder-page__folders {
16
+ margin: 0;
17
+ padding: 0;
18
+ list-style: none;
19
+ }
20
+
21
+ .rr-folder-page__item {
22
+ border-block-end: 1px solid
23
+ color-mix(in srgb, currentColor 14%, transparent);
24
+ }
25
+
26
+ .rr-folder-page__link {
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: space-between;
30
+ gap: 1rem;
31
+ padding-block: 0.875rem;
32
+ color: inherit;
33
+ text-decoration: none;
34
+ }
35
+
36
+ .rr-folder-page__link:hover,
37
+ .rr-folder-page__link:focus-visible {
38
+ color: var(--rb-color-accent);
39
+ }
40
+
41
+ .rr-folder-page__link:focus-visible {
42
+ outline: 2px solid var(--rb-color-accent);
43
+ outline-offset: 4px;
44
+ }
45
+
46
+ .rr-folder-page__link-title,
47
+ .rr-folder-page__meta,
48
+ .rr-folder-page__tags {
49
+ display: flex;
50
+ align-items: center;
51
+ gap: 0.5rem;
52
+ }
53
+
54
+ .rr-folder-page__meta {
55
+ flex: 0 0 auto;
56
+ color: var(
57
+ --rb-color-muted,
58
+ color-mix(in srgb, currentColor 62%, transparent)
59
+ );
60
+ font-size: 0.8125rem;
61
+ }
62
+
63
+ .rr-folder-page__tags {
64
+ flex-wrap: wrap;
65
+ justify-content: end;
66
+ }
67
+
68
+ @media (max-width: 40rem) {
69
+ .rr-folder-page__link {
70
+ align-items: flex-start;
71
+ }
72
+
73
+ .rr-folder-page__meta {
74
+ flex-direction: column;
75
+ align-items: end;
76
+ }
77
+ }
78
+ }