Skip to content

Commit 812aa3b

Browse files
authored
feat(meta): added new vitepress-plugin-meta package (#218)
1 parent 9e00abb commit 812aa3b

22 files changed

Lines changed: 810 additions & 165 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ To find out the integration name, there is a list of integrations below.
7272
- [Inline Link Previewing (for VitePress)](./packages/vitepress-plugin-inline-link-preview/README.md)
7373
- [Blinking highlight targeted heading (for VitePress)](./packages/vitepress-plugin-highlight-targeted-heading/README.md)
7474
- [Page properties (for VitePress)](./packages/vitepress-plugin-page-properties/README.md)
75+
- [Page `<meta>` metadata generation](./packages/vitepress-plugin-meta/README.md)
7576
- [Previewing image (social media card) generation (for VitePress)](./packages/vitepress-plugin-og-image/README.md)
7677
- [Enhanced `<mark>` element (for VitePress)](./packages/vitepress-plugin-enhanced-mark/README.md)
7778
- [Thumbnail hashing for images (for VitePress)](./packages/vitepress-plugin-thumbnail-hash/README.md)

README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ni @nolebase/<integration-name> -D
7373
- [闪烁高亮当前的目标标题(VitePress 插件)](./packages/vitepress-plugin-highlight-targeted-heading/README.md)
7474
- [页面属性(VitePress 插件)](./packages/vitepress-plugin-page-properties/README.md)
7575
- [预览图片(社交媒体卡片)生成(VitePress 插件)](./packages/vitepress-plugin-og-image/README.md)
76+
- [页面 `<meta>` 元信息生成](./packages/vitepress-plugin-meta/README.md)
7677
- [`<mark>` 元素增强(VitePress 插件)](./packages/vitepress-plugin-enhanced-mark/README.md)
7778
- [缩略图模糊哈希生成(VitePress 插件)](./packages/vitepress-plugin-thumbnail-hash/README.md)
7879

cspell.config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ words:
2121
- composables
2222
- contributor
2323
- datetime
24+
- defu
2425
- easytag
2526
- ElMassimo
2627
- emittypes
@@ -45,9 +46,11 @@ words:
4546
- quotepath
4647
- Rehype
4748
- resvg
49+
- retext
4850
- rizumu
4951
- Roboto
5052
- shikijs
53+
- testdata
5154
- thumbhash
5255
- thumbhashes
5356
- Twoslash

docs/.vitepress/config.ts

Lines changed: 62 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cwd, env } from 'node:process'
1+
import { argv, cwd, env } from 'node:process'
22

33
import { gray } from 'colorette'
44
import { type DefaultTheme, defineConfig } from 'vitepress'
@@ -10,8 +10,14 @@ import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links'
1010
import { InlineLinkPreviewElementTransform } from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
1111
import { buildEndGenerateOpenGraphImages } from '@nolebase/vitepress-plugin-og-image/vitepress'
1212
import { UnlazyImages } from '@nolebase/markdown-it-unlazy-img'
13+
import { transformHeadMeta } from '@nolebase/vitepress-plugin-meta/vitepress'
1314

1415
import 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

1622
export 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',

docs/.vitepress/twoslashConfig.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { cwd } from 'node:process'
2+
3+
export const compilerOptions = {
4+
cache: true,
5+
compilerOptions: {
6+
baseUrl: cwd(),
7+
target: 99,
8+
module: 99,
9+
moduleResolution: 100,
10+
paths: {
11+
'@nolebase/ui': [
12+
'../packages/ui/src/index.ts',
13+
],
14+
'@nolebase/unconfig-vitepress/*': [
15+
'../packages/unconfig-vitepress/src/*',
16+
],
17+
'@nolebase/vitepress-plugin-enhanced-readabilities/*': [
18+
'../packages/vitepress-plugin-enhanced-readabilities/src/*',
19+
],
20+
'@nolebase/vitepress-plugin-highlight-targeted-heading/*': [
21+
'../packages/vitepress-plugin-highlight-targeted-heading/src/*',
22+
],
23+
'@nolebase/vitepress-plugin-inline-link-preview/*': [
24+
'../packages/vitepress-plugin-inline-link-preview/src/*',
25+
],
26+
'@nolebase/vitepress-plugin-git-changelog/*': [
27+
'../packages/vitepress-plugin-git-changelog/src/*',
28+
],
29+
'@nolebase/vitepress-plugin-page-properties/*': [
30+
'../packages/vitepress-plugin-page-properties/src/*',
31+
],
32+
'@nolebase/vitepress-plugin-thumbnail-hash/*': [
33+
'../packages/vitepress-plugin-thumbnail-hash/src/*',
34+
],
35+
},
36+
resolveJsonModule: true,
37+
types: [
38+
'node',
39+
'vite/client',
40+
],
41+
esModuleInterop: true,
42+
isolatedModules: true,
43+
verbatimModuleSyntax: true,
44+
skipLibCheck: true,
45+
skipDefaultLibCheck: true,
46+
},
47+
}

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@nolebase/vitepress-plugin-graph-view": "workspace:^",
2828
"@nolebase/vitepress-plugin-highlight-targeted-heading": "workspace:^",
2929
"@nolebase/vitepress-plugin-inline-link-preview": "workspace:^",
30+
"@nolebase/vitepress-plugin-meta": "workspace:^",
3031
"@nolebase/vitepress-plugin-og-image": "workspace:^",
3132
"@nolebase/vitepress-plugin-page-properties": "workspace:^",
3233
"@nolebase/vitepress-plugin-thumbnail-hash": "workspace:^",

0 commit comments

Comments
 (0)