Merge branch 'master' into fix/symbolic-links-in-build

pull/185/head
Łukasz Romanowicz 5 years ago committed by GitHub
commit ff10456173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,58 @@
## [0.11.3](https://github.com/vuejs/vitepress/compare/v0.11.2...v0.11.3) (2021-01-13)
### Bug Fixes
- ignore non-html links in router and prefetch ([3e6e61b](https://github.com/vuejs/vitepress/commit/3e6e61bcea8d4a34079428fcce3ecd25af1ae4f7))
## [0.11.2](https://github.com/vuejs/vitepress/compare/v0.11.1...v0.11.2) (2021-01-12)
### Bug Fixes
- aria label id ([a0f463a](https://github.com/vuejs/vitepress/commit/a0f463af8fd828d24d9a01c3d808d85af8a71c9f))
### Performance Improvements
- generate preload directives for dynamicImport chunks too ([b9fc0cb](https://github.com/vuejs/vitepress/commit/b9fc0cb78d43949b417376498939daa892a33334))
## [0.11.1](https://github.com/vuejs/vitepress/compare/v0.11.0...v0.11.1) (2021-01-12)
### Features
- render content on home page ([ca631c7](https://github.com/vuejs/vitepress/commit/ca631c7f516ad6c643d252dd81e03e29fb3b9e05))
# [0.11.0](https://github.com/vuejs/vitepress/compare/v0.10.8...v0.11.0) (2021-01-12)
### Code Refactoring
- move default theme to 'vitepress/theme' ([a79e1e1](https://github.com/vuejs/vitepress/commit/a79e1e1916a71271728e6fe7c2b734fc2f209518))
### Features
- support customData in config ([4072dc5](https://github.com/vuejs/vitepress/commit/4072dc5f7ede381709fce49e9a29d6af4f7ab81a))
### BREAKING CHANGES
- the default theme is now exposed via 'vitepress/theme',
instead of a named export from 'vitepress'. This change fixes the case where
when a completely custom theme is used, importing anything from 'vitepress'
also imports the entire default theme.
## [0.10.8](https://github.com/vuejs/vitepress/compare/v0.10.7...v0.10.8) (2021-01-11)
### Bug Fixes
- resolve page hash case-insenstively, close [#202](https://github.com/vuejs/vitepress/issues/202) ([#203](https://github.com/vuejs/vitepress/issues/203)) ([bac1ce2](https://github.com/vuejs/vitepress/commit/bac1ce2d01469ff7586437f43b0d665b1c5eb278))
## [0.10.7](https://github.com/vuejs/vitepress/compare/v0.10.6...v0.10.7) (2021-01-05)
### Features
Bump to Vite 2.0.0-beta.8
### Bug Fixes
- scrollbar when using line highlight ([#200](https://github.com/vuejs/vitepress/issues/200)) ([b6ba8a9](https://github.com/vuejs/vitepress/commit/b6ba8a943cc0488410a438c6c2f277c1c33a90bf))
## [0.10.6](https://github.com/vuejs/vitepress/compare/v0.10.5...v0.10.6) (2021-01-04)
### Bug Fixes

@ -1,6 +1,6 @@
{
"name": "vitepress",
"version": "0.10.6",
"version": "0.11.3",
"description": "Vite & Vue powered static site generator",
"main": "dist/node/index.js",
"typings": "types/index.d.ts",
@ -31,7 +31,7 @@
"docs-dev": "node ./bin/vitepress dev docs",
"docs-debug": "node --inspect-brk ./bin/vitepress dev docs",
"docs-build": "yarn build && node ./bin/vitepress build docs",
"docs-serve": "yarn docs-build && node ./bin/vitepress serve docs"
"docs-serve": "node ./bin/vitepress serve docs"
},
"engines": {
"node": ">=12.0.0"
@ -88,7 +88,7 @@
"prismjs": "^1.20.0",
"sirv": "^1.0.10",
"slash": "^3.0.0",
"vite": "^2.0.0-beta.4",
"vite": "^2.0.0-beta.21",
"vue": "^3.0.5"
},
"devDependencies": {

@ -7,7 +7,7 @@ export function useUpdateHead(route: Route, siteDataByRouteRef: Ref<SiteData>) {
let isFirstUpdate = true
const updateHeadTags = (newTags: HeadConfig[]) => {
if (process.env.NODE_ENV === 'production' && isFirstUpdate) {
if (import.meta.env.PROD && isFirstUpdate) {
// in production, the initial meta tags are already pre-rendered so we
// skip the first update.
isFirstUpdate = false

@ -75,6 +75,11 @@ export function usePrefetch() {
rIC(() => {
document.querySelectorAll('#app a').forEach((link) => {
const { target, hostname, pathname } = link as HTMLAnchorElement
const extMatch = pathname.match(/\.\w+$/)
if (extMatch && extMatch[0] !== '.html') {
return
}
if (
// only prefetch same tab navigation, since a new tab will load
// the lean js chunk instead.

@ -1,3 +1,4 @@
import 'vite/dynamic-import-polyfill'
import { App, createApp as createClientApp, createSSRApp, h } from 'vue'
import { inBrowser, pathToFile } from './utils'
import { Router, RouterSymbol, createRouter } from './router'
@ -54,7 +55,7 @@ export function createApp() {
}
function newApp(): App {
return process.env.NODE_ENV === 'production'
return import.meta.env.PROD
? createSSRApp(VitePressApp)
: createClientApp(VitePressApp)
}
@ -85,6 +86,7 @@ function newRouter(): Router {
}
// SSR: sync require
// @ts-ignore
return require(pageFilePath)
}, NotFound)
}
@ -111,7 +113,7 @@ function shouldHotReload(payload: any): boolean {
if (inBrowser) {
const { app, router } = createApp()
// wait unitl page component is fetched before mounting
// wait until page component is fetched before mounting
router.go().then(() => {
app.mount('#app')
})

@ -65,13 +65,11 @@ export function mixinGlobalComputed(
}
export function mixinGlobalComponents(app: App) {
const isProd = process.env.NODE_ENV === 'production'
app.component('Content', Content)
app.component('ClientOnly', ClientOnly)
app.component(
'Debug',
isProd
import.meta.env.PROD
? () => null
: defineAsyncComponent(() => import('./components/Debug.vue'))
)

@ -23,7 +23,7 @@ const getDefaultRoute = (): Route => ({
path: '/',
component: null,
// this will be set upon initial page load, which is before
// the app is mounted, so it's guaranteed to be avaiable in
// the app is mounted, so it's guaranteed to be available in
// components
data: null as any
})
@ -114,6 +114,7 @@ export function createRouter(
if (link) {
const { href, protocol, hostname, pathname, hash, target } = link
const currentUrl = window.location
const extMatch = pathname.match(/\.\w+$/)
// only intercept inbound links
if (
!e.ctrlKey &&
@ -122,7 +123,8 @@ export function createRouter(
!e.metaKey &&
target !== `_blank` &&
protocol === currentUrl.protocol &&
hostname === currentUrl.hostname
hostname === currentUrl.hostname &&
!(extMatch && extMatch[0] !== '.html')
) {
e.preventDefault()
if (pathname === currentUrl.pathname) {

@ -17,7 +17,7 @@ export function pathToFile(path: string): string {
}
if (import.meta.env.DEV) {
// awlays force re-fetch content in dev
// always force re-fetch content in dev
pagePath += `.md?t=${Date.now()}`
} else {
// in production, each .md file is built into a .md.js file following
@ -28,7 +28,7 @@ export function pathToFile(path: string): string {
pagePath = pagePath.slice(base.length).replace(/\//g, '_') + '.md'
// client production build needs to account for page hash, which is
// injected directly in the page's html
const pageHash = __VP_HASH_MAP__[pagePath]
const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()]
pagePath = `${base}assets/${pagePath}.${pageHash}.js`
} else {
// ssr build uses much simpler name mapping

@ -5,7 +5,7 @@
export type { Router, Route } from './app/router'
// theme types
export * from './app/theme'
export type { Theme, EnhanceAppContext } from './app/theme'
// composables
export { useRouter, useRoute } from './app/router'
@ -24,6 +24,3 @@ import { ComponentOptions } from 'vue'
import _Debug from './app/components/Debug.vue'
const Debug = _Debug as ComponentOptions
export { Debug }
// default theme
export { default as DefaultTheme } from './theme-default'

@ -3,6 +3,9 @@
<HomeHero />
<slot name="hero" />
<HomeFeatures />
<div class="home-content">
<Content />
</div>
<slot name="features" />
<HomeFooter />
<slot name="footer" />
@ -19,4 +22,17 @@ import HomeFooter from './HomeFooter.vue'
.home {
padding-top: var(--header-height);
}
.home-content {
max-width: 960px;
margin: 0px auto;
padding: 0 1.5rem;
}
@media (max-width: 720px) {
.home-content {
max-width: 392px;
padding: 0;
}
}
</style>

@ -4,7 +4,7 @@
<img class="image" :src="$withBase($frontmatter.heroImage)" :alt="$frontmatter.heroAlt" />
</figure>
<h1 v-if="hasHeroText" class="title">{{ heroText }}</h1>
<h1 v-if="hasHeroText" id="main-title" class="title">{{ heroText }}</h1>
<p v-if="hasTagline" class="description">{{ tagline }}</p>
<NavLink

@ -113,7 +113,7 @@ function isAnchorActive(
}
function throttleAndDebounce(fn: () => void, delay: number): () => void {
let timeout: NodeJS.Timeout
let timeout: number
let called = false
return () => {

@ -85,6 +85,7 @@ li > div[class*='language-'] {
font-family: var(--code-font-family);
font-size: var(--code-font-size);
user-select: none;
overflow: hidden;
}
.highlight-lines .highlighted {

@ -6,7 +6,7 @@
"target": "esnext",
"module": "esnext",
"lib": ["ESNext", "DOM"],
"types": ["vite"],
"types": ["vite/client"],
"paths": {
"/@shared/*": ["shared/*"],
"/@types/*": ["../../types/*"],

@ -38,6 +38,10 @@ export function resolveAliases(
find: /^vitepress$/,
replacement: path.join(__dirname, '../client/index')
},
{
find: /^vitepress\/theme$/,
replacement: path.join(__dirname, '../client/theme-default/index')
},
// alias for local linked development
{ find: /^vitepress\//, replacement: PKG_ROOT + '/' },
// make sure it always use the same vue dependency that comes with

@ -40,7 +40,6 @@ export async function bundle(
plugins: createVitePressPlugin(root, config, ssr, pageToHashMap),
build: {
...options,
// @ts-ignore
ssr,
base: config.site.base,
outDir: ssr ? config.tempDir : config.outDir,

@ -29,7 +29,7 @@ export async function renderPage(
const pageServerJsFileName = pageName + '.js'
// for any initial page load, we only need the lean version of the page js
// since the static content is already on the page!
const pageHash = pageToHashMap[pageName]
const pageHash = pageToHashMap[pageName.toLowerCase()]
const pageClientJsFileName = `assets/${pageName}.${pageHash}.lean.js`
// resolve page data so we can render head tags
@ -88,14 +88,20 @@ function resolvePageImports(
) {
// find the page's js chunk and inject script tags for its imports so that
// they are start fetching as early as possible
const srcPath = normalizePath(
fs.realpathSync(path.resolve(config.root, page))
)
const pageChunk = result.output.find(
(chunk) => chunk.type === 'chunk' && chunk.facadeModuleId === srcPath
) as OutputChunk
return Array.from(new Set([...indexChunk.imports, ...pageChunk.imports]))
return Array.from(
new Set([
...indexChunk.imports,
...indexChunk.dynamicImports,
...pageChunk.imports,
...pageChunk.dynamicImports
])
)
}
function renderHead(head: HeadConfig[]) {

@ -20,7 +20,7 @@ export interface UserConfig<ThemeConfig = any> {
locales?: Record<string, LocaleConfig>
alias?: Record<string, string>
markdown?: MarkdownOptions
// TODO locales support etc.
customData?: any
}
export interface SiteConfig<ThemeConfig = any> {
@ -30,7 +30,7 @@ export interface SiteConfig<ThemeConfig = any> {
themeDir: string
outDir: string
tempDir: string
aliases: AliasOptions
alias: AliasOptions
pages: string[]
markdown?: MarkdownOptions
}
@ -59,7 +59,7 @@ export async function resolveConfig(
outDir: resolve(root, 'dist'),
tempDir: path.resolve(APP_PATH, 'temp'),
markdown: userConfig.markdown,
aliases: resolveAliases(root, themeDir, userConfig)
alias: resolveAliases(root, themeDir, userConfig)
}
return config
@ -91,6 +91,7 @@ export async function resolveSiteData(root: string): Promise<SiteData> {
base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/',
head: userConfig.head || [],
themeConfig: userConfig.themeConfig || {},
locales: userConfig.locales || {}
locales: userConfig.locales || {},
customData: userConfig.customData || {}
}
}

@ -24,7 +24,7 @@ const isPageChunk = (
export function createVitePressPlugin(
root: string,
{ configPath, aliases, markdown, themeDir, site }: SiteConfig,
{ configPath, alias, markdown, site }: SiteConfig,
ssr = false,
pageToHashMap?: Record<string, string>
): Plugin[] {
@ -42,8 +42,7 @@ export function createVitePressPlugin(
config() {
return {
alias: aliases,
transformInclude: /\.md$/,
alias,
define: {
__CARBON__: !!site.themeConfig.carbonAds?.carbon,
__BSA__: !!site.themeConfig.carbonAds?.custom,
@ -123,7 +122,7 @@ export function createVitePressPlugin(
if (isPageChunk(chunk)) {
// record page -> hash relations
const hash = chunk.fileName.match(hashRE)![1]
pageToHashMap![chunk.name] = hash
pageToHashMap![chunk.name.toLowerCase()] = hash
// inject another chunk with the content stripped
bundle[name + '-lean'] = {

3
theme.d.ts vendored

@ -0,0 +1,3 @@
// so that users can do `import DefaultTheme from 'vitepress/theme'`
import DefaultTheme from './dist/client/theme-default/index'
export default DefaultTheme

3
types/index.d.ts vendored

@ -1,5 +1,4 @@
export * from './shared'
export * from '../dist/node/index'
export * from '../dist/client/app/exports'
export * from '../dist/client/index'
export * from '../dist/client/theme-default/config'
export { default as defaultTheme } from '../dist/client/theme-default/index'

1
types/shared.d.ts vendored

@ -17,6 +17,7 @@ export interface SiteData<ThemeConfig = any> {
head: HeadConfig[]
themeConfig: ThemeConfig
locales: Record<string, LocaleConfig>
customData: any
}
export type HeadConfig =

@ -5120,7 +5120,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.17.0, resolve@^1.18.1:
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0:
version "1.19.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
@ -6031,13 +6031,14 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"
vite@^2.0.0-beta.4:
version "2.0.0-beta.4"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.4.tgz#6ea8e08ae5e6b510548d02ec770d34046622aef7"
integrity sha512-V0HV6xyUPQ9ktJ8gLm0Et7zTFtp8WmISsH/K+FuGF3aJ4VJOlSYEaget1nHCauUPI7WDPe97suz7SCIVHW2iEg==
vite@^2.0.0-beta.21:
version "2.0.0-beta.21"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.21.tgz#9a7233c93ed59c5b5de28c3a74f1e94b815d746e"
integrity sha512-B6OhGHwh4DTkDBxZXtGhxmDkK75M3o0sKFz/cfZ2bdqxRze870sJgH66kPuYWjgSVDdPz0NTIKBaxrbcA8wwmw==
dependencies:
esbuild "^0.8.26"
postcss "^8.2.1"
resolve "^1.19.0"
rollup "^2.35.1"
optionalDependencies:
fsevents "~2.1.2"

Loading…
Cancel
Save