1- import { cwd , env } from 'node:process'
1+ import { argv , cwd , env } from 'node:process'
22
33import { gray } from 'colorette'
44import { type DefaultTheme , defineConfig } from 'vitepress'
@@ -10,8 +10,14 @@ import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links'
1010import { InlineLinkPreviewElementTransform } from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
1111import { buildEndGenerateOpenGraphImages } from '@nolebase/vitepress-plugin-og-image/vitepress'
1212import { UnlazyImages } from '@nolebase/markdown-it-unlazy-img'
13+ import { transformHeadMeta } from '@nolebase/vitepress-plugin-meta/vitepress'
1314
1415import packageJSON from '../../package.json'
16+ import { compilerOptions } from './twoslashConfig'
17+
18+ function noTwoslash ( ) {
19+ return argv . some ( v => v . includes ( 'vitepress' ) ) && argv . includes ( 'dev' )
20+ }
1521
1622export const sidebars : Record < string , DefaultTheme . Sidebar > = {
1723 'en' : {
@@ -22,61 +28,6 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
2228 { text : 'Getting Started' , link : '/pages/en/guide/getting-started' } ,
2329 ] ,
2430 } ,
25- {
26- text : 'Integrations' ,
27- items : [
28- { text : 'Overview' , link : '/pages/en/integrations/' } ,
29- {
30- text : 'Markdown-it plugins' ,
31- items : [
32- { text : 'Bi-directional links' , link : '/pages/en/integrations/markdown-it-bi-directional-links/' } ,
33- { text : 'Element Transformation' , link : '/pages/en/integrations/markdown-it-element-transform/' } ,
34- { text : 'Lazy loading blurred thumbnails' , link : '/pages/en/integrations/markdown-it-unlazy-img/' } ,
35- ] ,
36- } ,
37- {
38- text : 'VitePress plugins' ,
39- items : [
40- { text : 'Enhanced Readabilities' , link : '/pages/en/integrations/vitepress-plugin-enhanced-readabilities/' } ,
41- { text : 'Inline Links Previewing' , link : '/pages/en/integrations/vitepress-plugin-inline-link-preview/' } ,
42- { text : 'Blinking highlight targeted heading' , link : '/pages/en/integrations/vitepress-plugin-highlight-targeted-heading/' } ,
43- { text : 'Git-based page histories' , link : '/pages/en/integrations/vitepress-plugin-git-changelog/' } ,
44- { text : 'Page properties' , link : '/pages/en/integrations/vitepress-plugin-page-properties/' } ,
45- { text : 'Previewing image (social media card) generation' , link : '/pages/en/integrations/vitepress-plugin-og-image/' } ,
46- { text : 'Enhanced mark elements' , link : '/pages/en/integrations/vitepress-plugin-enhanced-mark/' } ,
47- { text : 'Thumbnail hashing for images' , link : '/pages/en/integrations/vitepress-plugin-thumbnail-hash/' } ,
48- ] ,
49- } ,
50- {
51- text : 'Obsidian plugins' ,
52- items : [
53- { text : 'UnoCSS' , link : '/pages/en/integrations/obsidian-plugin-unocss/' } ,
54- ] ,
55- } ,
56- ] ,
57- } ,
58- {
59- text : 'UI Components' ,
60- items : [
61- { text : 'Overview' , link : '/pages/en/ui/' } ,
62- ] ,
63- } ,
64- {
65- text : 'Releasing' ,
66- items : [
67- {
68- text : 'Migration guides' ,
69- items : [
70- {
71- text : 'Migrate from v1 to v2' ,
72- link : '/pages/en/releases/migrations/v1-to-v2' ,
73- } ,
74- ] ,
75- } ,
76- ] ,
77- } ,
78- ] ,
79- '/pages/en/integrations/' : [
8031 {
8132 text : 'Integrations' ,
8233 items : [
@@ -124,6 +75,7 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
12475 ] ,
12576 } ,
12677 { text : 'Page properties' , link : '/pages/en/integrations/vitepress-plugin-page-properties/' } ,
78+ { text : 'Page metadata generation' , link : '/pages/en/integrations/vitepress-plugin-meta/' } ,
12779 { text : 'Previewing image (social media card) generation' , link : '/pages/en/integrations/vitepress-plugin-og-image/' } ,
12880 { text : 'Enhanced mark elements' , link : '/pages/en/integrations/vitepress-plugin-enhanced-mark/' } ,
12981 {
@@ -142,6 +94,26 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
14294 { text : 'UnoCSS' , link : '/pages/en/integrations/obsidian-plugin-unocss/' } ,
14395 ] ,
14496 } ,
97+ {
98+ text : 'UI Components' ,
99+ items : [
100+ { text : 'Overview' , link : '/pages/en/ui/' } ,
101+ ] ,
102+ } ,
103+ {
104+ text : 'Releasing' ,
105+ items : [
106+ {
107+ text : 'Migration guides' ,
108+ items : [
109+ {
110+ text : 'Migrate from v1 to v2' ,
111+ link : '/pages/en/releases/migrations/v1-to-v2' ,
112+ } ,
113+ ] ,
114+ } ,
115+ ] ,
116+ } ,
145117 ] ,
146118 '/pages/en/ui/' : [
147119 {
@@ -180,61 +152,6 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
180152 { text : '如何开始' , link : '/pages/zh-CN/guide/getting-started' } ,
181153 ] ,
182154 } ,
183- {
184- text : '集成' ,
185- items : [
186- { text : '概览' , link : '/pages/zh-CN/integrations/' } ,
187- {
188- text : 'Markdown It 插件' ,
189- items : [
190- { text : '双向链接' , link : '/pages/zh-CN/integrations/markdown-it-bi-directional-links/' } ,
191- { text : '元素转换' , link : '/pages/zh-CN/integrations/markdown-it-element-transform/' } ,
192- { text : '懒加载模糊缩略图' , link : '/pages/zh-CN/integrations/markdown-it-unlazy-img/' } ,
193- ] ,
194- } ,
195- {
196- text : 'VitePress 插件' ,
197- items : [
198- { text : '阅读增强' , link : '/pages/zh-CN/integrations/vitepress-plugin-enhanced-readabilities/' } ,
199- { text : '行内链接预览' , link : '/pages/zh-CN/integrations/vitepress-plugin-inline-link-preview/' } ,
200- { text : '闪烁高亮当前的目标标题' , link : '/pages/zh-CN/integrations/vitepress-plugin-highlight-targeted-heading/' } ,
201- { text : '基于 Git 的页面历史' , link : '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/' } ,
202- { text : '页面属性' , link : '/pages/zh-CN/integrations/vitepress-plugin-page-properties/' } ,
203- { text : '预览图片(社交媒体卡片)生成' , link : '/pages/zh-CN/integrations/vitepress-plugin-og-image/' } ,
204- { text : 'mark 元素增强' , link : '/pages/zh-CN/integrations/vitepress-plugin-enhanced-mark/' } ,
205- { text : '缩略图模糊哈希生成' , link : '/pages/zh-CN/integrations/vitepress-plugin-thumbnail-hash/' } ,
206- ] ,
207- } ,
208- {
209- text : 'Obsidian 插件' ,
210- items : [
211- { text : 'UnoCSS' , link : '/pages/zh-CN/integrations/obsidian-plugin-unocss/' } ,
212- ] ,
213- } ,
214- ] ,
215- } ,
216- {
217- text : 'UI 组件' ,
218- items : [
219- { text : '概览' , link : '/pages/zh-CN/ui/' } ,
220- ] ,
221- } ,
222- {
223- text : '版本发布' ,
224- items : [
225- {
226- text : '迁移指南' ,
227- items : [
228- {
229- text : '自 v1 迁移至 v2' ,
230- link : '/pages/zh-CN/releases/migrations/v1-to-v2' ,
231- } ,
232- ] ,
233- } ,
234- ] ,
235- } ,
236- ] ,
237- '/pages/zh-CN/integrations/' : [
238155 {
239156 text : '集成' ,
240157 items : [
@@ -282,6 +199,7 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
282199 ] ,
283200 } ,
284201 { text : '页面属性' , link : '/pages/zh-CN/integrations/vitepress-plugin-page-properties/' } ,
202+ { text : '页面元信息生成' , link : '/pages/zh-CN/integrations/vitepress-plugin-meta/' } ,
285203 { text : '预览图片(社交媒体卡片)生成' , link : '/pages/zh-CN/integrations/vitepress-plugin-og-image/' } ,
286204 { text : 'mark 元素增强' , link : '/pages/zh-CN/integrations/vitepress-plugin-enhanced-mark/' } ,
287205 {
@@ -300,6 +218,20 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
300218 { text : 'UnoCSS' , link : '/pages/zh-CN/integrations/obsidian-plugin-unocss/' } ,
301219 ] ,
302220 } ,
221+ {
222+ text : '版本发布' ,
223+ items : [
224+ {
225+ text : '迁移指南' ,
226+ items : [
227+ {
228+ text : '自 v1 迁移至 v2' ,
229+ link : '/pages/zh-CN/releases/migrations/v1-to-v2' ,
230+ } ,
231+ ] ,
232+ } ,
233+ ] ,
234+ } ,
303235 ] ,
304236 '/pages/zh-CN/ui/' : [
305237 {
@@ -466,59 +398,17 @@ export default defineConfig({
466398 } ,
467399 } ,
468400 markdown : {
469- codeTransformers : [
470- transformerTwoslash ( {
471- errorRendering : 'hover' ,
472- onTwoslashError ( error , _ , __ , ___ ) {
473- console . error ( 'Twoslash Error:' , ( error as Error ) ?. message , '\n' , ( error as Error ) ?. stack ? gray ( String ( ( error as Error ) ?. stack ) ) : '' )
474- } ,
475- twoslashOptions : {
476- cache : true ,
477- compilerOptions : {
478- baseUrl : cwd ( ) ,
479- target : 99 ,
480- module : 99 ,
481- moduleResolution : 100 ,
482- paths : {
483- '@nolebase/ui' : [
484- '../packages/ui/src/index.ts' ,
485- ] ,
486- '@nolebase/unconfig-vitepress/*' : [
487- '../packages/unconfig-vitepress/src/*' ,
488- ] ,
489- '@nolebase/vitepress-plugin-enhanced-readabilities/*' : [
490- '../packages/vitepress-plugin-enhanced-readabilities/src/*' ,
491- ] ,
492- '@nolebase/vitepress-plugin-highlight-targeted-heading/*' : [
493- '../packages/vitepress-plugin-highlight-targeted-heading/src/*' ,
494- ] ,
495- '@nolebase/vitepress-plugin-inline-link-preview/*' : [
496- '../packages/vitepress-plugin-inline-link-preview/src/*' ,
497- ] ,
498- '@nolebase/vitepress-plugin-git-changelog/*' : [
499- '../packages/vitepress-plugin-git-changelog/src/*' ,
500- ] ,
501- '@nolebase/vitepress-plugin-page-properties/*' : [
502- '../packages/vitepress-plugin-page-properties/src/*' ,
503- ] ,
504- '@nolebase/vitepress-plugin-thumbnail-hash/*' : [
505- '../packages/vitepress-plugin-thumbnail-hash/src/*' ,
506- ] ,
401+ codeTransformers : noTwoslash ( )
402+ ? [ ]
403+ : [
404+ transformerTwoslash ( {
405+ errorRendering : 'hover' ,
406+ onTwoslashError ( error , _ , __ , ___ ) {
407+ console . error ( 'Twoslash Error:' , ( error as Error ) ?. message , '\n' , ( error as Error ) ?. stack ? gray ( String ( ( error as Error ) ?. stack ) ) : '' )
507408 } ,
508- resolveJsonModule : true ,
509- types : [
510- 'node' ,
511- 'vite/client' ,
512- ] ,
513- esModuleInterop : true ,
514- isolatedModules : true ,
515- verbatimModuleSyntax : true ,
516- skipLibCheck : true ,
517- skipDefaultLibCheck : true ,
518- } ,
519- } ,
520- } ) ,
521- ] ,
409+ twoslashOptions : compilerOptions ,
410+ } ) ,
411+ ] ,
522412 preConfig ( md ) {
523413 md . use ( BiDirectionalLinks ( {
524414 dir : cwd ( ) ,
@@ -532,6 +422,15 @@ export default defineConfig({
532422 md . use ( InlineLinkPreviewElementTransform )
533423 } ,
534424 } ,
425+ async transformHead ( context ) {
426+ let head = [ ...context . head ]
427+
428+ const returnedHead = await transformHeadMeta ( ) ( head , context )
429+ if ( typeof returnedHead !== 'undefined' )
430+ head = returnedHead
431+
432+ return head
433+ } ,
535434 async buildEnd ( siteConfig ) {
536435 const newBuilder = buildEndGenerateOpenGraphImages ( {
537436 baseUrl : 'https://nolebase-integrations.ayaka.io' ,
0 commit comments