starlight-versions 0.2.0 → 0.3.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.
@@ -13,12 +13,12 @@ import starlightVersionsConfig from 'virtual:starlight-versions-config'
13
13
 
14
14
  import { getVersionFromSlug, getVersionIdentifier, getVersionURL } from '../libs/versions'
15
15
 
16
- const { entry, labels } = Astro.props
16
+ const { entry } = Astro.props
17
17
 
18
18
  const pagefindTranslations = {
19
- placeholder: labels['search.label'],
19
+ placeholder: Astro.locals.t('search.label'),
20
20
  ...Object.fromEntries(
21
- Object.entries(labels)
21
+ Object.entries(Astro.locals.t.all())
22
22
  .filter(([key]) => key.startsWith('pagefind.'))
23
23
  .map(([key, value]) => [key.replace('pagefind.', ''), value]),
24
24
  ),
@@ -35,20 +35,20 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
35
35
  data-pagefind-filter={`version:${pageVersionIdentifier}`}
36
36
  >
37
37
  <button data-open-modal disabled>
38
- <Icon name="magnifier" label={labels['search.label']} />
39
- <span class="sl-hidden md:sl-block" aria-hidden="true">{labels['search.label']}</span>
40
- <Icon name="forward-slash" class="sl-hidden md:sl-block" label={labels['search.shortcutLabel']} />
38
+ <Icon name="magnifier" label={Astro.locals.t('search.label')} />
39
+ <span class="sl-hidden md:sl-block" aria-hidden="true">{Astro.locals.t('search.label')}</span>
40
+ <Icon name="forward-slash" class="sl-hidden md:sl-block" label={Astro.locals.t('search.shortcutLabel')} />
41
41
  </button>
42
42
 
43
- <dialog style="padding:0" aria-label={labels['search.label']}>
43
+ <dialog style="padding:0" aria-label={Astro.locals.t('search.label')}>
44
44
  <div class="dialog-frame sl-flex">
45
45
  <button data-close-modal class="sl-flex md:sl-hidden">
46
- {labels['search.cancelLabel']}
46
+ {Astro.locals.t('search.cancelLabel')}
47
47
  </button>
48
48
  {
49
49
  import.meta.env.DEV ? (
50
50
  <div style="margin: auto; text-align: center; white-space: pre-line;" dir="ltr">
51
- <p>{labels['search.devWarning']}</p>
51
+ <p>{Astro.locals.t('search.devWarning')}</p>
52
52
  </div>
53
53
  ) : (
54
54
  <div class="search-container">
@@ -15,7 +15,7 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
15
15
  <label>
16
16
  <span class="sr-only">Select version</span>
17
17
  <Icon name="seti:clock" class="icon label-icon" />
18
- <select value={pageVersion?.label ?? 'current'}>
18
+ <select value={pageVersion?.label ?? 'current'} autocomplete="off">
19
19
  <option
20
20
  selected={pageVersion === undefined}
21
21
  value={getVersionURL(starlightVersionsConfig, starlightConfig, Astro.url, undefined).pathname}
@@ -101,11 +101,25 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
101
101
  constructor() {
102
102
  super()
103
103
 
104
- this.querySelector('select')?.addEventListener('change', (event) => {
104
+ const select = this.querySelector('select')
105
+ if (!select) return
106
+
107
+ select?.addEventListener('change', (event) => {
105
108
  if (event.currentTarget instanceof HTMLSelectElement) {
106
109
  window.location.pathname = event.currentTarget.value
107
110
  }
108
111
  })
112
+
113
+ window.addEventListener('pageshow', (event) => {
114
+ if (!event.persisted) return
115
+ const markupSelectedIndex = select.querySelector<HTMLOptionElement>('option[selected]')?.index
116
+
117
+ // If the page was loaded from a cache, the version select selected index might not be in sync with the
118
+ // current page.
119
+ if (markupSelectedIndex !== select.selectedIndex) {
120
+ select.selectedIndex = markupSelectedIndex ?? 0
121
+ }
122
+ })
109
123
  }
110
124
  },
111
125
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-versions",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to version documentation pages.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -40,7 +40,7 @@
40
40
  "vitest": "^1.6.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "@astrojs/starlight": ">=0.25.0"
43
+ "@astrojs/starlight": ">=0.28.0"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18"