starlight-obsidian 0.4.9 → 0.5.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/index.ts +25 -6
- package/libs/plugin.ts +3 -2
- package/libs/remark.ts +16 -8
- package/libs/starlight.ts +2 -1
- package/package.json +1 -1
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/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/remark.ts
CHANGED
|
@@ -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) {
|
|
@@ -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
|
})
|