@riebeckite/plugin-l10n 0.0.13 → 0.0.15

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
@@ -92,4 +92,5 @@ Each translated entry receives one `<link rel="alternate" hreflang="…">` per e
92
92
 
93
93
  ## See also
94
94
 
95
- - [Plugin guide](../../../docs/en/reference/plugin-api.md)
95
+ - [Plugin guide](../../../docs/en/docs/reference/plugin-api.md)
96
+
package/README_ja.md CHANGED
@@ -73,4 +73,5 @@ l10n({
73
73
 
74
74
  ## ????
75
75
 
76
- - [?????????](../../../docs/ja/reference/plugin-api.md)
76
+ - [?????????](../../../docs/ja/docs/reference/plugin-api.md)
77
+
package/dist/index.js CHANGED
@@ -31,6 +31,8 @@ function l10n(options) {
31
31
  let state = emptyState();
32
32
  return definePlugin({
33
33
  name: "l10n",
34
+ provides: ["content.localization"],
35
+ outputDependencies: [{ type: "global" }],
34
36
  options,
35
37
  assets: [createStyleAsset("l10n")],
36
38
  validateOptions: () => validateOptions(options).map((message) => ({ path: "l10n", message })),
@@ -110,7 +112,7 @@ function getLocalization(manifest, slug) {
110
112
  const lang = entry.publicLocation.metadata?.[LANGUAGE_METADATA_KEY];
111
113
  const translationId = entry.publicLocation.metadata?.[TRANSLATION_METADATA_KEY];
112
114
  if (!lang || !translationId) return null;
113
- const candidates = manifest.entries.filter(
115
+ const candidates = manifest.discoverableEntries.filter(
114
116
  (candidate) => candidate.publicLocation.metadata?.[TRANSLATION_METADATA_KEY] === translationId
115
117
  );
116
118
  const translations = Object.fromEntries(
@@ -131,7 +133,7 @@ function getLocalization(manifest, slug) {
131
133
  function getLocalizedContent(manifest, slug, lang) {
132
134
  const localization = getLocalization(manifest, slug);
133
135
  if (!localization) return null;
134
- const candidates = manifest.entries.filter(
136
+ const candidates = manifest.publicEntries.filter(
135
137
  (entry) => entry.publicLocation.metadata?.[TRANSLATION_METADATA_KEY] === localization.translationId && entry.publicLocation.metadata?.[LANGUAGE_METADATA_KEY] === lang
136
138
  );
137
139
  return candidates.length === 1 ? candidates[0] ?? null : null;
@@ -385,36 +387,46 @@ function resolveLocalizedTarget(state, source, targetSlug) {
385
387
  return findTranslation(state, target.translationId, source.lang) ?? target;
386
388
  }
387
389
  function addLocalizationHeadTags(manifest, state) {
388
- for (const entry of manifest.entries) {
390
+ for (const entry of manifest.discoverableEntries) {
389
391
  const content = state.contents.get(entry.slug);
390
392
  if (!content) continue;
391
393
  const translations = uniqueLanguageEntries(
392
- manifest.entries.filter(
394
+ manifest.discoverableEntries.filter(
393
395
  (candidate) => candidate.publicLocation.metadata?.[TRANSLATION_METADATA_KEY] === content.translationId
394
396
  )
395
397
  );
396
- entry.headTags = [
397
- ...entry.headTags ?? [],
398
- ...translations.map((translation) => ({
398
+ const headTags = translations.map(
399
+ (translation) => ({
399
400
  tag: "link",
400
401
  attrs: {
401
402
  rel: "alternate",
402
403
  hreflang: translation.publicLocation.metadata?.[LANGUAGE_METADATA_KEY] ?? "",
403
404
  href: translation.permalink
404
405
  }
405
- }))
406
+ })
407
+ );
408
+ entry.headTags = [
409
+ ...(entry.headTags ?? []).filter(
410
+ (tag) => !headTags.some((generated) => sameHeadTag(tag, generated))
411
+ ),
412
+ ...headTags
406
413
  ];
407
414
  }
408
415
  }
409
416
  function addLanguageSwitchers(manifest, ui) {
410
417
  if (ui === false) return;
411
- for (const entry of manifest.entries) {
418
+ for (const entry of manifest.discoverableEntries) {
412
419
  const localization = getLocalization(manifest, entry.slug);
413
420
  if (!localization) continue;
414
421
  const html = ui.render({ localization });
415
- if (html) appendContentBodySlot(entry, ui.slot, html);
422
+ if (html && !entry.bodySlots?.[ui.slot]?.includes(html)) {
423
+ appendContentBodySlot(entry, ui.slot, html);
424
+ }
416
425
  }
417
426
  }
427
+ function sameHeadTag(left, right) {
428
+ return left.tag === right.tag && left.attrs?.rel === right.attrs?.rel && left.attrs?.hreflang === right.attrs?.hreflang && left.attrs?.href === right.attrs?.href;
429
+ }
418
430
  function uniqueLanguageEntries(entries) {
419
431
  return entries.filter((entry) => {
420
432
  const lang = entry.publicLocation.metadata?.[LANGUAGE_METADATA_KEY];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-l10n",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
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.13"
19
+ "@riebeckite/core": "0.0.15"
20
20
  },
21
21
  "devDependencies": {
22
22
  "tsx": "^4.22.4",
23
- "@riebeckite/plugin-obsidian-markdown": "0.0.13"
23
+ "@riebeckite/plugin-obsidian-markdown": "0.0.15"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"