starlight-versions 0.5.6 → 0.6.0

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-versions
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#50](https://github.com/HiDeoo/starlight-versions/pull/50) [`983229b`](https://github.com/HiDeoo/starlight-versions/commit/983229b1d907f5bba1e774df40545db21cbb4206) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for translating the plugin's UI strings.
8
+
3
9
  ## 0.5.6
4
10
 
5
11
  ### Patch Changes
@@ -13,10 +13,16 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
13
13
  {
14
14
  pageVersion && template === 'splash' && (
15
15
  <div>
16
- This content is for {pageVersion.label ?? `the ${pageVersion.slug} version`}. Switch to the
17
- {/* prettier-ignore */}
18
- <a href={getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname}>latest version</a>
19
- for up-to-date documentation.
16
+ {pageVersion.label ? (
17
+ <Fragment set:html={Astro.locals.t('starlightVersions.outdated.label', { label: pageVersion.label })} />
18
+ ) : (
19
+ <Fragment set:html={Astro.locals.t('starlightVersions.outdated.slug', { slug: pageVersion.slug })} />
20
+ )}{' '}
21
+ <Fragment
22
+ set:html={Astro.locals.t('starlightVersions.link.latest', {
23
+ link: getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname,
24
+ })}
25
+ />
20
26
  </div>
21
27
  )
22
28
  }
@@ -32,7 +38,7 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
32
38
  text-wrap: balance;
33
39
  }
34
40
 
35
- div a {
41
+ div :global(a) {
36
42
  color: var(--sl-color-orange-high);
37
43
  }
38
44
  </style>
@@ -13,10 +13,16 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
13
13
  <p>
14
14
  <Icon name="seti:clock" size="1em" color="var(--sl-color-orange-high)" />
15
15
  <span>
16
- This content is for {pageVersion.label ?? `the ${pageVersion.slug} version`}. Switch to the
17
- {/* prettier-ignore */}
18
- <a href={getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname}>latest version</a>
19
- for up-to-date documentation.
16
+ {pageVersion.label ? (
17
+ <Fragment set:html={Astro.locals.t('starlightVersions.outdated.label', { label: pageVersion.label })} />
18
+ ) : (
19
+ <Fragment set:html={Astro.locals.t('starlightVersions.outdated.slug', { slug: pageVersion.slug })} />
20
+ )}{' '}
21
+ <Fragment
22
+ set:html={Astro.locals.t('starlightVersions.link.latest', {
23
+ link: getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname,
24
+ })}
25
+ />
20
26
  </span>
21
27
  </p>
22
28
  )
@@ -37,7 +43,7 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
37
43
  line-height: var(--sl-line-height-headings);
38
44
  }
39
45
 
40
- p a {
46
+ p :global(a) {
41
47
  color: var(--sl-color-orange-high);
42
48
  }
43
49
 
@@ -35,7 +35,7 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
35
35
  ---
36
36
 
37
37
  <site-search class={Astro.props['class']} {...dataAttributes}>
38
- <button data-open-modal disabled>
38
+ <button data-open-modal disabled aria-label={Astro.locals.t('search.label')} aria-keyshortcuts="Control+K">
39
39
  <Icon name="magnifier" />
40
40
  <span class="sl-hidden md:sl-block" aria-hidden="true">{Astro.locals.t('search.label')}</span>
41
41
  <kbd class="sl-hidden md:sl-flex" style="display: none;">
@@ -60,10 +60,22 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
60
60
  <div class="starlight-versions-pagefind-notice">
61
61
  <Icon name="seti:clock" size="1em" color="var(--sl-color-orange-high)" />
62
62
  <span>
63
- Search limited to {pageVersion.label ?? `the ${pageVersion.slug} version`}. Switch to the
64
- {/* prettier-ignore */}
65
- <a href={getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname}>latest version</a>
66
- for up-to-date results.
63
+ {pageVersion.label ? (
64
+ <Fragment
65
+ set:html={Astro.locals.t('starlightVersions.search.outdated.label', {
66
+ label: pageVersion.label,
67
+ })}
68
+ />
69
+ ) : (
70
+ <Fragment
71
+ set:html={Astro.locals.t('starlightVersions.search.outdated.slug', { slug: pageVersion.slug })}
72
+ />
73
+ )}{' '}
74
+ <Fragment
75
+ set:html={Astro.locals.t('starlightVersions.search.link.latest', {
76
+ link: getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname,
77
+ })}
78
+ />
67
79
  </span>
68
80
  </div>
69
81
  )}
@@ -97,6 +109,8 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
97
109
  </script>
98
110
 
99
111
  <script>
