@riebeckite/plugin-related-posts 0.0.20 → 0.0.22

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
@@ -1,12 +1,14 @@
1
1
  # @riebeckite/plugin-related-posts
2
2
 
3
+ <!-- Generated from docs/docs/plugins/related-posts.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
4
+
3
5
  Build-time "related notes" navigation. For every published entry, the plugin
4
6
  ranks the other entries in the content manifest and contributes a related-posts
5
7
  section to the `article.footer` Slot. No client-side JavaScript is required.
6
8
 
7
9
  [日本語](./README_ja.md)
8
10
 
9
- ## Overview
11
+ ## Recommended placement
10
12
 
11
13
  `relatedPosts()` reads the manifest's content graph and scores every other
12
14
  published entry against the current one:
@@ -25,7 +27,7 @@ The plugin contributes the section to each manifest entry's `article.footer`
25
27
  Slot. The Site decides where to render that Slot, so the section appears on
26
28
  generated pages and in feeds when the standard article footer is used.
27
29
 
28
- ## Usage
30
+ ## Quick Start
29
31
 
30
32
  ```ts
31
33
  import { defineConfig } from "@riebeckite/core";
@@ -37,26 +39,34 @@ export default defineConfig({
37
39
  });
38
40
  ```
39
41
 
40
- ## Component
42
+ ## Advanced customization
41
43
 
42
- In addition to the automatic `article.footer` Slot contribution, the navigation
43
- is available as a server-rendered Hono JSX Component for placement in a Site
44
- layout. Build the entries with the existing helper and pass resolved options:
44
+ The Site can place the public server-rendered component anywhere. Set
45
+ `render: false` first to prevent the automatic `article.footer` contribution;
46
+ ranking and publication filtering remain available through the public helpers.
45
47
 
46
48
  ```tsx
47
- import RelatedPosts from "@riebeckite/plugin-related-posts/components";
49
+ import {
50
+ buildRelatedPosts,
51
+ RelatedPosts,
52
+ resolveRelatedPostsOptions,
53
+ } from "@riebeckite/plugin-related-posts";
54
+
55
+ const options = resolveRelatedPostsOptions({ render: false });
56
+ const entries = buildRelatedPosts({ manifest, entry, options, config });
48
57
 
49
- <RelatedPosts entries={related} options={resolvedOptions} />;
58
+ return <aside><RelatedPosts entries={entries} options={options} /></aside>;
50
59
  ```
51
60
 
52
- `related` is the result of `buildRelatedPosts()` and `resolvedOptions` is the
53
- result of `resolveRelatedPostsOptions()`. Import `style.css` when the Plugin is
54
- not registered.
61
+ The official Starter already renders `article.footer` once. Remove the manual
62
+ component to remove a manual placement. Do not use it alongside automatic
63
+ rendering for the same article.
55
64
 
56
65
  ## Options
57
66
 
58
67
  | Option | Type | Default | Description |
59
68
  | ------ | ---- | ------- | ----------- |
69
+ | `render` | `boolean` | `true` | Append generated navigation to `article.footer`; set `false` for manual placement |
60
70
  | `limit` | `number` | `5` | Maximum number of related entries |
61
71
  | `minScore` | `number` | `1` | Minimum score required to be listed |
62
72
  | `heading` | `boolean` | `true` | Render the `<h2>` heading |
@@ -73,18 +83,9 @@ relatedPosts({
73
83
  });
74
84
  ```
75
85
 
76
- ## Output
77
-
78
- ```html
79
- <nav class="rb-related-posts" data-related-posts>
80
- <h2 class="rb-related-posts__heading">Related</h2>
81
- <ul>
82
- <li class="rb-related-posts__item">
83
- <a class="rb-related-posts__link" href="/notes/example" data-related-score="5">Example Note</a>
84
- </li>
85
- </ul>
86
- </nav>
87
- ```
86
+ ## Display
87
+
88
+ Related entries are rendered in the `article.footer` slot on eligible pages. This site renders the live navigation below the article when matching public entries exist.
88
89
 
89
90
  ## Style
90
91
 
@@ -112,4 +113,4 @@ import "@riebeckite/plugin-related-posts/style.css";
112
113
 
113
114
  ## See also
114
115
 
115
- - [Plugin guide](../../../docs/docs/reference/plugin-api.md)
116
+ - [Plugin guide](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/reference/plugin-api.md)
package/README_ja.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @riebeckite/plugin-related-posts
2
2
 
3
+ <!-- Generated from docs/docs/plugins/related-posts.ja.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
4
+
3
5
  ビルド時に「関連ノート」ナビゲーションを生成するプラグインです。公開対象の
4
6
  各エントリについて、コンテンツマニフェスト上の他のエントリをスコア順に並べ、
5
7
  関連ノートのセクションを `article.footer` Slot に追加します。クライアント側 JavaScript は
@@ -7,7 +9,7 @@
7
9
 
8
10
  [English](./README.md)
9
11
 
10
- ## 仕組み
12
+ ## 推奨配置
11
13
 
12
14
  `relatedPosts()` はマニフェストのコンテンツグラフを読み、現在のエントリと
13
15
  他の公開エントリを次のシグナルで採点します。
@@ -26,7 +28,7 @@
26
28
  記事フッターでこの Slot を描画している場合、生成ページとフィードの両方に
27
29
  セクションが反映されます。
28
30
 
29
- ## 使い方
31
+ ## クイックスタート
30
32
 
31
33
  ```ts
32
34
  import { defineConfig } from "@riebeckite/core";
@@ -38,26 +40,25 @@ export default defineConfig({
38
40
  });
