starlight-obsidian 0.4.9 → 0.6.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 +11 -0
- package/index.ts +25 -6
- package/libs/obsidian.ts +2 -2
- package/libs/plugin.ts +3 -2
- package/libs/rehype.ts +1 -1
- package/libs/remark.ts +18 -10
- package/libs/starlight.ts +3 -2
- package/overrides/PageTitle.astro +1 -0
- package/package.json +41 -41
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# starlight-obsidian
|
|
2
|
+
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#34](https://github.com/HiDeoo/starlight-obsidian/pull/34) [`9079b9b`](https://github.com/HiDeoo/starlight-obsidian/commit/9079b9be67eb2efd68a3d8906068263657629974) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for Astro v5, drops support for Astro v4.
|
|
8
|
+
|
|
9
|
+
⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.30.0`.
|
|
10
|
+
|
|
11
|
+
Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs/starlight%400.30.0) to update your project.
|
package/index.ts
CHANGED
|
@@ -22,16 +22,24 @@ const starlightObsidianConfigSchema = z.object({
|
|
|
22
22
|
*/
|
|
23
23
|
configFolder: z.string().startsWith('.').default('.obsidian'),
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Defines which frontmatter fields the Starlight Obsidian plugin should copy from Obsidian notes to the generated
|
|
26
|
+
* pages.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* By default (`none`), all unsupported properties are ignored and not exported. Set this option to `starlight` to
|
|
29
|
+
* copy all known Starlight frontmatter fields from an Obsidian note to the associated generated page or to `all` to
|
|
30
|
+
* copy all frontmatter fields.
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
+
* This option is useful if you want to customize the generated Starlight pages from Obsidian. Note that the values
|
|
33
|
+
* are not validated and are copied as-is so it's up to you to ensure they are compatible with Starlight.
|
|
34
|
+
*
|
|
35
|
+
* @default 'none'
|
|
32
36
|
* @see https://starlight.astro.build/reference/frontmatter/
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
copyFrontmatter: z.union([z.literal('none'), z.literal('starlight'), z.literal('all')]).default('none'),
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use the {@link StarlightObsidianUserConfig.copyFrontmatter} option instead.
|
|
41
|
+
*/
|
|
42
|
+
copyStarlightFrontmatter: z.never().optional(),
|
|
35
43
|
/**
|
|
36
44
|
* A list of glob patterns to ignore when generating the Obsidian vault pages.
|
|
37
45
|
* This option can be used to ignore files or folders.
|
|
@@ -102,6 +110,17 @@ export default function starlightObsidianPlugin(userConfig: StarlightObsidianUse
|
|
|
102
110
|
const parsedConfig = starlightObsidianConfigSchema.safeParse(userConfig)
|
|
103
111
|
|
|
104
112
|
if (!parsedConfig.success) {
|
|
113
|
+
const isUsingDeprecatedCopyStarlightFrontmatter = parsedConfig.error.issues.some(
|
|
114
|
+
(issue) => issue.path.join('.') === 'copyStarlightFrontmatter',
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
if (isUsingDeprecatedCopyStarlightFrontmatter) {
|
|
118
|
+
throwUserError(
|
|
119
|
+
'The `copyStarlightFrontmatter` option has been deprecated in favor of the `copyFrontmatter` option.',
|
|
120
|
+
'For more information see https://starlight-obsidian.vercel.app/configuration/#copyfrontmatter',
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
105
124
|
throwUserError(
|
|
106
125
|
`The provided plugin configuration is invalid.\n${parsedConfig.error.issues.map((issue) => issue.message).join('\n')}`,
|
|
107
126
|
)
|
package/libs/obsidian.ts
CHANGED
|
@@ -224,8 +224,8 @@ interface BaseVaultFile {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
export interface VaultFile extends BaseVaultFile {
|
|
227
|
-
isEqualFileName(otherFileName: string)
|
|
228
|
-
isEqualStem(otherStem: string)
|
|
227
|
+
isEqualFileName: (otherFileName: string) => boolean
|
|
228
|
+
isEqualStem: (otherStem: string) => boolean
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
export type ObsidianFrontmatter = z.output<typeof obsidianFrontmatterSchema> & {
|
package/libs/plugin.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AstroError } from 'astro/errors'
|
|
2
2
|
|
|
3
|
-
export function throwUserError(message: string): never {
|
|
3
|
+
export function throwUserError(message: string, hint?: string): never {
|
|
4
4
|
throw new AstroError(
|
|
5
5
|
message,
|
|
6
|
-
|
|
6
|
+
hint ??
|
|
7
|
+
`See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-obsidian/issues/new/choose`,
|
|
7
8
|
)
|
|
8
9
|
}
|
package/libs/rehype.ts
CHANGED
|
@@ -82,7 +82,7 @@ function isNodeWithValue(node: ElementContent | undefined): node is NodeWithValu
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
function getBlockIdentifer(node: NodeWithValue): { length: number; name: string } | undefined {
|
|
85
|
-
const match = node.value
|
|
85
|
+
const match = blockIdentifierRegex.exec(node.value)
|
|
86
86
|
const identifier = match?.groups?.['identifier']
|
|
87
87
|
const name = match?.groups?.['name']
|
|
88
88
|
|
package/libs/remark.ts
CHANGED
|
@@ -377,7 +377,7 @@ function handleBlockquotes(node: Blockquote, context: VisitorContext) {
|
|
|
377
377
|
return SKIP
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
const match =
|
|
380
|
+
const match = calloutRegex.exec(firstLine)
|
|
381
381
|
|
|
382
382
|
const { title, type } = match?.groups ?? {}
|
|
383
383
|
|
|
@@ -453,9 +453,14 @@ function getFrontmatterNodeValue(file: VFile, obsidianFrontmatter?: ObsidianFron
|
|
|
453
453
|
editUrl: false,
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
if (obsidianFrontmatter && file.data.
|
|
457
|
-
|
|
458
|
-
|
|
456
|
+
if (obsidianFrontmatter && (file.data.copyFrontmatter === 'starlight' || file.data.copyFrontmatter === 'all')) {
|
|
457
|
+
if (file.data.copyFrontmatter === 'starlight') {
|
|
458
|
+
const starlightLikeFrontmatter = getStarlightLikeFrontmatter(obsidianFrontmatter.raw)
|
|
459
|
+
frontmatter = { ...frontmatter, ...starlightLikeFrontmatter }
|
|
460
|
+
} else {
|
|
461
|
+
const { cover, image, description, permalink, tags, ...restFrontmatter } = obsidianFrontmatter.raw
|
|
462
|
+
frontmatter = { ...frontmatter, ...restFrontmatter }
|
|
463
|
+
}
|
|
459
464
|
}
|
|
460
465
|
|
|
461
466
|
if (file.data.includeKatexStyles) {
|
|
@@ -479,10 +484,13 @@ function getFrontmatterNodeValue(file: VFile, obsidianFrontmatter?: ObsidianFron
|
|
|
479
484
|
frontmatter.head = []
|
|
480
485
|
}
|
|
481
486
|
|
|
482
|
-
frontmatter.head.
|
|
483
|
-
{ tag: 'meta', attrs: { property: 'og:image', content: ogImage } }
|
|
484
|
-
|
|
485
|
-
|
|
487
|
+
if (!frontmatter.head.some((tag) => tag.attrs['property'] === 'og:image')) {
|
|
488
|
+
frontmatter.head.push({ tag: 'meta', attrs: { property: 'og:image', content: ogImage } })
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (!frontmatter.head.some((tag) => tag.attrs['property'] === 'twitter:image')) {
|
|
492
|
+
frontmatter.head.push({ tag: 'meta', attrs: { name: 'twitter:image', content: ogImage } })
|
|
493
|
+
}
|
|
486
494
|
}
|
|
487
495
|
|
|
488
496
|
if (obsidianFrontmatter?.description && obsidianFrontmatter.description.length > 0) {
|
|
@@ -558,7 +566,7 @@ function handleImagesWithSize(node: Image, context: VisitorContext, type: 'asset
|
|
|
558
566
|
return
|
|
559
567
|
}
|
|
560
568
|
|
|
561
|
-
const match = node.alt
|
|
569
|
+
const match = imageSizeRegex.exec(node.alt)
|
|
562
570
|
const { altText, width, widthOnly, height } = match?.groups ?? {}
|
|
563
571
|
|
|
564
572
|
if (widthOnly === undefined && width === undefined) {
|
|
@@ -674,7 +682,7 @@ function ensureTransformContext(file: VFile): asserts file is VFile & { data: Tr
|
|
|
674
682
|
export interface TransformContext {
|
|
675
683
|
aliases?: string[]
|
|
676
684
|
assetImports?: [id: string, path: string][]
|
|
677
|
-
|
|
685
|
+
copyFrontmatter: StarlightObsidianConfig['copyFrontmatter']
|
|
678
686
|
embedded?: boolean
|
|
679
687
|
files: VaultFile[]
|
|
680
688
|
includeKatexStyles?: boolean
|
package/libs/starlight.ts
CHANGED
|
@@ -62,6 +62,7 @@ const starlightFrontmatterKeys = [
|
|
|
62
62
|
'prev',
|
|
63
63
|
'next',
|
|
64
64
|
'pagefind',
|
|
65
|
+
'draft',
|
|
65
66
|
'sidebar',
|
|
66
67
|
]
|
|
67
68
|
|
|
@@ -181,7 +182,7 @@ async function addContent(
|
|
|
181
182
|
type,
|
|
182
183
|
} = await transformMarkdownToString(vaultFile.fsPath, obsidianContent, {
|
|
183
184
|
files: vaultFiles,
|
|
184
|
-
|
|
185
|
+
copyFrontmatter: config.copyFrontmatter,
|
|
185
186
|
output: config.output,
|
|
186
187
|
vault,
|
|
187
188
|
})
|
|
@@ -279,7 +280,7 @@ function throwVaultFileError(error: unknown, vaultFile: VaultFile): never {
|
|
|
279
280
|
}
|
|
280
281
|
|
|
281
282
|
function isSidebarGroup(item: SidebarGroup): item is SidebarManualGroup {
|
|
282
|
-
return 'items' in item
|
|
283
|
+
return typeof item === 'object' && 'items' in item
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
interface OutputPaths {
|
|
@@ -6,6 +6,7 @@ import Tags from '../components/Tags.astro'
|
|
|
6
6
|
|
|
7
7
|
const { entry } = Astro.props
|
|
8
8
|
|
|
9
|
+
// @ts-expect-error - This plugin does not extend Starlight's schema so tags are unknown.
|
|
9
10
|
const tags = entry['data']['tags']
|
|
10
11
|
const showTags = tags !== undefined && tags.length > 0
|
|
11
12
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-obsidian",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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,53 +17,52 @@
|
|
|
17
17
|
"./package.json": "./package.json"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@astro-community/astro-embed-twitter": "0.5.
|
|
21
|
-
"@astro-community/astro-embed-youtube": "0.
|
|
22
|
-
"@astrojs/markdown-remark": "
|
|
23
|
-
"decode-uri-component": "0.4.1",
|
|
24
|
-
"github-slugger": "2.0.0",
|
|
25
|
-
"globby": "14.0.
|
|
26
|
-
"hast-util-to-html": "9.0.
|
|
27
|
-
"hast-util-to-string": "3.0.
|
|
28
|
-
"hastscript": "9.0.0",
|
|
29
|
-
"html-escaper": "3.0.3",
|
|
30
|
-
"is-absolute-url": "4.0.1",
|
|
31
|
-
"mdast-util-find-and-replace": "3.0.1",
|
|
32
|
-
"mdast-util-from-markdown": "2.0.
|
|
33
|
-
"mdast-util-to-hast": "13.
|
|
34
|
-
"nanoid": "5.0.
|
|
35
|
-
"rehype": "13.0.
|
|
36
|
-
"rehype-autolink-headings": "7.1.0",
|
|
37
|
-
"rehype-katex": "7.0.
|
|
38
|
-
"rehype-mermaid": "2.1.0",
|
|
39
|
-
"remark": "15.0.1",
|
|
40
|
-
"remark-frontmatter": "5.0.0",
|
|
41
|
-
"remark-gfm": "4.0.0",
|
|
42
|
-
"remark-math": "6.0.0",
|
|
43
|
-
"unist-util-visit": "5.0.0",
|
|
44
|
-
"vfile": "6.0.
|
|
45
|
-
"yaml": "2.
|
|
20
|
+
"@astro-community/astro-embed-twitter": "^0.5.8",
|
|
21
|
+
"@astro-community/astro-embed-youtube": "^0.5.6",
|
|
22
|
+
"@astrojs/markdown-remark": "^6.0.0",
|
|
23
|
+
"decode-uri-component": "^0.4.1",
|
|
24
|
+
"github-slugger": "^2.0.0",
|
|
25
|
+
"globby": "^14.0.2",
|
|
26
|
+
"hast-util-to-html": "^9.0.4",
|
|
27
|
+
"hast-util-to-string": "^3.0.1",
|
|
28
|
+
"hastscript": "^9.0.0",
|
|
29
|
+
"html-escaper": "^3.0.3",
|
|
30
|
+
"is-absolute-url": "^4.0.1",
|
|
31
|
+
"mdast-util-find-and-replace": "^3.0.1",
|
|
32
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
33
|
+
"mdast-util-to-hast": "^13.2.0",
|
|
34
|
+
"nanoid": "^5.0.9",
|
|
35
|
+
"rehype": "^13.0.2",
|
|
36
|
+
"rehype-autolink-headings": "^7.1.0",
|
|
37
|
+
"rehype-katex": "^7.0.1",
|
|
38
|
+
"rehype-mermaid": "^2.1.0",
|
|
39
|
+
"remark": "^15.0.1",
|
|
40
|
+
"remark-frontmatter": "^5.0.0",
|
|
41
|
+
"remark-gfm": "^4.0.0",
|
|
42
|
+
"remark-math": "^6.0.0",
|
|
43
|
+
"unist-util-visit": "^5.0.0",
|
|
44
|
+
"vfile": "^6.0.3",
|
|
45
|
+
"yaml": "^2.6.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/
|
|
51
|
-
"@types/
|
|
52
|
-
"@types/unist": "3.0.
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"vitest": "1.2.1"
|
|
48
|
+
"@types/hast": "^3.0.4",
|
|
49
|
+
"@types/html-escaper": "^3.0.2",
|
|
50
|
+
"@types/mdast": "^4.0.4",
|
|
51
|
+
"@types/node": "^18.19.68",
|
|
52
|
+
"@types/unist": "^3.0.3",
|
|
53
|
+
"typescript": "^5.7.2",
|
|
54
|
+
"vitest": "2.1.6"
|
|
56
55
|
},
|
|
57
56
|
"peerDependencies": {
|
|
58
|
-
"@astrojs/starlight": ">=0.
|
|
59
|
-
"astro": ">=4.0.0"
|
|
57
|
+
"@astrojs/starlight": ">=0.30.0"
|
|
60
58
|
},
|
|
61
59
|
"engines": {
|
|
62
|
-
"node": ">=18.
|
|
60
|
+
"node": ">=18.17.1"
|
|
63
61
|
},
|
|
64
62
|
"packageManager": "pnpm@8.14.1",
|
|
65
63
|
"publishConfig": {
|
|
66
|
-
"access": "public"
|
|
64
|
+
"access": "public",
|
|
65
|
+
"provenance": true
|
|
67
66
|
},
|
|
68
67
|
"sideEffects": false,
|
|
69
68
|
"keywords": [
|
|
@@ -77,11 +76,12 @@
|
|
|
77
76
|
"homepage": "https://github.com/HiDeoo/starlight-obsidian",
|
|
78
77
|
"repository": {
|
|
79
78
|
"type": "git",
|
|
80
|
-
"url": "https://github.com/HiDeoo/starlight-obsidian.git"
|
|
79
|
+
"url": "https://github.com/HiDeoo/starlight-obsidian.git",
|
|
80
|
+
"directory": "packages/starlight-obsidian"
|
|
81
81
|
},
|
|
82
82
|
"bugs": "https://github.com/HiDeoo/starlight-obsidian/issues",
|
|
83
83
|
"scripts": {
|
|
84
84
|
"test": "vitest",
|
|
85
|
-
"lint": "
|
|
85
|
+
"lint": "eslint . --cache --max-warnings=0"
|
|
86
86
|
}
|
|
87
87
|
}
|