112
+ import { pagefindUserConfig } from 'virtual:starlight/pagefind-config'
113
+
100
114
  class SiteSearch extends HTMLElement {
101
115
  constructor() {
102
116
  super()
@@ -163,6 +177,7 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
163
177
  // @ts-expect-error — Missing types for @pagefind/default-ui package.
164
178
  const { PagefindUI } = await import('@pagefind/default-ui')
165
179
  const search = new PagefindUI({
180
+ ...pagefindUserConfig,
166
181
  element: '#starlight__search',
167
182
  baseUrl: import.meta.env.BASE_URL,
168
183
  bundlePath: `${import.meta.env.BASE_URL.replace(/\/$/, '')}/pagefind/`,
@@ -282,12 +297,13 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
282
297
  }
283
298
 
284
299
  #starlight__search {
285
- --pagefind-ui-primary: var(--sl-color-accent-light);
300
+ --pagefind-ui-primary: var(--sl-color-text);
286
301
  --pagefind-ui-text: var(--sl-color-gray-2);
287
302
  --pagefind-ui-font: var(--__sl-font);
288
303
  --pagefind-ui-background: var(--sl-color-black);
289
304
  --pagefind-ui-border: var(--sl-color-gray-5);
290
305
  --pagefind-ui-border-width: 1px;
306
+ --pagefind-ui-tag: var(--sl-color-gray-5);
291
307
  --sl-search-cancel-space: 5rem;
292
308
 
293
309
  display: flex;
@@ -499,6 +515,16 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
499
515
  font-weight: 600;
500
516
  }
501
517
 
518
+ #starlight__search .pagefind-ui__filter-value::before {
519
+ border-color: var(--sl-color-text-invert);
520
+ }
521
+
522
+ #starlight__search .pagefind-ui__result-tags {
523
+ background-color: var(--sl-color-black);
524
+ margin-top: 0;
525
+ padding: var(--sl-search-result-nested-pad-block) var(--sl-search-result-pad-inline-end);
526
+ }
527
+
502
528
  #starlight__search .pagefind-ui__filter-panel {
503
529
  display: none;
504
530
  }
@@ -12,7 +12,7 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
12
12
 
13
13
  <starlight-version-select>
14
14
  <label>
15
- <span class="sr-only">Select version</span>
15
+ <span class="sr-only">{Astro.locals.t('starlightVersions.select.accessibleLabel')}</span>
16
16
  <Icon name="seti:clock" class="icon label-icon" />
17
17
  <select value={pageVersion?.label ?? 'current'} autocomplete="off">
18
18
  <option
package/index.ts CHANGED
@@ -4,6 +4,7 @@ import { StarlightVersionsConfigSchema, type StarlightVersionsUserConfig } from
4
4
  import { overrideComponents, throwPluginError } from './libs/plugin'
5
5
  import { ensureNewVersion, getVersionedSidebar } from './libs/versions'
6
6
  import { vitePluginStarlightVersions } from './libs/vite'
7
+ import { Translations } from './translations'
7
8
 
8
9
  export type { StarlightVersionsConfig, StarlightVersionsUserConfig } from './libs/config'
9
10
 
@@ -21,6 +22,9 @@ export default function starlightVersionsPlugin(userConfig: StarlightVersionsUse
21
22
  return {
22
23
  name: 'starlight-versions-plugin',
23
24
  hooks: {
25
+ 'i18n:setup'({ injectTranslations }) {
26
+ injectTranslations(Translations)
27
+ },
24
28
  async 'config:setup'({
25
29
  addIntegration,
26
30
  addRouteMiddleware,
package/locals.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare namespace App {
2
+ type StarlightLocals = import('@astrojs/starlight').StarlightLocals
3
+ interface Locals extends StarlightLocals {}
4
+ }
5
+
6
+ declare namespace StarlightApp {
7
+ type Translations = typeof import('./translations').Translations.en
8
+ interface I18n extends Translations {}
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-versions",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to version documentation pages.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -0,0 +1,11 @@
1
+ export const Translations = {
2
+ en: {
3
+ 'starlightVersions.link.latest': 'Switch to the <a href={{link}}>latest version</a> for up-to-date documentation.',
4
+ 'starlightVersions.outdated.label': 'This content is for {{label}}.',
5
+ 'starlightVersions.outdated.slug': 'This content is for the {{slug}} version.',
6
+ 'starlightVersions.search.link.latest': 'Switch to the <a href={{link}}>latest version</a> for up-to-date results.',
7
+ 'starlightVersions.search.outdated.label': 'Search limited to {{label}}.',
8
+ 'starlightVersions.search.outdated.slug': 'Search limited to the {{slug}} version.',
9
+ 'starlightVersions.select.accessibleLabel': 'Select version',
10
+ },
11
+ }
package/virtual.d.ts CHANGED
@@ -21,3 +21,9 @@ declare module 'virtual:starlight/project-context' {
21
21
  }
22
22
  export default ProjectContext
23
23
  }
24
+
25
+ declare module 'virtual:starlight/pagefind-config' {
26
+ export const pagefindUserConfig: Partial<
27
+ Extract<import('@astrojs/starlight/types').StarlightConfig['pagefind'], object>
28
+ >
29
+ }