Skip to content

Commit ca1b2a2

Browse files
authored
Merge branch 'main' into feat/i18n-next
2 parents ad8a368 + 4482c50 commit ca1b2a2

File tree

9 files changed

+215
-35
lines changed

9 files changed

+215
-35
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
# [1.0.0-alpha.14](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.13...v1.0.0-alpha.14) (2022-09-14)
2+
3+
4+
### Bug Fixes
5+
6+
* prevent jumping on clicking docsearch action buttons ([#1140](https://github.com/vuejs/vitepress/issues/1140)) ([86413e6](https://github.com/vuejs/vitepress/commit/86413e6739a834f8490c2004a62a27d1f5a59d00))
7+
* **theme:** break long words ([#1064](https://github.com/vuejs/vitepress/issues/1064)) ([9c739fd](https://github.com/vuejs/vitepress/commit/9c739fd37d15bbf16e8214e20a4bca1c763c4510))
8+
* **theme:** don't nest sidebar links ([#1279](https://github.com/vuejs/vitepress/issues/1279)) ([f840dbc](https://github.com/vuejs/vitepress/commit/f840dbc58f972492ed4afa9b6b222c4f7d89ade1))
9+
* **theme:** keep display copied hint when click multiple times ([#1262](https://github.com/vuejs/vitepress/issues/1262)) ([bb11d0f](https://github.com/vuejs/vitepress/commit/bb11d0f17852a3f2a35339f765acffca526a9ee8))
10+
* **theme:** show progress bar after delay ([#1278](https://github.com/vuejs/vitepress/issues/1278)) ([496bd34](https://github.com/vuejs/vitepress/commit/496bd34ff4143dcef9532f4298ca670bfa34e399))
11+
* **theme:** use pointer cursor only on enabled buttons ([#1300](https://github.com/vuejs/vitepress/issues/1300)) ([d7eac98](https://github.com/vuejs/vitepress/commit/d7eac980e15510de18dbf1fd675a6c1def5f6697))
12+
* **theme:** use pointer-events auto instead of all ([#1290](https://github.com/vuejs/vitepress/issues/1290)) ([6fac5b2](https://github.com/vuejs/vitepress/commit/6fac5b2964e77462edc963811ee1714e337fa53e))
13+
* **types:** allow non async `transformHtml` and `buildEnd` ([#1270](https://github.com/vuejs/vitepress/issues/1270)) ([ee37eaa](https://github.com/vuejs/vitepress/commit/ee37eaa27191faad03c04d60fb3ca8ffbb887fbe))
14+
15+
16+
### Features
17+
18+
* add `transformHead` hook ([#1323](https://github.com/vuejs/vitepress/issues/1323)) ([6b16dad](https://github.com/vuejs/vitepress/commit/6b16dad22f944cb173dbf67ef04be5cb0d09279f))
19+
* add `vp-raw` container ([#1104](https://github.com/vuejs/vitepress/issues/1104)) ([9a6e1ea](https://github.com/vuejs/vitepress/commit/9a6e1ea401c4a44205f96c4786c44061582f675c))
20+
* bundle type definitions of dev-deps ([#1257](https://github.com/vuejs/vitepress/issues/1257)) ([12591a9](https://github.com/vuejs/vitepress/commit/12591a9487ff7647162051f4b28956f0c1403efb))
21+
* **theme:** add page load progress bar ([#1264](https://github.com/vuejs/vitepress/issues/1264)) ([ecf5515](https://github.com/vuejs/vitepress/commit/ecf5515bd453eca20946339a56be9180f6dca2c1))
22+
* **theme:** allow disabling whole layout ([#1268](https://github.com/vuejs/vitepress/issues/1268)) ([8f63033](https://github.com/vuejs/vitepress/commit/8f630339ba95cbaded97f0fcff9323755dd16bcc))
23+
* **theme:** support dynamic headers and nesting in outline ([#1281](https://github.com/vuejs/vitepress/issues/1281)) ([288aa48](https://github.com/vuejs/vitepress/commit/288aa48b92bc1d4dd74d064148a3b03373cdf1c3))
24+
25+
26+
### Performance Improvements
27+
28+
* **a11y:** add aria-checked attribute to switch ([#644](https://github.com/vuejs/vitepress/issues/644)) ([eb9026d](https://github.com/vuejs/vitepress/commit/eb9026d83ca17c59893e7063e0c64b0bf1b99765))
29+
* render pages asynchronously ([#1320](https://github.com/vuejs/vitepress/issues/1320)) ([8e4ff4d](https://github.com/vuejs/vitepress/commit/8e4ff4de901d846ac99d37ebf212b12e9687ed5e))
30+
31+
32+
### Reverts
33+
34+
* **#1264:** add page load progress bar ([#1311](https://github.com/vuejs/vitepress/issues/1311)) ([5378a49](https://github.com/vuejs/vitepress/commit/5378a49613ceef591d2cacecbc175921658b22b1)), closes [#1264](https://github.com/vuejs/vitepress/issues/1264)
35+
36+
37+
138
# [1.0.0-alpha.13](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2022-08-30)
239

340

docs/config/app-configs.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,70 @@ export default {
246246
cleanUrls: 'with-subfolders'
247247
}
248248
```
249+
250+
## Build Hooks
251+
252+
VitePress build hooks allow you to add new functionality and behaviors to your website:
253+
254+
- Sitemap
255+
- Search Indexing
256+
- PWA
257+
258+
### transformHead
259+
260+
- Type: `(ctx: TransformContext) => Awaitable<HeadConfig[]>`
261+
262+
`transformHead` is a build hook to transform the head before generating each page. It will allow you to add head entries that cannot be statically added to your VitePress config. You only need to return extra entries, they will be merged automatically with the existing ones.
263+
264+
::: warning
265+
Don't mutate anything inside the `ctx`.
266+
:::
267+
268+
```ts
269+
export default {
270+
async transformHead(ctx) {
271+
}
272+
}
273+
```
274+
275+
```ts
276+
interface TransformContext {
277+
siteConfig: SiteConfig
278+
siteData: SiteData
279+
pageData: PageData
280+
title: string
281+
description: string
282+
head: HeadConfig[]
283+
content: string
284+
}
285+
```
286+
287+
### transformHtml
288+
289+
- Type: `(code: string, id: string, ctx: TransformContext) => Awaitable<string | void>`
290+
291+
`transformHtml` is a build hook to transform the content of each page before saving to disk.
292+
293+
::: warning
294+
Don't mutate anything inside the `ctx`. Also, modifying the html content may cause hydration problems in runtime.
295+
:::
296+
297+
```ts
298+
export default {
299+
async transformHtml(code, id, context) {
300+
}
301+
}
302+
```
303+
304+
### buildEnd
305+
306+
- Type: `(siteConfig: SiteConfig) => Awaitable<void>`
307+
308+
`buildEnd` is a build CLI hook, it will run after build (SSG) finish but before VitePress CLI process exits.
309+
310+
```ts
311+
export default {
312+
async buildEnd(siteConfig) {
313+
}
314+
}
315+
```

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "vitepress",
3-
"version": "1.0.0-alpha.13",
3+
"version": "1.0.0-alpha.14",
44
"description": "Vite & Vue powered static site generator",
55
"type": "module",
6-
"packageManager": "pnpm@7.11.0",
6+
"packageManager": "pnpm@7.9.2",
77
"main": "dist/node/index.js",
88
"types": "types/index.d.ts",
99
"exports": {
@@ -148,6 +148,7 @@
148148
"npm-run-all": "^4.1.5",
149149
"ora": "^5.4.1",
150150
"picocolors": "^1.0.0",
151+
"pkg-dir": "^5.0.0",
151152
"playwright-chromium": "^1.25.1",
152153
"polka": "^0.5.2",
153154
"prettier": "^2.7.1",

pnpm-lock.yaml

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/theme-default/components/VPNavBarExtra.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { useLangs } from '../composables/langs.js'
88
99
const { site, theme } = useData()
1010
const { localeLinks, currentLang } = useLangs()
11+
12+
const hasExtraContent = computed(() => theme.value.localeLinks || site.value.appearance || theme.value.socialLinks)
1113
</script>
1214

1315
<template>
14-
<VPFlyout class="VPNavBarExtra" label="extra navigation">
16+
<VPFlyout v-if="hasExtraContent" class="VPNavBarExtra" label="extra navigation">
1517
<div v-if="localeLinks.length && currentLang.label" class="group">
1618
<p class="trans-title">{{ currentLang.label }}</p>
17-
1819
<template v-for="locale in localeLinks" :key="locale.link">
1920
<VPMenuLink :item="locale" />
2021
</template>

src/node/build/build.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { renderPage } from './render'
88
import { bundle, okMark, failMark } from './bundle'
99
import { createRequire } from 'module'
1010
import { pathToFileURL } from 'url'
11+
import pkgDir from 'pkg-dir'
1112

1213
export async function build(
1314
root?: string,
@@ -17,7 +18,7 @@ export async function build(
1718

1819
process.env.NODE_ENV = 'production'
1920
const siteConfig = await resolveConfig(root, 'build', 'production')
20-
const unlinkVue = linkVue(siteConfig.root)
21+
const unlinkVue = linkVue()
2122

2223
if (buildOptions.base) {
2324
siteConfig.site.base = buildOptions.base
@@ -65,18 +66,20 @@ export async function build(
6566

6667
const pages = ['404.md', ...siteConfig.pages]
6768

68-
for (const page of pages) {
69-
await renderPage(
70-
render,
71-
siteConfig,
72-
page,
73-
clientResult,
74-
appChunk,
75-
cssChunk,
76-
pageToHashMap,
77-
hashMapString
69+
await Promise.all(
70+
pages.map((page) =>
71+
renderPage(
72+
render,
73+
siteConfig,
74+
page,
75+
clientResult,
76+
appChunk,
77+
cssChunk,
78+
pageToHashMap,
79+
hashMapString
80+
)
7881
)
79-
}
82+
)
8083
} catch (e) {
8184
spinner.stopAndPersist({
8285
symbol: failMark
@@ -104,14 +107,17 @@ export async function build(
104107
console.log(`build complete in ${((Date.now() - start) / 1000).toFixed(2)}s.`)
105108
}
106109

107-
function linkVue(root: string) {
108-
const dest = path.resolve(root, 'node_modules/vue')
109-
// if user did not install vue by themselves, link VitePress' version
110-
if (!fs.existsSync(dest)) {
111-
const src = path.dirname(createRequire(import.meta.url).resolve('vue'))
112-
fs.ensureSymlinkSync(src, dest, 'junction')
113-
return () => {
114-
fs.unlinkSync(dest)
110+
function linkVue() {
111+
const root = pkgDir.sync()
112+
if (root) {
113+
const dest = path.resolve(root, 'node_modules/vue')
114+
// if user did not install vue by themselves, link VitePress' version
115+
if (!fs.existsSync(dest)) {
116+
const src = path.dirname(createRequire(import.meta.url).resolve('vue'))
117+
fs.ensureSymlinkSync(src, dest, 'junction')
118+
return () => {
119+
fs.unlinkSync(dest)
120+
}
115121
}
116122
}
117123
return () => {}

src/node/build/render.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,24 @@ export async function renderPage(
107107
const title: string = createTitle(siteData, pageData)
108108
const description: string = pageData.description || siteData.description
109109

110-
const head = mergeHead(
110+
const headBeforeTransform = mergeHead(
111111
siteData.head,
112112
filterOutHeadDescription(pageData.frontmatter.head)
113113
)
114114

115+
const head = mergeHead(
116+
headBeforeTransform,
117+
(await config.transformHead?.({
118+
siteConfig: config,
119+
siteData,
120+
pageData,
121+
title,
122+
description,
123+
head: headBeforeTransform,
124+
content
125+
})) || []
126+
)
127+
115128
let inlinedScript = ''
116129
if (config.mpa && result) {
117130
const matchingChunk = result.output.find(

0 commit comments

Comments
 (0)