starlight-annotations 0.5.0 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # starlight-annotations
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4ff776c: Adds the overview page for every locale of a multilingual site (`/it/annotations/` next to `/annotations/`), in that locale's language, and makes the notes panel link to the one in the reader's language. A sidebar link to `/annotations/` no longer leads to a missing page on localized pages, since Starlight adds the locale to it.
8
+
3
9
  ## 0.5.0
4
10
 
5
11
  ### Minor Changes
package/index.js CHANGED
@@ -18,10 +18,16 @@ export default function starlightAnnotations(options = {}) {
18
18
  // Starlight links customCss on every page, in dev and in the build.
19
19
  // (CSS imported by an injected script is bundled but not linked.)
20
20
  updateConfig({ customCss: [...(starlightConfig.customCss ?? []), 'starlight-annotations/styles.css'] });
21
- // The overview page is not localized: it speaks the default language.
21
+ // The overview page exists once per locale (/annotations/, /it/annotations/…),
22
+ // because Starlight prefixes sidebar links with the reader's locale.
22
23
  const locales = starlightConfig.locales ?? {};
23
24
  const lang = locales[starlightConfig.defaultLocale ?? 'root']?.lang ?? locales.root?.lang ?? starlightConfig.defaultLocale ?? 'en';
24
- addIntegration(annotationsIntegration({ ...config, lang }));
25
+ const prefixed = Object.fromEntries(
26
+ Object.entries(locales)
27
+ .filter(([key]) => key !== 'root')
28
+ .map(([key, locale]) => [key, locale?.lang ?? key]),
29
+ );
30
+ addIntegration(annotationsIntegration({ ...config, lang, locales: prefixed }));
25
31
  },
26
32
  },
27
33
  };
@@ -79,7 +85,11 @@ function annotationsIntegration(config) {
79
85
  });
80
86
  injectScript('page', `import 'starlight-annotations/client';`);
81
87
  if (config.overview) {
82
- injectRoute({ pattern: `/${config.overview}`, entrypoint: fileURLToPath(new URL('./src/overview.astro', import.meta.url)), prerender: true });
88
+ injectRoute({
89
+ pattern: `/[...locale]/${config.overview}`,
90
+ entrypoint: fileURLToPath(new URL('./src/overview.astro', import.meta.url)),
91
+ prerender: true,
92
+ });
83
93
  }
84
94
  },
85
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-annotations",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "🖍️ Let readers highlight text and leave notes on Starlight docs. Notes are committed to your Git repository on GitHub, GitLab, Gitea or Forgejo.",
5
5
  "license": "MIT",
6
6
  "author": "Alessandro Rosa",
@@ -247,7 +247,11 @@ async function start(root) {
247
247
  const toggle = h('button', { type: 'button', class: 'annot-toggle', onclick: () => setOpen(!drawer.classList.contains('open')) }, T.notes, count);
248
248
  const body = h('div', { class: 'annot-body' });
249
249
  // The page with every note on the site, when the plugin adds it.
250
- const overviewUrl = config.overview ? `${BASE}/${config.overview}/` : null;
250
+ // In the reader's locale, like the rest of the page.
251
+ const locale = page.split('/')[0];
252
+ const overviewUrl = config.overview
253
+ ? `${BASE}/${config.locales && locale in config.locales ? `${locale}/` : ''}${config.overview}/`
254
+ : null;
251
255
  const resolvedBox = h('input', {
252
256
  type: 'checkbox',
253
257
  onchange: (event) => {
@@ -1,13 +1,20 @@
1
1
  ---
2
- // The overview page, added by the plugin at `/<overview>/`. The list itself
3
- // is drawn in the browser (client/overview.js), from the same API as the
4
- // notes panel; here only the page titles are known, from the content.
2
+ // The overview page, added by the plugin at `/<overview>/` and once per
3
+ // locale (`/it/<overview>/`), so links from a localized sidebar or panel
4
+ // land in the reader's language. Every locale lists every note of the site.
5
+ // The list itself is drawn in the browser (client/overview.js), from the
6
+ // same API as the notes panel; here only the page titles are known.
5
7
  import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
6
8
  import { getCollection } from 'astro:content';
7
9
  import config from 'virtual:starlight-annotations/config';
8
10
  import { strings } from './client/i18n.js';
9
11
 
10
- const T = strings(config.lang, config.translations);
12
+ export function getStaticPaths() {
13
+ return [{ params: { locale: undefined } }, ...Object.keys(config.locales ?? {}).map((locale) => ({ params: { locale } }))];
14
+ }
15
+
16
+ const { locale } = Astro.params;
17
+ const T = strings(locale ? config.locales[locale] : config.lang, config.translations);
11
18
  const docs = await getCollection('docs');
12
19
  const titles = Object.fromEntries(docs.map((entry) => [entry.id, entry.data.title]));
13
20
  ---