@riebeckite/plugin-backlinks 0.0.16 → 0.0.18

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
@@ -7,10 +7,10 @@ current note.
7
7
 
8
8
  ## Overview
9
9
 
10
- `backlinks()` provides a `Backlinks` component that renders a footer list of
11
- incoming links. `getPublishedBacklinks()` resolves the incoming links of a
12
- note from the content manifest, keeps only notes whose `frontmatter` passes
13
- `isPublished`, and returns them sorted in manifest order.
10
+ `backlinksPlugin()` appends a footer list of incoming links to the
11
+ `article.footer` body slot. `getPublishedBacklinks()` resolves the incoming
12
+ links of a note from the content manifest, keeps only publicly discoverable
13
+ notes, and returns them sorted in manifest order.
14
14
 
15
15
  Without incoming links (or when none of them are published), the component
16
16
  renders nothing.
@@ -27,10 +27,11 @@ export default defineConfig({
27
27
  });
28
28
  ```
29
29
 
30
- `backlinksPlugin()` registers the plugin in the plugin list and bundles
31
- `style.css` into the app stylesheet.
30
+ `backlinksPlugin()` adds backlinks for every public entry with published
31
+ incoming links and bundles `style.css` into the app stylesheet. Render the
32
+ `article.footer` body slot in the article layout to display the list.
32
33
 
33
- ### Render the component
34
+ ### Custom placement
34
35
 
35
36
  ```tsx
36
37
  import Backlinks, { getPublishedBacklinks } from "@riebeckite/plugin-backlinks";
@@ -46,7 +47,6 @@ const backlinks = getPublishedBacklinks({
46
47
  resolveTitle: getArticleTitle,
47
48
  });
48
49
 
49
- // ...in your route
50
50
  return (
51
51
  <Article
52
52
  footerContent={<Backlinks backlinks={backlinks} />}
@@ -56,7 +56,7 @@ return (
56
56
 
57
57
  ## Component
58
58
 
59
- `Backlinks({ backlinks })` renders a `<footer class="article-backlinks">` with
59
+ `Backlinks({ backlinks })` renders a `<footer class="article-backlinks rr-backlinks">` with
60
60
  an eyebrow label and a list of links to each backlink's resolved `permalink`.
61
61
 
62
62
  ## Exports
@@ -69,6 +69,6 @@ an eyebrow label and a list of links to each backlink's resolved `permalink`.
69
69
 
70
70
  ## See also
71
71
 
72
- - [Plugin guide](../../../docs/en/docs/reference/plugin-api.md)
72
+ - [Plugin guide](../../../docs/docs/reference/plugin-api.en.md)
73
73
  - [`@riebeckite/plugin-local-graph`](../local-graph/README.md)
74
74
  - [`@riebeckite/plugin-garden-explorer`](../garden-explorer/README.md)
package/README_ja.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## できること
8
8
 
9
- `getPublishedBacklinks()` はコンテンツマニフェストから被リンクを集め、`isPublished` を通るノートだけをマニフェスト順で返します。`Backlinks` コンポーネントはその結果をフッターのリンク一覧として描画します。表示対象がなければ何も出力しません。
9
+ `backlinksPlugin()` はコンテンツマニフェストから被リンクを集め、公開対象のノートだけをマニフェスト順で `article.footer` body slot に追加します。`Backlinks` コンポーネントはその結果をフッターのリンク一覧として描画します。表示対象がなければ何も出力しません。
10
10
 
11
11
  ## 設定と配置
12
12
 
@@ -20,7 +20,11 @@ export default defineConfig({
20
20
  });
21
21
  ```
22
22
 
23
- プラグイン登録後も、表示位置はアプリ側で決めます。記事ルートなどでマニフェストを取得し、現在の `slug` に対する被リンクを渡してください。
23
+ プラグインは公開済みの被リンクがある記事へ自動的に出力を追加します。記事レイアウトで `article.footer` body slot を描画してください。
24
+
25
+ ### 独自の配置
26
+
27
+ Plugin が追加する footer ではなく、アプリ側で表示位置を決める場合は、記事ルートなどでマニフェストを取得し、現在の `slug` に対する被リンクを渡してください。
24
28
 
25
29
  ```tsx
26
30
  import Backlinks, { getPublishedBacklinks } from "@riebeckite/plugin-backlinks";
@@ -40,7 +44,6 @@ return <Article footerContent={<Backlinks backlinks={items} />} />;
40
44
 
41
45
  ## 関連資料
42
46
 
43
- - [プラグインシステム](../../../docs/ja/docs/reference/plugin-api.md)
47
+ - [プラグインシステム](../../../docs/docs/reference/plugin-api.md)
44
48
  - [`@riebeckite/plugin-local-graph`](../local-graph/README_ja.md)
45
49
  - [`@riebeckite/plugin-garden-explorer`](../garden-explorer/README_ja.md)
46
-
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // index.ts
2
- import { definePlugin } from "@riebeckite/core";
2
+ import { appendContentBodySlot, definePlugin } from "@riebeckite/core";
3
+ import { renderToString } from "hono/jsx/dom/server";
3
4
 
4
5
  // components/backlinks.tsx
5
6
  import { jsx, jsxs } from "hono/jsx/jsx-runtime";
@@ -33,6 +34,24 @@ function getPublishedBacklinks(args) {
33
34
  function backlinksPlugin() {
34
35
  return definePlugin({
35
36
  name: "backlinks",
37
+ order: 500,
38
+ onManifestCreated: ({ config, manifest }) => {
39
+ if (!config) return;
40
+ for (const entry of manifest.discoverableEntries) {
41
+ const backlinks = getPublishedBacklinks({
42
+ manifest,
43
+ config,
44
+ slug: entry.slug,
45
+ resolveTitle
46
+ });
47
+ if (backlinks.length === 0) continue;
48
+ appendContentBodySlot(
49
+ entry,
50
+ "article.footer",
51
+ renderToString(Backlinks({ backlinks }))
52
+ );
53
+ }
54
+ },
36
55
  assets: [
37
56
  {
38
57
  pluginName: "backlinks",
@@ -42,6 +61,10 @@ function backlinksPlugin() {
42
61
  ]
43
62
  });
44
63
  }
64
+ function resolveTitle(slug, title) {
65
+ if (typeof title === "string" && title.trim()) return title;
66
+ return slug.split("/").at(-1) ?? slug;
67
+ }
45
68
  export {
46
69
  Backlinks,
47
70
  backlinksPlugin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-backlinks",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
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.16"
25
+ "@riebeckite/core": "0.0.18"
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsx": "^4.22.4",
29
- "@riebeckite/test": "0.0.16"
29
+ "@riebeckite/test": "0.0.18"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
package/style.css CHANGED
@@ -1,6 +1,5 @@
1
1
  .article-backlinks {
2
- margin-top: 4rem;
3
- margin-bottom: 4rem;
2
+ margin-block-start: var(--rb-space-6, 3rem);
4
3
  padding-top: 1.5rem;
5
4
  border-top: 1px solid color-mix(in srgb, currentColor 16%, transparent);
6
5
  }