starlight-obsidian 0.10.0 → 0.11.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,19 @@
1
1
  # starlight-obsidian
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#67](https://github.com/HiDeoo/starlight-obsidian/pull/67) [`2969770`](https://github.com/HiDeoo/starlight-obsidian/commit/296977054e79da21b3b081f245b9e4ed69d26066) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Improves error message when the `output` directory configuration option is invalid.
8
+
9
+ - [#69](https://github.com/HiDeoo/starlight-obsidian/pull/69) [`619d371`](https://github.com/HiDeoo/starlight-obsidian/commit/619d371f1a14d48cf68702f28245ac42deee4a39) Thanks [@AsterisMono](https://github.com/AsterisMono)! - Adds support for translating the generated vault pages sidebar group label.
10
+
11
+ ## 0.10.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#63](https://github.com/HiDeoo/starlight-obsidian/pull/63) [`3e638d4`](https://github.com/HiDeoo/starlight-obsidian/commit/3e638d43b191da7685d59d3bc7d86ec3de4a922f) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Setups trusted publishing using OpenID Connect (OIDC) authentication — no code changes.
16
+
3
17
  ## 0.10.0
4
18
 
5
19
  ### Minor Changes
package/index.ts CHANGED
@@ -6,6 +6,7 @@ import { z } from 'astro/zod'
6
6
 
7
7
  import { starlightObsidianIntegration } from './libs/integration'
8
8
  import { getObsidianPaths, getVault } from './libs/obsidian'
9
+ import { stripLeadingAndTrailingSlashes } from './libs/path'
9
10
  import { throwUserError } from './libs/plugin'
10
11
  import { addObsidianFiles, getSidebarFromConfig, getSidebarGroupPlaceholder, type SidebarGroup } from './libs/starlight'
11
12
 
@@ -65,7 +66,18 @@ const starlightObsidianConfigSchema = z.object({
65
66
  *
66
67
  * @default 'notes'
67
68
  */
68
- output: z.string().default('notes'),
69
+ output: z
70
+ .string()
71
+ .default('notes')
72
+ .refine(
73
+ (value) => {
74
+ const label = stripLeadingAndTrailingSlashes(value)
75
+ return label !== '' && label !== '.' && !label.startsWith('..')
76
+ },
77
+ {
78
+ message: "The `output` directory cannot be empty, '.', or start with '..'.",
79
+ },
80
+ ),
69
81
  /**
70
82
  * Whether the Starlight Obsidian plugin should skip the generation of the Obsidian vault pages.
71
83
  *
@@ -95,9 +107,12 @@ const starlightObsidianConfigSchema = z.object({
95
107
  /**
96
108
  * The generated vault pages sidebar group label.
97
109
  *
110
+ * The value can be a string, or for multilingual sites, an object with values for each different locale.
111
+ * When using the object form, the keys must be BCP-47 tags (e.g. `en`, `ar`, or `zh-CN`).
112
+ *
98
113
  * @default 'Notes'
99
114
  */
100
- label: z.string().default('Notes'),
115
+ label: z.union([z.string(), z.record(z.string())]).default('Notes'),
101
116
  })
102
117
  .default({}),
103
118
  /**
@@ -179,7 +194,7 @@ function makeStarlightObsidianPlugin(
179
194
  ...overrideStarlightComponent(starlightConfig.components, logger, 'PageTitle'),
180
195
  },
181
196
  customCss: [...(starlightConfig.customCss ?? []), 'starlight-obsidian/styles/common'],
182
- sidebar: getSidebarFromConfig(config, starlightConfig.sidebar, sidebarGroup),
197
+ sidebar: getSidebarFromConfig(config, starlightConfig, sidebarGroup),
183
198
  }
184
199
 
185
200
  if (config.skipGeneration) {
package/libs/path.ts CHANGED
@@ -52,3 +52,17 @@ export function slashify(filePath: string) {
52
52
  export function osPath(filePath: string) {
53
53
  return filePath.replaceAll('/', path.sep)
54
54
  }
55
+
56
+ function stripLeadingSlash(href: string) {
57
+ if (href.startsWith('/')) href = href.slice(1)
58
+ return href
59
+ }
60
+
61
+ function stripTrailingSlash(href: string) {
62
+ if (href.endsWith('/')) href = href.slice(0, -1)
63
+ return href
64
+ }
65
+
66
+ export function stripLeadingAndTrailingSlashes(href: string): string {
67
+ return stripTrailingSlash(stripLeadingSlash(href))
68
+ }
package/libs/starlight.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
 
4
- import type { StarlightUserConfig } from '@astrojs/starlight/types'
4
+ import type { HookParameters, StarlightUserConfig } from '@astrojs/starlight/types'
5
5
  import type { AstroIntegrationLogger } from 'astro'
6
6
 
7
7
  import type { StarlightObsidianConfig } from '..'
@@ -75,23 +75,39 @@ export function getSidebarGroupPlaceholder(label = starlightObsidianSidebarGroup
75
75
 
76
76
  export function getSidebarFromConfig(
77
77
  config: StarlightObsidianConfig,
78
- sidebar: StarlightUserConfig['sidebar'],
78
+ starlightConfig: HookParameters<'config:setup'>['config'],
79
79
  sidebarGroupPlaceholder: SidebarGroup,
80
80
  ): StarlightUserConfig['sidebar'] {
81
- if (!sidebar || sidebar.length === 0) {
82
- return sidebar
81
+ if (!starlightConfig.sidebar || starlightConfig.sidebar.length === 0) {
82
+ return starlightConfig.sidebar
83
83
  }
84
84
 
85
85
  function replaceSidebarGroupPlaceholder(group: SidebarManualGroup): SidebarItem {
86
86
  if (group.label === sidebarGroupPlaceholder.label) {
87
- return {
87
+ const defaultLocaleConfig = starlightConfig.locales?.[starlightConfig.defaultLocale ?? 'root']
88
+ const label =
89
+ typeof config.sidebar.label === 'string'
90
+ ? config.sidebar.label
91
+ : config.sidebar.label[defaultLocaleConfig?.lang ?? 'en']
92
+
93
+ if (!label || label.length === 0) {
94
+ throw new Error('The generated vault pages sidebar group label must have a key for the default language.')
95
+ }
96
+
97
+ const group: SidebarGroup = {
88
98
  autogenerate: {
89
99
  collapsed: config.sidebar.collapsedFolders ?? config.sidebar.collapsed,
90
100
  directory: config.output,
91
101
  },
92
102
  collapsed: config.sidebar.collapsed,
93
- label: config.sidebar.label,
103
+ label,
94
104
  }
105
+
106
+ if (typeof config.sidebar.label !== 'string') {
107
+ group['translations'] = config.sidebar.label
108
+ }
109
+
110
+ return group
95
111
  }
96
112
 
97
113
  if (isSidebarGroup(group)) {
@@ -106,7 +122,7 @@ export function getSidebarFromConfig(
106
122
  return group
107
123
  }
108
124
 
109
- return sidebar.map((item) => {
125
+ return starlightConfig.sidebar.map((item) => {
110
126
  return isSidebarGroup(item) ? replaceSidebarGroupPlaceholder(item) : item
111
127
  })
112
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-obsidian",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to publish Obsidian vaults.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -55,8 +55,7 @@
55
55
  },
56
56
  "packageManager": "pnpm@8.14.1",
57
57
  "publishConfig": {
58
- "access": "public",
59
- "provenance": true
58
+ "access": "public"
60
59
  },
61
60
  "sideEffects": false,
62
61
  "keywords": [