Skip to content

feat(config): Hierarchical site configuration using distributed config files #4660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c3c0d71
first working version
zhangyx1998 Mar 30, 2025
e33e9c3
refactor docs: move language-specific files into their own folders.
zhangyx1998 Mar 30, 2025
d33f6ff
fix: modify chunk rules to avoid circular import
zhangyx1998 Mar 30, 2025
fb5dbb2
update: clean up debug logging code
zhangyx1998 Mar 30, 2025
a69c186
Merge branch 'main' into feat/hierarchical-theme-config
zhangyx1998 Mar 30, 2025
fde8f22
fix bundle.ts: reliable detection for `vitepress/package.json`
zhangyx1998 Mar 30, 2025
324d79c
Merge remote-tracking branch 'origin/feat/hierarchical-theme-config' …
zhangyx1998 Mar 30, 2025
8d4ae1c
revert translation.ts: remove unneeded code
zhangyx1998 Mar 30, 2025
550e5f9
revert bundle.ts
zhangyx1998 Mar 30, 2025
f33687c
major refactor: move main logic into resolveUserConfig()
zhangyx1998 Mar 30, 2025
12b2a58
update: use node API in distributed config files
zhangyx1998 Mar 30, 2025
a8428fe
fix: remove debug code
zhangyx1998 Mar 30, 2025
0fcb916
update: remove unused code
zhangyx1998 Mar 30, 2025
7211246
fix: move `/en/config.ts` to `/config.ts`, allow root-level configura…
zhangyx1998 Mar 30, 2025
f5bdd2b
update: add config type helper, clean up code
zhangyx1998 Mar 31, 2025
6400027
update docs/*/config.ts: use defineAdditionalConfig() instead of defi…
zhangyx1998 Mar 31, 2025
38513dc
Merge branch 'main' into feat/hierarchical-theme-config
zhangyx1998 Apr 1, 2025
c8bef32
fix: respect user configured `srcDir`
zhangyx1998 Apr 3, 2025
787b825
refactor: apply additional config for both SSR and client
zhangyx1998 Apr 5, 2025
f4c18e8
fix: preserve original mergeHead() behavior
zhangyx1998 Apr 5, 2025
fb8d4e5
update: revert last change, rename `mergeHead` arguments for clarity.
zhangyx1998 Apr 5, 2025
13bbf1b
Revert "update: revert last change, rename `mergeHead` arguments for …
zhangyx1998 Apr 5, 2025
bd80a64
update: clarify comments for `mergeHead`
zhangyx1998 Apr 5, 2025
b5dfa18
Merge branch 'main' into feat/hierarchical-theme-config
zhangyx1998 Apr 6, 2025
72627ef
fix: mitigate netlify javascript heap out of memory issue
zhangyx1998 Apr 6, 2025
e142477
Merge branch 'main' into feat/hierarchical-theme-config
zhangyx1998 Apr 6, 2025
98dc562
Merge remote-tracking branch 'upstream/main' into feat/hierarchical-t…
zhangyx1998 Apr 11, 2025
a7e8c2c
remove build concurrency workaround
brc-dd Apr 13, 2025
01f600f
update configs
brc-dd Apr 13, 2025
886be32
no need to export deep partial and exclude non-pure-object stuff
brc-dd Apr 13, 2025
83eb77d
LocaleConfig can also now accept partial values
brc-dd Apr 13, 2025
13b2153
unrelated, add llms.txt plugin on build only
brc-dd Apr 13, 2025
2dd4d2b
update comment
brc-dd Apr 13, 2025
e835777
adjust imports
brc-dd Apr 13, 2025
b9d8419
update type helpers
brc-dd Apr 13, 2025
27de822
update comment, json is no longer supported
brc-dd Apr 13, 2025
e73dce3
minor tweaks
brc-dd Apr 13, 2025
21eda05
format
brc-dd Apr 13, 2025
aa29aad
use builtin functions
brc-dd Apr 13, 2025
5fdd374
fix: properly override `localeIndex` property on resolved siteData
zhangyx1998 Apr 13, 2025
0e48535
fix the locale for path thing
brc-dd Apr 14, 2025
369ba70
share isObject code
brc-dd Apr 14, 2025
53369ab
update lunaria config
brc-dd Apr 14, 2025
d5b1563
optimize head merging and preserve order
brc-dd Apr 15, 2025
87048f5
adjust implementation
brc-dd Apr 15, 2025
0e50456
Merge branch 'main' into feat/hierarchical-theme-config
brc-dd Apr 15, 2025
4995fb9
update opengraph stuff in docs, export resolveSiteDataByRoute
brc-dd Apr 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions docs/.vitepress/config/shared.ts → docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { defineConfig } from 'vitepress'
import {
defineConfig,
resolveSiteDataByRoute,
type HeadConfig
} from 'vitepress'
import {
groupIconMdPlugin,
groupIconVitePlugin,
localIconLoader
} from 'vitepress-plugin-group-icons'
import llmstxt from 'vitepress-plugin-llms'
import { search as esSearch } from './es'
import { search as faSearch } from './fa'
import { search as koSearch } from './ko'
import { search as ptSearch } from './pt'
import { search as ruSearch } from './ru'
import { search as zhSearch } from './zh'

export const shared = defineConfig({
const prod = !!process.env.NETLIFY

export default defineConfig({
title: 'VitePress',

rewrites: {
Expand Down Expand Up @@ -78,8 +78,6 @@ export const shared = defineConfig({
['link', { rel: 'icon', type: 'image/png', href: '/vitepress-logo-mini.png' }],
['meta', { name: 'theme-color', content: '#5f67ee' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: 'en' }],
['meta', { property: 'og:title', content: 'VitePress | Vite & Vue Powered Static Site Generator' }],
['meta', { property: 'og:site_name', content: 'VitePress' }],
['meta', { property: 'og:image', content: 'https://vitepress.dev/vitepress-og.jpg' }],
['meta', { property: 'og:url', content: 'https://vitepress.dev/' }],
Expand All @@ -98,35 +96,53 @@ export const shared = defineConfig({
options: {
appId: '8J64VVRP8K',
apiKey: '52f578a92b88ad6abde815aae2b0ad7c',
indexName: 'vitepress',
locales: {
...zhSearch,
...ptSearch,
...ruSearch,
...esSearch,
...koSearch,
...faSearch
}
indexName: 'vitepress'
}
},

carbonAds: { code: 'CEBDT27Y', placement: 'vuejsorg' }
},

locales: {
root: { label: 'English' },
zh: { label: '简体中文' },
pt: { label: 'Português' },
ru: { label: 'Русский' },
es: { label: 'Español' },
ko: { label: '한국어' },
fa: { label: 'فارسی' }
},

vite: {
plugins: [
groupIconVitePlugin({
customIcon: {
vitepress: localIconLoader(
import.meta.url,
'../../public/vitepress-logo-mini.svg'
'../public/vitepress-logo-mini.svg'
),
firebase: 'logos:firebase'
}
}),
llmstxt({
workDir: 'en',
ignoreFiles: ['index.md']
})
prod &&
llmstxt({
workDir: 'en',
ignoreFiles: ['index.md']
})
]
}
},

transformPageData: prod
? (pageData, ctx) => {
const site = resolveSiteDataByRoute(
ctx.siteConfig.site,
pageData.relativePath
)
const title = `${pageData.title || site.title} | ${pageData.description || site.description}`
;((pageData.frontmatter.head ??= []) as HeadConfig[]).push(
['meta', { property: 'og:locale', content: site.lang }],
['meta', { property: 'og:title', content: title }]
)
}
: undefined
})
22 changes: 0 additions & 22 deletions docs/.vitepress/config/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions docs/.vitepress/config/en.ts → docs/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createRequire } from 'module'
import { defineConfig, type DefaultTheme } from 'vitepress'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'

const require = createRequire(import.meta.url)
const pkg = require('vitepress/package.json')

export const en = defineConfig({
export default defineAdditionalConfig({
lang: 'en-US',
description: 'Vite & Vue powered static site generator.',

Expand Down
3 changes: 0 additions & 3 deletions docs/en/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: home

title: VitePress
titleTemplate: Vite & Vue Powered Static Site Generator

hero:
name: VitePress
text: Vite & Vue Powered Static Site Generator
Expand Down
24 changes: 15 additions & 9 deletions docs/.vitepress/config/es.ts → docs/es/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { createRequire } from 'module'
import { defineConfig, type DefaultTheme } from 'vitepress'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'

const require = createRequire(import.meta.url)
const pkg = require('vitepress/package.json')

export const es = defineConfig({
export default defineAdditionalConfig({
lang: 'es-CO',
description: 'Generador de Sitios Estaticos desarrollado con Vite y Vue.',

themeConfig: {
nav: nav(),

search: { options: searchOptions() },

sidebar: {
'/es/guide/': { base: '/es/guide/', items: sidebarGuide() },
'/es/reference/': { base: '/es/reference/', items: sidebarReference() }
Expand All @@ -36,11 +38,15 @@ export const es = defineConfig({
},

lastUpdated: {
text: 'Actualizado en',
formatOptions: {
dateStyle: 'short',
timeStyle: 'medium'
}
text: 'Actualizado en'
},

notFound: {
title: 'PÁGINA NO ENCONTRADA',
quote:
'Pero si no cambias de dirección y sigues buscando, podrías terminar donde te diriges.',
linkLabel: 'ir a inicio',
linkText: 'Llévame a casa'
},

langMenuLabel: 'Cambiar Idioma',
Expand Down Expand Up @@ -170,8 +176,8 @@ function sidebarReference(): DefaultTheme.SidebarItem[] {
]
}

export const search: DefaultTheme.AlgoliaSearchOptions['locales'] = {
es: {
function searchOptions(): Partial<DefaultTheme.AlgoliaSearchOptions> {
return {
placeholder: 'Buscar documentos',
translations: {
button: {
Expand Down
3 changes: 0 additions & 3 deletions docs/es/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: home

title: VitePress
titleTemplate: Generador de Sitios Estáticos desarrollado con Vite y Vue

hero:
name: VitePress
text: Generador de Sitios Estáticos Vite y Vue
Expand Down
46 changes: 18 additions & 28 deletions docs/.vitepress/config/fa.ts → docs/fa/config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { createRequire } from 'module'
import { defineConfig, type DefaultTheme } from 'vitepress'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'

const require = createRequire(import.meta.url)
const pkg = require('vitepress/package.json')

export const fa = defineConfig({
title: 'ویت‌پرس',
export default defineAdditionalConfig({
lang: 'fa-IR',
description: 'Vite & Vue powered static site generator.',
description: 'ژنراتور استاتیک وب‌سایت با Vite و Vue',
dir: 'rtl',
markdown: {
container: {
tipLabel: 'نکته',
warningLabel: 'هشدار',
dangerLabel: 'خطر',
infoLabel: 'اطلاعات',
detailsLabel: 'جزئیات'
}
},

themeConfig: {
nav: nav(),

search: { options: searchOptions() },

sidebar: {
'/fa/guide/': { base: '/fa/guide/', items: sidebarGuide() },
'/fa/reference/': { base: '/fa/reference/', items: sidebarReference() }
Expand All @@ -45,11 +39,15 @@ export const fa = defineConfig({
},

lastUpdated: {
text: 'آخرین به‌روزرسانی‌',
formatOptions: {
dateStyle: 'short',
timeStyle: 'medium'
}
text: 'آخرین به‌روزرسانی‌'
},

notFound: {
title: 'صفحه پیدا نشد',
quote:
'اما اگر جهت خود را تغییر ندهید و همچنان به جستجو ادامه دهید، ممکن است در نهایت به جایی برسید که در حال رفتن به آن هستید.',
linkLabel: 'برو به خانه',
linkText: 'من را به خانه ببر'
},

langMenuLabel: 'تغییر زبان',
Expand All @@ -58,14 +56,6 @@ export const fa = defineConfig({
darkModeSwitchLabel: 'تم تاریک',
lightModeSwitchTitle: 'رفتن به حالت روشن',
darkModeSwitchTitle: 'رفتن به حالت تاریک',
notFound: {
linkLabel: 'بازگشت به خانه',
linkText: 'بازگشت به خانه',
title: 'صفحه مورد نظر یافت نشد',
code: '۴۰۴',
quote:
'اما اگر جهت خود را تغییر ندهید و اگر ادامه دهید به دنبال چیزی که دنبال می‌کنید، ممکن است در نهایت به جایی که در حال رفتن به سمتش هستید، برسید.'
},
siteTitle: 'ویت‌پرس'
}
})
Expand Down Expand Up @@ -181,8 +171,8 @@ function sidebarReference(): DefaultTheme.SidebarItem[] {
]
}

export const search: DefaultTheme.AlgoliaSearchOptions['locales'] = {
fa: {
function searchOptions(): Partial<DefaultTheme.AlgoliaSearchOptions> {
return {
placeholder: 'جستجوی مستندات',
translations: {
button: {
Expand Down
3 changes: 0 additions & 3 deletions docs/fa/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: home

title: ویت‌پرس
titleTemplate: Vite & Vue Powered Static Site Generator

hero:
name: ویت‌پرس
text: سازنده سایت‌های ایستا به کمک Vite و Vue
Expand Down
18 changes: 14 additions & 4 deletions docs/.vitepress/config/ko.ts → docs/ko/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { createRequire } from 'module'
import { defineConfig, type DefaultTheme } from 'vitepress'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'

const require = createRequire(import.meta.url)
const pkg = require('vitepress/package.json')

export const ko = defineConfig({
export default defineAdditionalConfig({
lang: 'ko-KR',
description: 'Vite 및 Vue 기반 정적 사이트 생성기.',

themeConfig: {
nav: nav(),

search: { options: searchOptions() },

sidebar: {
'/ko/guide/': { base: '/ko/guide/', items: sidebarGuide() },
'/ko/reference/': { base: '/ko/reference/', items: sidebarReference() }
Expand Down Expand Up @@ -39,6 +41,14 @@ export const ko = defineConfig({
text: '업데이트 날짜'
},

notFound: {
title: '페이지를 찾을 수 없습니다',
quote:
'방향을 바꾸지 않고 계속 찾다 보면 결국 당신이 가고 있는 곳에 도달할 수도 있습니다.',
linkLabel: '홈으로 가기',
linkText: '집으로 데려가줘'
},

langMenuLabel: '언어 변경',
returnToTopLabel: '맨 위로 돌아가기',
sidebarMenuLabel: '사이드바 메뉴',
Expand Down Expand Up @@ -208,8 +218,8 @@ function sidebarReference(): DefaultTheme.SidebarItem[] {
]
}

export const search: DefaultTheme.AlgoliaSearchOptions['locales'] = {
ko: {
function searchOptions(): Partial<DefaultTheme.AlgoliaSearchOptions> {
return {
placeholder: '문서 검색',
translations: {
button: {
Expand Down
3 changes: 0 additions & 3 deletions docs/ko/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: home

title: VitePress
titleTemplate: Vite & Vue 기반 정적 사이트 생성기

hero:
name: VitePress
text: Vite & Vue 기반 정적 사이트 생성기
Expand Down
4 changes: 2 additions & 2 deletions docs/lunaria.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"files": [
{
"location": ".vitepress/config/{en,zh,pt,ru,es,ko,fa}.ts",
"pattern": ".vitepress/config/@lang.ts",
"location": "**/config.ts",
"pattern": "@lang/@path",
"type": "universal"
},
{
Expand Down
Loading