starlight-theme-nova 0.9.1 → 0.9.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "starlight-theme-nova",
3
3
  "type": "module",
4
- "version": "0.9.1",
4
+ "version": "0.9.3",
5
5
  "description": "",
6
6
  "author": "ocavue <ocavue@gmail.com>",
7
7
  "license": "MIT",
@@ -28,9 +28,9 @@
28
28
  "dependencies": {
29
29
  "@aria-ui/core": "^0.0.21",
30
30
  "@pagefind/default-ui": "^1.3.0",
31
- "@shikijs/transformers": "^3.7.0",
32
- "@shikijs/twoslash": "^3.7.0",
33
- "@shikijs/types": "^3.7.0",
31
+ "@shikijs/transformers": "^3.9.1",
32
+ "@shikijs/twoslash": "^3.9.1",
33
+ "@shikijs/types": "^3.9.1",
34
34
  "@types/hast": "^3.0.4",
35
35
  "astro-theme-toggle": "^0.6.1",
36
36
  "hast-util-is-element": "^3.0.0",
@@ -47,17 +47,17 @@
47
47
  }
48
48
  },
49
49
  "devDependencies": {
50
- "@astrojs/starlight": "^0.34.4",
50
+ "@astrojs/starlight": "^0.35.2",
51
51
  "@iconify-json/bxl": "^1.2.2",
52
- "@iconify-json/logos": "^1.2.4",
53
- "@iconify-json/lucide": "^1.2.54",
54
- "@iconify-json/tabler": "^1.2.19",
52
+ "@iconify-json/logos": "^1.2.5",
53
+ "@iconify-json/lucide": "^1.2.59",
54
+ "@iconify-json/tabler": "^1.2.20",
55
55
  "@ocavue/tsconfig": "^0.3.7",
56
56
  "@types/node": "^20.17.30",
57
- "@unocss/cli": "^66.1.3",
58
- "astro": "^5.10.1",
57
+ "@unocss/cli": "^66.3.2",
58
+ "astro": "^5.12.7",
59
59
  "typescript": "^5.8.3",
60
- "unocss": "^66.1.3",
60
+ "unocss": "^66.3.2",
61
61
  "unocss-preset-animations": "^1.2.1"
62
62
  },
63
63
  "scripts": {
@@ -9,30 +9,11 @@ import ThemeSelect from 'virtual:starlight/components/ThemeSelect'
9
9
 
10
10
  import options from 'virtual:starlight-theme-nova/user-config'
11
11
  import MobileMenuToggle from './MobileMenuToggle.astro'
12
+ import { getI18nText } from './get-i18n-text'
12
13
 
13
14
  const nav = options.nav ?? []
14
15
 
15
- const { locale } = Astro.locals.starlightRoute
16
-
17
- const getLocalizedValue = (
18
- value: string | { [local: string]: string },
19
- ): string => {
20
- if (typeof value === 'string') {
21
- return value
22
- }
23
-
24
- if (typeof locale === 'string' && value[locale]) {
25
- return value[locale]
26
- }
27
-
28
- // Use the same "root" convention as the Starlight docs to get the default value.
29
- // https://github.com/withastro/starlight/blob/9d3ba179c5d524c1c61d771ceb1a7b4e754bee16/docs/src/content/docs/guides/i18n.mdx?plain=1#L72-L75
30
- if (value['root']) {
31
- return value['root']
32
- }
33
-
34
- return Object.values(value)[0] ?? ''
35
- }
16
+ const route = Astro.locals.starlightRoute
36
17
  ---
37
18
 
38
19
  <div class="nova-header">
@@ -42,8 +23,8 @@ const getLocalizedValue = (
42
23
  <nav class="nova-header-nav">
43
24
  {
44
25
  nav.map((item) => (
45
- <a class="nova-header-nav-link" href={getLocalizedValue(item.href)}>
46
- {getLocalizedValue(item.label)}
26
+ <a class="nova-header-nav-link" href={getI18nText(item.href, route)}>
27
+ {getI18nText(item.label, route)}
47
28
  </a>
48
29
  ))
49
30
  }
@@ -41,7 +41,7 @@ const { hasSidebar } = Astro.locals.starlightRoute
41
41
  .sidebar-content {
42
42
  height: 100%;
43
43
  min-height: max-content;
44
- padding: 1rem var(--sl-sidebar-pad-x) 0;
44
+ padding: 1rem var(--sl-sidebar-pad-x) 1rem;
45
45
  flex-direction: column;
46
46
  gap: 1rem;
47
47
  }
@@ -0,0 +1,45 @@
1
+ import type { StarlightRouteData } from '@astrojs/starlight/route-data'
2
+ import config from 'virtual:starlight/user-config'
3
+
4
+ export function getI18nText(
5
+ value: string | Record<string, string>,
6
+ route: StarlightRouteData,
7
+ ): string {
8
+ if (typeof value === 'string') {
9
+ return value
10
+ }
11
+
12
+ const { lang, locale } = route
13
+
14
+ // Try `lang` first, which is a BCP-47 language tag
15
+ if (value[lang]) {
16
+ return value[lang]
17
+ }
18
+
19
+ // Use the same "root" convention as the Starlight docs to get the default value.
20
+ // https://github.com/withastro/starlight/blob/9d3ba179c5d524c1c61d771ceb1a7b4e754bee16/docs/src/content/docs/guides/i18n.mdx?plain=1#L72-L75
21
+ if (
22
+ config.defaultLocale.lang === lang ||
23
+ config.defaultLocale.locale === locale
24
+ ) {
25
+ if (value['root']) {
26
+ return value['root']
27
+ }
28
+ }
29
+
30
+ const message =
31
+ `[Astrobook] Unable to find the translation for language "${lang}".\n` +
32
+ `Are you using the correct BCP-47 language tag ` +
33
+ `(e.g. "en", "ar", or "zh-CN") in the following configuration?\n` +
34
+ JSON.stringify(value, null, 2) +
35
+ '\n'
36
+
37
+ // Fallback to the `locale`, which is a base path at which a language is
38
+ // served. This is not of the same format as the `lang` BCP-47 language tag.
39
+ if (locale && value[locale]) {
40
+ console.warn(message)
41
+ return value[locale]
42
+ }
43
+
44
+ throw new Error(message)
45
+ }
@@ -1,5 +1,13 @@
1
1
  export interface NavItem {
2
+ /**
3
+ * The visible label for this item in the navigation. It could be a string or
4
+ * a record of strings with the language code as the key.
5
+ */
2
6
  label: string | Record<string, string>
7
+ /**
8
+ * The link to this item’s content. It could be a string or a record of
9
+ * strings with the language code as the key.
10
+ */
3
11
  href: string | Record<string, string>
4
12
  }
5
13