@riebeckite/plugin-l10n 0.0.11 → 0.0.13
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 +2 -2
- package/README_ja.md +2 -2
- package/dist/index.js +9 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -86,10 +86,10 @@ l10n({
|
|
|
86
86
|
|
|
87
87
|
## Links and SEO
|
|
88
88
|
|
|
89
|
-
Before the existing Content Graph is built, WikiLink graph targets are switched to the source note's language when that translation exists; otherwise their original target remains. The rendered article rewrites both WikiLinks and Markdown links to an existing translation in the current page's language, preserving query strings and fragments.
|
|
89
|
+
Before the existing Content Graph is built, WikiLink graph targets are switched to the source note's language when that translation exists; otherwise their original target remains. The rendered article rewrites both Obsidian WikiLinks (after `@riebeckite/plugin-obsidian-markdown` resolves them) and Markdown links to an existing translation in the current page's language, preserving query strings and fragments. When no translation exists, the original/default target remains linked. External, fragment-only, unknown, asset, and other non-content URLs remain unchanged. The Content Graph and rendered links use the same resolution policy; no second graph is created.
|
|
90
90
|
|
|
91
91
|
Each translated entry receives one `<link rel="alternate" hreflang="…">` per existing translation through Core's `headTags` extension point. The site shell remains responsible for rendering those tags and for selecting `<html lang>` for a request.
|
|
92
92
|
|
|
93
93
|
## See also
|
|
94
94
|
|
|
95
|
-
- [Plugin guide](../../../docs/en/plugin-
|
|
95
|
+
- [Plugin guide](../../../docs/en/reference/plugin-api.md)
|
package/README_ja.md
CHANGED
|
@@ -56,7 +56,7 @@ l10n({
|
|
|
56
56
|
|
|
57
57
|
Theme は `.l10n-switcher` の CSS class を上書きできます。`ui.render` はフレームワーク非依存の HTML renderer なので、カスタム Site は任意のサーバー描画コンポーネントへ置き換えられます。
|
|
58
58
|
|
|
59
|
-
各ページには実在する翻訳だけを対象に `hreflang` の alternate link を追加します。WikiLink の Content Graph
|
|
59
|
+
各ページには実在する翻訳だけを対象に `hreflang` の alternate link を追加します。WikiLink の Content Graph は同言語の翻訳を優先し、なければ元のリンク先を使います。本文では Obsidian WikiLink を `@riebeckite/plugin-obsidian-markdown` が解決した後、WikiLink と Markdown の内部リンクを同じ規則で処理します。現在のページと同じ言語の翻訳があればその URL に切り替え、なければ original/default のリンク先を維持します。クエリ文字列とフラグメントは維持し、外部 URL、フラグメントのみのリンク、不明な URL、asset などコンテンツ以外の URL は変更しません。Content Graph と本文リンクは同じ解決ポリシーを使います。
|
|
60
60
|
|
|
61
61
|
## 独自検出
|
|
62
62
|
|
|
@@ -73,4 +73,4 @@ l10n({
|
|
|
73
73
|
|
|
74
74
|
## ????
|
|
75
75
|
|
|
76
|
-
- [?????????](../../../docs/ja/plugin-
|
|
76
|
+
- [?????????](../../../docs/ja/reference/plugin-api.md)
|
package/dist/index.js
CHANGED
|
@@ -59,14 +59,8 @@ function l10n(options) {
|
|
|
59
59
|
if (!source) continue;
|
|
60
60
|
entry.links = entry.links.map((link) => {
|
|
61
61
|
if (!link.slug) return link;
|
|
62
|
-
const target = state
|
|
63
|
-
|
|
64
|
-
const localized = findTranslation(
|
|
65
|
-
state,
|
|
66
|
-
target.translationId,
|
|
67
|
-
source.lang
|
|
68
|
-
);
|
|
69
|
-
return localized ? { ...link, kind: "note", slug: localized.slug } : link;
|
|
62
|
+
const target = resolveLocalizedTarget(state, source, link.slug);
|
|
63
|
+
return target ? { ...link, kind: "note", slug: target.slug } : link;
|
|
70
64
|
});
|
|
71
65
|
}
|
|
72
66
|
},
|
|
@@ -103,14 +97,8 @@ function localizeLinkUrl(url, source, options, slugsByPermalink) {
|
|
|
103
97
|
const { permalink, suffix } = splitLinkUrl(url);
|
|
104
98
|
const targetSlug = slugsByPermalink.get(permalink);
|
|
105
99
|
if (!targetSlug) return url;
|
|
106
|
-
const target = options.state
|
|
107
|
-
|
|
108
|
-
const localized = findTranslation(
|
|
109
|
-
options.state,
|
|
110
|
-
target.translationId,
|
|
111
|
-
source.lang
|
|
112
|
-
);
|
|
113
|
-
return localized ? `${options.resolvePermalink(localized.slug)}${suffix}` : url;
|
|
100
|
+
const target = resolveLocalizedTarget(options.state, source, targetSlug);
|
|
101
|
+
return target ? `${options.resolvePermalink(target.slug)}${suffix}` : url;
|
|
114
102
|
}
|
|
115
103
|
function splitLinkUrl(url) {
|
|
116
104
|
const suffixIndex = url.search(/[?#]/);
|
|
@@ -391,6 +379,11 @@ function findTranslation(state, translationId, lang) {
|
|
|
391
379
|
(content) => content.translationId === translationId && content.lang === lang
|
|
392
380
|
) ?? null;
|
|
393
381
|
}
|
|
382
|
+
function resolveLocalizedTarget(state, source, targetSlug) {
|
|
383
|
+
const target = state.contents.get(targetSlug);
|
|
384
|
+
if (!target) return null;
|
|
385
|
+
return findTranslation(state, target.translationId, source.lang) ?? target;
|
|
386
|
+
}
|
|
394
387
|
function addLocalizationHeadTags(manifest, state) {
|
|
395
388
|
for (const entry of manifest.entries) {
|
|
396
389
|
const content = state.contents.get(entry.slug);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-l10n",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"yaml": "^2.9.0",
|
|
19
|
-
"@riebeckite/core": "0.0.
|
|
19
|
+
"@riebeckite/core": "0.0.13"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"tsx": "^4.22.4",
|
|
23
|
-
"@riebeckite/plugin-obsidian-markdown": "0.0.
|
|
23
|
+
"@riebeckite/plugin-obsidian-markdown": "0.0.13"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|