39
41
  ```
40
42
 
41
- ## Component として使う
43
+ ## 高度なカスタマイズ
42
44
 
43
- 自動の `article.footer` Slot への追加に加え、Site のレイアウト内で任意の位置に
44
- 配置できる、サーバー描画の Hono JSX Component も公開しています。既存の helper
45
- で entries を計算し、解決済みの options を渡してください。
45
+ Site のレイアウト内で任意の位置に配置できるサーバー描画の Hono JSX Component を公開しています。`render: false` で自動の `article.footer` Slot 追加を止め、既存の helper で entries を計算して解決済み options を渡してください。採点と公開境界のフィルタリングは維持されます。
46
46
 
47
47
  ```tsx
48
- import RelatedPosts from "@riebeckite/plugin-related-posts/components";
48
+ import { buildRelatedPosts, RelatedPosts, resolveRelatedPostsOptions } from "@riebeckite/plugin-related-posts";
49
49
 
50
- <RelatedPosts entries={related} options={resolvedOptions} />;
50
+ const options = resolveRelatedPostsOptions({ render: false });
51
+ const entries = buildRelatedPosts({ manifest, entry, options, config });
52
+ return <aside><RelatedPosts entries={entries} options={options} /></aside>;
51
53
  ```
52
54
 
53
- `related` には `buildRelatedPosts()` の戻り値を、`resolvedOptions` には
54
- `resolveRelatedPostsOptions()` の戻り値を渡します。Plugin を登録しない場合は
55
- `style.css` も読み込んでください。
55
+ 公式 Starter は `article.footer` を一度描画します。手動配置を消すにはコンポーネントを消します。自動描画を有効にしたまま同じ記事へ手動描画しないでください。
56
56
 
57
57
  ## オプション
58
58
 
59
59
  | オプション | 型 | 既定値 | 説明 |
60
60
  | ---------- | -- | ------ | ---- |
61
+ | `render` | `boolean` | `true` | `article.footer` への自動追加。手動配置では `false` |
61
62
  | `limit` | `number` | `5` | 表示する関連エントリの最大件数 |
62
63
  | `minScore` | `number` | `1` | 表示に必要な最小スコア |
63
64
  | `heading` | `boolean` | `true` | `<h2>` 見出しを出力する |
@@ -74,18 +75,9 @@ relatedPosts({
74
75
  });
75
76
  ```
76
77
 
77
- ## 出力
78
-
79
- ```html
80
- <nav class="rb-related-posts" data-related-posts>
81
- <h2 class="rb-related-posts__heading">Related</h2>
82
- <ul>
83
- <li class="rb-related-posts__item">
84
- <a class="rb-related-posts__link" href="/notes/example" data-related-score="5">Example Note</a>
85
- </li>
86
- </ul>
87
- </nav>
88
- ```
78
+ ## 表示
79
+
80
+ 関連エントリは対象ページの `article.footer` スロットに描画されます。このサイトでは、条件に合う公開エントリがあれば記事下に実際のナビゲーションを表示します。
89
81
 
90
82
  ## スタイル
91
83
 
@@ -113,4 +105,4 @@ import "@riebeckite/plugin-related-posts/style.css";
113
105
 
114
106
  ## 関連リンク
115
107
 
116
- - [プラグイン API](../../../docs/docs/reference/plugin-api.ja.md)
108
+ - [プラグイン API](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/reference/plugin-api.ja.md)
package/dist/index.js CHANGED
@@ -142,6 +142,7 @@ function relatedPosts(options = {}) {
142
142
  options,
143
143
  validateOptions: validateRelatedPostsOptions,
144
144
  onManifestCreated: (context) => {
145
+ if (options.render === false) return;
145
146
  const { manifest } = context;
146
147
  for (const entry of manifest.discoverableEntries) {
147
148
  if (!isEligibleRelatedEntry(entry, manifest, context.config)) continue;
@@ -166,6 +167,9 @@ var relatedPostsPlugin = relatedPosts;
166
167
  function validateRelatedPostsOptions(options) {
167
168
  if (!options) return [];
168
169
  const issues = [];
170
+ if (options.render !== void 0 && typeof options.render !== "boolean") {
171
+ issues.push({ path: "render", message: "Expected a boolean." });
172
+ }
169
173
  if (options.limit !== void 0 && (!Number.isInteger(options.limit) || options.limit < 0)) {
170
174
  issues.push({ path: "limit", message: "Expected a non-negative integer." });
171
175
  }
@@ -1,5 +1,6 @@
1
1
  /** Options accepted by `relatedPosts()`. */
2
2
  export type RelatedPostsOptions = {
3
+ render?: boolean;
3
4
  /** Maximum number of related entries to render. Defaults to `5`. */
4
5
  limit?: number;
5
6
  /** Minimum score a candidate must reach to be listed. Defaults to `1`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-related-posts",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,11 +22,11 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "hono": "^4.12.25",
25
- "@riebeckite/core": "0.0.20"
25
+ "@riebeckite/core": "0.0.22"
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsx": "^4.22.4",
29
- "@riebeckite/test": "0.0.20"
29
+ "@riebeckite/test": "0.0.22"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
package/style.css CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  .rb-related-posts ul {
24
24
  display: grid;
25
- gap: 0.5rem;
25
+ gap: 0;
26
26
  margin: 0;
27
27
  padding: 0;
28
28
  list-style: none;
@@ -30,7 +30,8 @@
30
30
 
31
31
  .rb-related-posts__item {
32
32
  margin: 0;
33
- padding: 0;
33
+ padding: 0.75rem 0;
34
+ border-bottom: 1px solid var(--rb-related-posts-rule);
34
35
  }
35
36
 
36
37
  .rb-related-posts__link {