Skip to content

Commit

Permalink
feat(meta): added new vitepress-plugin-meta package (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww authored May 17, 2024
1 parent 9e00abb commit 812aa3b
Show file tree
Hide file tree
Showing 22 changed files with 810 additions and 165 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ To find out the integration name, there is a list of integrations below.
- [Inline Link Previewing (for VitePress)](./packages/vitepress-plugin-inline-link-preview/README.md)
- [Blinking highlight targeted heading (for VitePress)](./packages/vitepress-plugin-highlight-targeted-heading/README.md)
- [Page properties (for VitePress)](./packages/vitepress-plugin-page-properties/README.md)
- [Page `<meta>` metadata generation](./packages/vitepress-plugin-meta/README.md)
- [Previewing image (social media card) generation (for VitePress)](./packages/vitepress-plugin-og-image/README.md)
- [Enhanced `<mark>` element (for VitePress)](./packages/vitepress-plugin-enhanced-mark/README.md)
- [Thumbnail hashing for images (for VitePress)](./packages/vitepress-plugin-thumbnail-hash/README.md)
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ ni @nolebase/<integration-name> -D
- [闪烁高亮当前的目标标题(VitePress 插件)](./packages/vitepress-plugin-highlight-targeted-heading/README.md)
- [页面属性(VitePress 插件)](./packages/vitepress-plugin-page-properties/README.md)
- [预览图片(社交媒体卡片)生成(VitePress 插件)](./packages/vitepress-plugin-og-image/README.md)
- [页面 `<meta>` 元信息生成](./packages/vitepress-plugin-meta/README.md)
- [`<mark>` 元素增强(VitePress 插件)](./packages/vitepress-plugin-enhanced-mark/README.md)
- [缩略图模糊哈希生成(VitePress 插件)](./packages/vitepress-plugin-thumbnail-hash/README.md)

Expand Down
3 changes: 3 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ words:
- composables
- contributor
- datetime
- defu
- easytag
- ElMassimo
- emittypes
Expand All @@ -45,9 +46,11 @@ words:
- quotepath
- Rehype
- resvg
- retext
- rizumu
- Roboto
- shikijs
- testdata
- thumbhash
- thumbhashes
- Twoslash
Expand Down
225 changes: 62 additions & 163 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cwd, env } from 'node:process'
import { argv, cwd, env } from 'node:process'

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

import packageJSON from '../../package.json'
import { compilerOptions } from './twoslashConfig'

function noTwoslash() {
return argv.some(v => v.includes('vitepress')) && argv.includes('dev')
}

