starlight-obsidian 0.10.1 → 0.12.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,23 @@
1
1
  # starlight-obsidian
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#70](https://github.com/HiDeoo/starlight-obsidian/pull/70) [`877dbb6`](https://github.com/HiDeoo/starlight-obsidian/commit/877dbb65ac7beff9e3110db1ac1ba5ec936de342) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for Astro v6, drops support for Astro v5.
8
+
9
+ ⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.38.0`.
10
+
11
+ Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs%2Fstarlight%400.38.0) to update your project.
12
+
13
+ ## 0.11.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [#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.
18
+
19
+ - [#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.
20
+
3
21
  ## 0.10.1
4
22
 
5
23
  ### Patch 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
 
@@ -58,14 +59,25 @@ const starlightObsidianConfigSchema = z.object({
58
59
  */
59
60
  singleDollarTextMath: z.boolean().default(true),
60
61
  })
61
- .default({}),
62
+ .prefault({}),
62
63
  /**
63
64
  * The name of the output directory containing the generated Obsidian vault pages relative to the `src/content/docs/`
64
65
  * directory.
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,11 +107,14 @@ 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(), z.string())]).default('Notes'),
101
116
  })
102
- .default({}),
117
+ .prefault({}),
103
118
  /**
104
119
  * Determines if the table of contents top-level heading should be the Starlight default one ("Overview") or the page
105
120
  * title.
@@ -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/rehype.ts CHANGED
@@ -15,8 +15,7 @@ export function rehypeStarlightObsidian() {
15
15
  const lastChild = node.children.at(-1)
16
16
 
17
17
  if (
18
- !lastChild ||
19
- lastChild.type !== 'element' ||
18
+ lastChild?.type !== 'element' ||
20
19
  !(lastChild.tagName === 'p' || lastChild.tagName === 'ul' || lastChild.tagName === 'ol')
21
20
  ) {
22
21
  return CONTINUE
package/libs/remark.ts CHANGED
@@ -509,9 +509,7 @@ function getFrontmatterNodeValue(file: VFile, obsidianFrontmatter?: ObsidianFron
509
509
  }
510
510
 
511
511
  if (file.data.includeKatexStyles) {
512
- if (!frontmatter.head) {
513
- frontmatter.head = []
514
- }
512
+ frontmatter.head ??= []
515
513
 
516
514
  frontmatter.head.push({
517
515
  tag: 'link',
@@ -525,9 +523,7 @@ function getFrontmatterNodeValue(file: VFile, obsidianFrontmatter?: ObsidianFron
525
523
  const ogImage = obsidianFrontmatter?.cover ?? obsidianFrontmatter?.image
526
524
 
527
525
  if (ogImage && isAbsoluteUrl(ogImage)) {
528
- if (!frontmatter.head) {
529
- frontmatter.head = []
530
- }
526
+ frontmatter.head ??= []
531
527
 
532
528
  if (!frontmatter.head.some((tag) => tag.attrs['property'] === 'og:image')) {
533
529
  frontmatter.head.push({ tag: 'meta', attrs: { property: 'og:image', content: ogImage } })
@@ -632,9 +628,7 @@ function handleImagesWithSize(node: Image, context: VisitorContext, type: 'asset
632
628
  } else {
633
629
  const importId = generateAssetImportId()
634
630
 
635
- if (!context.file.data.assetImports) {
636
- context.file.data.assetImports = []
637
- }
631
+ context.file.data.assetImports ??= []
638
632
 
639
633
  context.file.data.assetImports.push([importId, node.url])
640
634
 
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.1",
3
+ "version": "0.12.0",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to publish Obsidian vaults.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -17,43 +17,42 @@
17
17
  "./package.json": "./package.json"
18
18
  },
19
19
  "dependencies": {
20
- "@astro-community/astro-embed-twitter": "^0.5.8",
21
- "@astro-community/astro-embed-youtube": "^0.5.6",
20
+ "@astro-community/astro-embed-twitter": "^0.5.11",
21
+ "@astro-community/astro-embed-youtube": "^0.5.10",
22
22
  "decode-uri-component": "^0.4.1",
23
23
  "github-slugger": "^2.0.0",
24
- "globby": "^14.0.2",
25
- "hast-util-to-html": "^9.0.4",
26
- "is-absolute-url": "^4.0.1",
27
- "mdast-util-find-and-replace": "^3.0.1",
28
- "mdast-util-from-markdown": "^2.0.2",
29
- "mdast-util-to-hast": "^13.2.0",
30
- "nanoid": "^5.0.9",
24
+ "globby": "^16.1.1",
25
+ "hast-util-to-html": "^9.0.5",
26
+ "is-absolute-url": "^5.0.0",
27
+ "mdast-util-find-and-replace": "^3.0.2",
28
+ "mdast-util-from-markdown": "^2.0.3",
29
+ "mdast-util-to-hast": "^13.2.1",
30
+ "nanoid": "^5.1.6",
31
31
  "rehype": "^13.0.2",
32
32
  "rehype-katex": "^7.0.1",
33
33
  "rehype-mermaid": "^2.1.0",
34
34
  "remark": "^15.0.1",
35
35
  "remark-frontmatter": "^5.0.0",
36
- "remark-gfm": "^4.0.0",
36
+ "remark-gfm": "^4.0.1",
37
37
  "remark-math": "^6.0.0",
38
- "unist-util-visit": "^5.0.0",
38
+ "unist-util-visit": "^5.1.0",
39
39
  "vfile": "^6.0.3",
40
- "yaml": "^2.6.1"
40
+ "yaml": "^2.8.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/hast": "^3.0.4",
44
44
  "@types/mdast": "^4.0.4",
45
- "@types/node": "^18.19.68",
45
+ "@types/node": "^22.19.15",
46
46
  "@types/unist": "^3.0.3",
47
- "typescript": "^5.7.2",
48
- "vitest": "2.1.6"
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.0.18"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@astrojs/starlight": ">=0.34.0"
52
52
  },
53
53
  "engines": {
54
- "node": ">=18.17.1"
54
+ "node": ">=22.12.0"
55
55
  },
56
- "packageManager": "pnpm@8.14.1",
57
56
  "publishConfig": {
58
57
  "access": "public"
59
58
  },