starlight-obsidian 0.12.1 → 0.13.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,50 @@
1
1
  # starlight-obsidian
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#74](https://github.com/HiDeoo/starlight-obsidian/pull/74) [`175ab3f`](https://github.com/HiDeoo/starlight-obsidian/commit/175ab3f553eb77ee4004d30330c05b6f416393b4) Thanks [@HiDeoo](https://github.com/HiDeoo)! - ⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.39.0`.
8
+
9
+ Please use the `@astrojs/upgrade` command to upgrade your project:
10
+
11
+ ```sh
12
+ npx @astrojs/upgrade
13
+ ```
14
+
15
+ - [#74](https://github.com/HiDeoo/starlight-obsidian/pull/74) [`175ab3f`](https://github.com/HiDeoo/starlight-obsidian/commit/175ab3f553eb77ee4004d30330c05b6f416393b4) Thanks [@HiDeoo](https://github.com/HiDeoo)! - ⚠️ **BREAKING CHANGE:** Updates sidebar generation to support Starlight `0.39` autogenerated sidebar entries.
16
+
17
+ The previously exported `obsidianSidebarGroup` has been replaced by `obsidianSidebarEntries`, which now expands to the generated Obsidian sidebar entries.
18
+ The `sidebar.label` and `sidebar.collapsed` plugin options have been removed.
19
+
20
+ To migrate, create a [sidebar group](https://starlight.astro.build/guides/sidebar/#groups) in your Starlight configuration and place `obsidianSidebarEntries` in that group’s `items` array:
21
+
22
+ ```diff
23
+ -import starlightObsidian, { obsidianSidebarGroup } from 'starlight-obsidian'
24
+ +import starlightObsidian, { obsidianSidebarEntries } from 'starlight-obsidian'
25
+
26
+ starlight({
27
+ plugins: [
28
+ starlightObsidian({
29
+ vault: '../path/to/vault',
30
+ sidebar: {
31
+ - label: 'Notes',
32
+ - collapsed: true,
33
+ collapsedFolders: true,
34
+ },
35
+ }),
36
+ ],
37
+ sidebar: [
38
+ - obsidianSidebarGroup,
39
+ + {
40
+ + label: 'Notes',
41
+ + collapsed: true,
42
+ + items: [obsidianSidebarEntries],
43
+ + },
44
+ ],
45
+ })
46
+ ```
47
+
3
48
  ## 0.12.1
4
49
 
5
50
  ### Patch Changes
package/index.ts CHANGED
@@ -8,7 +8,12 @@ import { starlightObsidianIntegration } from './libs/integration'
8
8
  import { getObsidianPaths, getVault } from './libs/obsidian'
9
9
  import { stripLeadingAndTrailingSlashes } from './libs/path'
10
10
  import { throwUserError } from './libs/plugin'
11
- import { addObsidianFiles, getSidebarFromConfig, getSidebarGroupPlaceholder, type SidebarGroup } from './libs/starlight'
11
+ import {
12
+ addObsidianFiles,
13
+ getSidebarEntriesPlaceholder,
14
+ getSidebarFromConfig,
15
+ type SidebarAutoEntries,
16
+ } from './libs/starlight'
12
17
 
13
18
  const starlightObsidianConfigSchema = z.object({
14
19
  /**
@@ -88,31 +93,24 @@ const starlightObsidianConfigSchema = z.object({
88
93
  */
89
94
  skipGeneration: z.boolean().default(false),
90
95
  /**
91
- * The generated vault pages sidebar group configuration.
96
+ * The generated vault pages sidebar entries configuration.
92
97
  */
93
98
  sidebar: z
94
99
  .object({
95
100
  /**
96
- * Whether the generated vault pages root sidebar group should be collapsed by default.
97
- *
98
- * @default false
101
+ * @deprecated Use the `collapsed` option of the Starlight sidebar group that contains the vault pages instead.
99
102
  */
100
- collapsed: z.boolean().default(false),
103
+ collapsed: z.never().optional(),
101
104
  /**
102
105
  * Whether the sidebar groups of your vault nested folders should be collapsed by default.
103
106
  *
104
- * Defaults to the value of the `collapsed` option.
107
+ * @default false
105
108
  */
106
- collapsedFolders: z.boolean().optional(),
109
+ collapsedFolders: z.boolean().default(false),
107
110
  /**
108
- * The generated vault pages sidebar group label.
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
- *
113
- * @default 'Notes'
111
+ * @deprecated Use the `label` option of the Starlight sidebar group that contains the vault pages instead.
114
112
  */
115
- label: z.union([z.string(), z.record(z.string(), z.string())]).default('Notes'),
113
+ label: z.never().optional(),
116
114
  })
117
115
  .prefault({}),
118
116
  /**
@@ -131,19 +129,22 @@ const starlightObsidianConfigSchema = z.object({
131
129
 
132
130
  let overridesInjected = false
133
131
 
134
- export const obsidianSidebarGroup = getSidebarGroupPlaceholder()
132
+ export const obsidianSidebarEntries = getSidebarEntriesPlaceholder()
135
133
 
136
134
  export default function starlightObsidianPlugin(userConfig: StarlightObsidianUserConfig): StarlightPlugin {
137
- return makeStarlightObsidianPlugin(obsidianSidebarGroup)(userConfig)
135
+ return makeStarlightObsidianPlugin(obsidianSidebarEntries)(userConfig)
138
136
  }
139
137
 
140
- export function createStarlightObsidianPlugin(): [plugin: typeof starlightObsidianPlugin, sidebarGroup: SidebarGroup] {
141
- const sidebarGroup = getSidebarGroupPlaceholder(Symbol(randomBytes(24).toString('base64url')))
142
- return [makeStarlightObsidianPlugin(sidebarGroup), sidebarGroup]
138
+ export function createStarlightObsidianPlugin(): [
139
+ plugin: typeof starlightObsidianPlugin,
140
+ sidebarEntries: SidebarAutoEntries,
141
+ ] {
142
+ const sidebarEntries = getSidebarEntriesPlaceholder(Symbol(randomBytes(24).toString('base64url')))
143
+ return [makeStarlightObsidianPlugin(sidebarEntries), sidebarEntries]
143
144
  }
144
145
 
145
146
  function makeStarlightObsidianPlugin(
146
- sidebarGroup: SidebarGroup,
147
+ sidebarEntries: SidebarAutoEntries,
147
148
  ): (userConfig: StarlightObsidianUserConfig) => StarlightPlugin {
148
149
  overridesInjected = true
149
150
 
@@ -151,6 +152,18 @@ function makeStarlightObsidianPlugin(
151
152
  const parsedConfig = starlightObsidianConfigSchema.safeParse(userConfig)
152
153
 
153
154
  if (!parsedConfig.success) {
155
+ const isUsingRemovedSidebarGroupConfig = parsedConfig.error.issues.some((issue) => {
156
+ const path = issue.path.join('.')
157
+ return path === 'sidebar.label' || path === 'sidebar.collapsed'
158
+ })
159
+
160
+ if (isUsingRemovedSidebarGroupConfig) {
161
+ throwUserError(
162
+ 'The `sidebar.label` and `sidebar.collapsed` options have been removed.',
163
+ 'Create a group in your Starlight sidebar configuration, set the `label` and `collapsed` options on that group, and add `obsidianSidebarEntries` to its `items` array.\nFor more information see https://starlight.astro.build/guides/sidebar/#groups',
164
+ )
165
+ }
166
+
154
167
  const isUsingDeprecatedCopyStarlightFrontmatter = parsedConfig.error.issues.some(
155
168
  (issue) => issue.path.join('.') === 'copyStarlightFrontmatter',
156
169
  )
@@ -197,7 +210,7 @@ ${z.prettifyError(parsedConfig.error)}
197
210
  ...overrideStarlightComponent(starlightConfig.components, logger, 'PageTitle'),
198
211
  },
199
212
  customCss: [...(starlightConfig.customCss ?? []), 'starlight-obsidian/styles/common'],
200
- sidebar: getSidebarFromConfig(config, starlightConfig, sidebarGroup),
213
+ sidebar: getSidebarFromConfig(config, starlightConfig, sidebarEntries),
201
214
  }
202
215
 
203
216
  if (config.skipGeneration) {
package/libs/starlight.ts CHANGED
@@ -15,7 +15,7 @@ const assetsPath = 'src/assets'
15
15
  const docsPath = 'src/content/docs'
16
16
  const publicPath = 'public'
17
17
 
18
- const starlightObsidianSidebarGroupLabel = Symbol('StarlightObsidianSidebarGroupLabel')
18
+ const starlightObsidianSidebarEntriesDirectory = Symbol('StarlightObsidianSidebarEntriesDirectory')
19
19
 
20
20
  const obsidianToStarlightCalloutTypeMap: Record<string, string> = {
21
21
  note: 'note',
@@ -66,65 +66,40 @@ const starlightFrontmatterKeys = [
66
66
  'sidebar',
67
67
  ]
68
68
 
69
- export function getSidebarGroupPlaceholder(label = starlightObsidianSidebarGroupLabel): SidebarManualGroup {
70
- return {
71
- items: [],
72
- label: label.toString(),
73
- }
69
+ export function getSidebarEntriesPlaceholder(directory = starlightObsidianSidebarEntriesDirectory): SidebarAutoEntries {
70
+ return { autogenerate: { directory: directory.toString() } }
74
71
  }
75
72
 
76
73
  export function getSidebarFromConfig(
77
74
  config: StarlightObsidianConfig,
78
75
  starlightConfig: HookParameters<'config:setup'>['config'],
79
- sidebarGroupPlaceholder: SidebarGroup,
76
+ sidebarEntriesPlaceholder: SidebarAutoEntries,
80
77
  ): StarlightUserConfig['sidebar'] {
81
78
  if (!starlightConfig.sidebar || starlightConfig.sidebar.length === 0) {
82
79
  return starlightConfig.sidebar
83
80
  }
84
81
 
85
- function replaceSidebarGroupPlaceholder(group: SidebarManualGroup): SidebarItem {
86
- if (group.label === sidebarGroupPlaceholder.label) {
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 = {
82
+ function replaceSidebarEntriesPlaceholder(item: SidebarItem): SidebarItem {
83
+ if (isObsidianSidebarEntriesPlaceholder(item, sidebarEntriesPlaceholder)) {
84
+ return {
98
85
  autogenerate: {
99
- collapsed: config.sidebar.collapsedFolders ?? config.sidebar.collapsed,
100
86
  directory: config.output,
87
+ collapsed: config.sidebar.collapsedFolders,
101
88
  },
102
- collapsed: config.sidebar.collapsed,
103
- label,
104
- }
105
-
106
- if (typeof config.sidebar.label !== 'string') {
107
- group['translations'] = config.sidebar.label
108
89
  }
109
-
110
- return group
111
90
  }
112
91
 
113
- if (isSidebarGroup(group)) {
92
+ if (isSidebarGroup(item)) {
114
93
  return {
115
- ...group,
116
- items: group.items.map((item) => {
117
- return isSidebarGroup(item) ? replaceSidebarGroupPlaceholder(item) : item
118
- }),
94
+ ...item,
95
+ items: item.items.map(replaceSidebarEntriesPlaceholder),
119
96
  }
120
97
  }
121
98
 
122
- return group
99
+ return item
123
100
  }
124
101
 
125
- return starlightConfig.sidebar.map((item) => {
126
- return isSidebarGroup(item) ? replaceSidebarGroupPlaceholder(item) : item
127
- })
102
+ return starlightConfig.sidebar.map(replaceSidebarEntriesPlaceholder)
128
103
  }
129
104
 
130
105
  export async function addObsidianFiles(
@@ -297,20 +272,27 @@ function throwVaultFileError(error: unknown, vaultFile: VaultFile): never {
297
272
  throw new Error(`${vaultFile.path} — ${error instanceof Error ? error.message : String(error)}`, { cause: error })
298
273
  }
299
274
 
300
- function isSidebarGroup(item: SidebarItem): item is SidebarManualGroup {
275
+ function isSidebarGroup(item: SidebarItem): item is SidebarGroup {
301
276
  return typeof item === 'object' && 'items' in item
302
277
  }
303
278
 
279
+ function isObsidianSidebarEntriesPlaceholder(
280
+ item: SidebarItem,
281
+ placeholder: SidebarAutoEntries,
282
+ ): item is SidebarAutoEntries {
283
+ return (
284
+ typeof item === 'object' &&
285
+ 'autogenerate' in item &&
286
+ item.autogenerate.directory === placeholder.autogenerate.directory
287
+ )
288
+ }
289
+
304
290
  interface OutputPaths {
305
291
  asset: string
306
292
  content: string
307
293
  file: string
308
294
  }
309
295
 
310
- interface SidebarManualGroup {
311
- items: SidebarManualGroup[]
312
- label: string
313
- }
314
-
315
296
  type SidebarItem = NonNullable<StarlightUserConfig['sidebar']>[number]
316
- export type SidebarGroup = Exclude<SidebarItem, string>
297
+ type SidebarGroup = Extract<SidebarItem, { items: unknown[] }>
298
+ export type SidebarAutoEntries = Extract<SidebarItem, { autogenerate: unknown }>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-obsidian",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to publish Obsidian vaults.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -48,7 +48,7 @@
48
48
  "vitest": "^4.0.18"
49
49
  },
50
50
  "peerDependencies": {
51
- "@astrojs/starlight": ">=0.34.0"
51
+ "@astrojs/starlight": ">=0.39.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.12.0"