export const sidebars: Record<string, DefaultTheme.Sidebar> = {
'en': {
Expand All @@ -22,61 +28,6 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
{ text: 'Getting Started', link: '/pages/en/guide/getting-started' },
],
},
{
text: 'Integrations',
items: [
{ text: 'Overview', link: '/pages/en/integrations/' },
{
text: 'Markdown-it plugins',
items: [
{ text: 'Bi-directional links', link: '/pages/en/integrations/markdown-it-bi-directional-links/' },
{ text: 'Element Transformation', link: '/pages/en/integrations/markdown-it-element-transform/' },
{ text: 'Lazy loading blurred thumbnails', link: '/pages/en/integrations/markdown-it-unlazy-img/' },
],
},
{
text: 'VitePress plugins',
items: [
{ text: 'Enhanced Readabilities', link: '/pages/en/integrations/vitepress-plugin-enhanced-readabilities/' },
{ text: 'Inline Links Previewing', link: '/pages/en/integrations/vitepress-plugin-inline-link-preview/' },
{ text: 'Blinking highlight targeted heading', link: '/pages/en/integrations/vitepress-plugin-highlight-targeted-heading/' },
{ text: 'Git-based page histories', link: '/pages/en/integrations/vitepress-plugin-git-changelog/' },
{ text: 'Page properties', link: '/pages/en/integrations/vitepress-plugin-page-properties/' },
{ text: 'Previewing image (social media card) generation', link: '/pages/en/integrations/vitepress-plugin-og-image/' },
{ text: 'Enhanced mark elements', link: '/pages/en/integrations/vitepress-plugin-enhanced-mark/' },
{ text: 'Thumbnail hashing for images', link: '/pages/en/integrations/vitepress-plugin-thumbnail-hash/' },
],
},
{
text: 'Obsidian plugins',
items: [
{ text: 'UnoCSS', link: '/pages/en/integrations/obsidian-plugin-unocss/' },
],
},
],
},
{
text: 'UI Components',
items: [
{ text: 'Overview', link: '/pages/en/ui/' },
],
},
{
text: 'Releasing',
items: [
{
text: 'Migration guides',
items: [
{
text: 'Migrate from v1 to v2',
link: '/pages/en/releases/migrations/v1-to-v2',
},
],
},
],
},
],
'/pages/en/integrations/': [
{
text: 'Integrations',
items: [
Expand Down Expand Up @@ -124,6 +75,7 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
],
},
{ text: 'Page properties', link: '/pages/en/integrations/vitepress-plugin-page-properties/' },
{ text: 'Page metadata generation', link: '/pages/en/integrations/vitepress-plugin-meta/' },
{ text: 'Previewing image (social media card) generation', link: '/pages/en/integrations/vitepress-plugin-og-image/' },
{ text: 'Enhanced mark elements', link: '/pages/en/integrations/vitepress-plugin-enhanced-mark/' },
{
Expand All @@ -142,6 +94,26 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
{ text: 'UnoCSS', link: '/pages/en/integrations/obsidian-plugin-unocss/' },
],
},
{
text: 'UI Components',
items: [
{ text: 'Overview', link: '/pages/en/ui/' },
],
},
{
text: 'Releasing',
items: [
{
text: 'Migration guides',
items: [
{
text: 'Migrate from v1 to v2',
link: '/pages/en/releases/migrations/v1-to-v2',
},
],
},
],
},
],
'/pages/en/ui/': [
{
Expand Down Expand Up @@ -180,61 +152,6 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
{ text: '如何开始', link: '/pages/zh-CN/guide/getting-started' },
],
},
{
text: '集成',
items: [
{ text: '概览', link: '/pages/zh-CN/integrations/' },
{
text: 'Markdown It 插件',
items: [
{ text: '双向链接', link: '/pages/zh-CN/integrations/markdown-it-bi-directional-links/' },
{ text: '元素转换', link: '/pages/zh-CN/integrations/markdown-it-element-transform/' },
{ text: '懒加载模糊缩略图', link: '/pages/zh-CN/integrations/markdown-it-unlazy-img/' },
],
},
{
text: 'VitePress 插件',
items: [
{ text: '阅读增强', link: '/pages/zh-CN/integrations/vitepress-plugin-enhanced-readabilities/' },
{ text: '行内链接预览', link: '/pages/zh-CN/integrations/vitepress-plugin-inline-link-preview/' },
{ text: '闪烁高亮当前的目标标题', link: '/pages/zh-CN/integrations/vitepress-plugin-highlight-targeted-heading/' },
{ text: '基于 Git 的页面历史', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/' },
{ text: '页面属性', link: '/pages/zh-CN/integrations/vitepress-plugin-page-properties/' },
{ text: '预览图片(社交媒体卡片)生成', link: '/pages/zh-CN/integrations/vitepress-plugin-og-image/' },
{ text: 'mark 元素增强', link: '/pages/zh-CN/integrations/vitepress-plugin-enhanced-mark/' },
{ text: '缩略图模糊哈希生成', link: '/pages/zh-CN/integrations/vitepress-plugin-thumbnail-hash/' },
],
},
{
text: 'Obsidian 插件',
items: [
{ text: 'UnoCSS', link: '/pages/zh-CN/integrations/obsidian-plugin-unocss/' },
],
},
],
},
{
text: 'UI 组件',
items: [
{ text: '概览', link: '/pages/zh-CN/ui/' },
],
},
{
text: '版本发布',
items: [
{
text: '迁移指南',
items: [
{
text: '自 v1 迁移至 v2',
link: '/pages/zh-CN/releases/migrations/v1-to-v2',
},
],
},
],
},
],
'/pages/zh-CN/integrations/': [
{
text: '集成',
items: [
Expand Down Expand Up @@ -282,6 +199,7 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
],
},
{ text: '页面属性', link: '/pages/zh-CN/integrations/vitepress-plugin-page-properties/' },
{ text: '页面元信息生成', link: '/pages/zh-CN/integrations/vitepress-plugin-meta/' },
{ text: '预览图片(社交媒体卡片)生成', link: '/pages/zh-CN/integrations/vitepress-plugin-og-image/' },
{ text: 'mark 元素增强', link: '/pages/zh-CN/integrations/vitepress-plugin-enhanced-mark/' },
{
Expand All @@ -300,6 +218,20 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
{ text: 'UnoCSS', link: '/pages/zh-CN/integrations/obsidian-plugin-unocss/' },
],
},
{
text: '版本发布',
items: [
{
text: '迁移指南',
items: [
{
text: '自 v1 迁移至 v2',
link: '/pages/zh-CN/releases/migrations/v1-to-v2',
},
],
},
],
},
],
'/pages/zh-CN/ui/': [
{
Expand Down Expand Up @@ -466,59 +398,17 @@ export default defineConfig({
},
},
markdown: {
codeTransformers: [
transformerTwoslash({
errorRendering: 'hover',
onTwoslashError(error, _, __, ___) {
console.error('Twoslash Error:', (error as Error)?.message, '\n', (error as Error)?.stack ? gray(String((error as Error)?.stack)) : '')
},
twoslashOptions: {
cache: true,
compilerOptions: {
baseUrl: cwd(),
target: 99,
module: 99,
moduleResolution: 100,
paths: {
'@nolebase/ui': [
'../packages/ui/src/index.ts',
],
'@nolebase/unconfig-vitepress/*': [
'../packages/unconfig-vitepress/src/*',
],
'@nolebase/vitepress-plugin-enhanced-readabilities/*': [
'../packages/vitepress-plugin-enhanced-readabilities/src/*',
],
'@nolebase/vitepress-plugin-highlight-targeted-heading/*': [
'../packages/vitepress-plugin-highlight-targeted-heading/src/*',
],
'@nolebase/vitepress-plugin-inline-link-preview/*': [
'../packages/vitepress-plugin-inline-link-preview/src/*',
],
'@nolebase/vitepress-plugin-git-changelog/*': [
'../packages/vitepress-plugin-git-changelog/src/*',
],
'@nolebase/vitepress-plugin-page-properties/*': [
'../packages/vitepress-plugin-page-properties/src/*',
],
'@nolebase/vitepress-plugin-thumbnail-hash/*': [
'../packages/vitepress-plugin-thumbnail-hash/src/*',
],
codeTransformers: noTwoslash()
? []
: [
transformerTwoslash({
errorRendering: 'hover',
onTwoslashError(error, _, __, ___) {
console.error('Twoslash Error:', (error as Error)?.message, '\n', (error as Error)?.stack ? gray(String((error as Error)?.stack)) : '')
},
resolveJsonModule: true,
types: [
'node',
'vite/client',
],
esModuleInterop: true,
isolatedModules: true,
verbatimModuleSyntax: true,
skipLibCheck: true,
skipDefaultLibCheck: true,
},
},
}),
],
twoslashOptions: compilerOptions,
}),
],
preConfig(md) {
md.use(BiDirectionalLinks({
dir: cwd(),
Expand All @@ -532,6 +422,15 @@ export default defineConfig({
md.use(InlineLinkPreviewElementTransform)
},
},
async transformHead(context) {
let head = [...context.head]

const returnedHead = await transformHeadMeta()(head, context)
if (typeof returnedHead !== 'undefined')
head = returnedHead

return head
},
async buildEnd(siteConfig) {
const newBuilder = buildEndGenerateOpenGraphImages({
baseUrl: 'https://nolebase-integrations.ayaka.io',
Expand Down
47 changes: 47 additions & 0 deletions docs/.vitepress/twoslashConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { cwd } from 'node:process'

export const compilerOptions = {
cache: true,
compilerOptions: {
baseUrl: cwd(),
target: 99,
module: 99,
moduleResolution: 100,
paths: {
'@nolebase/ui': [
'../packages/ui/src/index.ts',
],
'@nolebase/unconfig-vitepress/*': [
'../packages/unconfig-vitepress/src/*',
],
'@nolebase/vitepress-plugin-enhanced-readabilities/*': [
'../packages/vitepress-plugin-enhanced-readabilities/src/*',
],
'@nolebase/vitepress-plugin-highlight-targeted-heading/*': [
'../packages/vitepress-plugin-highlight-targeted-heading/src/*',
],
'@nolebase/vitepress-plugin-inline-link-preview/*': [
'../packages/vitepress-plugin-inline-link-preview/src/*',
],
'@nolebase/vitepress-plugin-git-changelog/*': [
'../packages/vitepress-plugin-git-changelog/src/*',
],
'@nolebase/vitepress-plugin-page-properties/*': [
'../packages/vitepress-plugin-page-properties/src/*',
],
'@nolebase/vitepress-plugin-thumbnail-hash/*': [
'../packages/vitepress-plugin-thumbnail-hash/src/*',
],
},
resolveJsonModule: true,
types: [
'node',
'vite/client',
],
esModuleInterop: true,
isolatedModules: true,
verbatimModuleSyntax: true,
skipLibCheck: true,
skipDefaultLibCheck: true,
},
}
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@nolebase/vitepress-plugin-graph-view": "workspace:^",
"@nolebase/vitepress-plugin-highlight-targeted-heading": "workspace:^",
"@nolebase/vitepress-plugin-inline-link-preview": "workspace:^",
"@nolebase/vitepress-plugin-meta": "workspace:^",
"@nolebase/vitepress-plugin-og-image": "workspace:^",
"@nolebase/vitepress-plugin-page-properties": "workspace:^",
"@nolebase/vitepress-plugin-thumbnail-hash": "workspace:^",
Expand Down
Loading

0 comments on commit 812aa3b

Please sign in to comment.