Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/vitepress
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.20.9
Choose a base ref
...
head repository: vuejs/vitepress
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.20.10
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 25, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    pflorek Patrick Florek
    Copy the full SHA
    e61db62 View commit details
  2. release: v0.20.10

    yyx990803 committed Dec 25, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    pflorek Patrick Florek
    Copy the full SHA
    51978a3 View commit details
Showing with 28 additions and 7 deletions.
  1. +6 −0 CHANGELOG.md
  2. +8 −0 docs/.vitepress/config.ts
  3. +1 −1 package.json
  4. +13 −6 src/node/build/render.ts
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.20.10](https://github.com/vuejs/vitepress/compare/v0.20.9...v0.20.10) (2021-12-25)

### Features

- minify head inline scripts ([e61db62](https://github.com/vuejs/vitepress/commit/e61db62a1c49cb5f368a152221bfa60737dbbc6a))

## [0.20.9](https://github.com/vuejs/vitepress/compare/v0.20.8...v0.20.9) (2021-12-15)

### Features
8 changes: 8 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,14 @@ export default {
title: 'VitePress',
description: 'Vite & Vue powered static site generator.',

head: [
[
'script',
{},
'(() => { const afsefe = window.foo;\n console.log(afsefe);})()'
]
],

themeConfig: {
repo: 'vuejs/vitepress',
docsDir: 'docs',
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vitepress",
"version": "0.20.9",
"version": "0.20.10",
"description": "Vite & Vue powered static site generator",
"main": "dist/node/index.js",
"typings": "types/index.d.ts",
19 changes: 13 additions & 6 deletions src/node/build/render.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs-extra'
import { SiteConfig, resolveSiteDataByRoute } from '../config'
import { HeadConfig } from '../shared'
import { normalizePath } from 'vite'
import { normalizePath, transformWithEsbuild } from 'vite'
import { RollupOutput, OutputChunk, OutputAsset } from 'rollup'
import { slash } from '../utils/slash'
import escape from 'escape-html'
@@ -121,7 +121,7 @@ export async function renderPage(
${stylesheetLink}
${preloadLinksString}
${prefetchLinkString}
${renderHead(head)}
${await renderHead(head)}
</head>
<body>
<div id="app">${content}</div>
@@ -165,17 +165,24 @@ function resolvePageImports(
]
}

function renderHead(head: HeadConfig[]) {
return head
.map(([tag, attrs = {}, innerHTML = '']) => {
function renderHead(head: HeadConfig[]): Promise<string> {
return Promise.all(
head.map(async ([tag, attrs = {}, innerHTML = '']) => {
const openTag = `<${tag}${renderAttrs(attrs)}>`
if (tag !== 'link' && tag !== 'meta') {
if (tag === 'script') {
innerHTML = (
await transformWithEsbuild(innerHTML, 'inline-script.js', {
minify: true
})
).code.trim()
}
return `${openTag}${innerHTML}</${tag}>`
} else {
return openTag
}
})
.join('\n ')
).then((tags) => tags.join('\n '))
}

function renderAttrs(attrs: Record<string, string>): string {