diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ba3f45..82dd03d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index e918272e..92e717da 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/client/app/composables/head.ts b/src/client/app/composables/head.ts index 1230760a..fc55fca6 100644 --- a/src/client/app/composables/head.ts +++ b/src/client/app/composables/head.ts @@ -7,7 +7,7 @@ export function useUpdateHead(route: Route, siteDataByRouteRef: Ref) { 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 diff --git a/src/client/app/composables/preFetch.ts b/src/client/app/composables/preFetch.ts index 04c8dfde..e35bcecb 100644 --- a/src/client/app/composables/preFetch.ts +++ b/src/client/app/composables/preFetch.ts @@ -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. diff --git a/src/client/app/index.ts b/src/client/app/index.ts index d450d859..5eb688e3 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -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') }) diff --git a/src/client/app/mixin.ts b/src/client/app/mixin.ts index 9fb29376..24841ce8 100644 --- a/src/client/app/mixin.ts +++ b/src/client/app/mixin.ts @@ -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')) ) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 4c314ce3..7e445d29 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -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) { diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 0eee7e11..26383bf5 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -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 diff --git a/src/client/index.ts b/src/client/index.ts index 8dc04483..4bbc0251 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -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' diff --git a/src/client/theme-default/components/Home.vue b/src/client/theme-default/components/Home.vue index 38c0ae02..7c30ce59 100644 --- a/src/client/theme-default/components/Home.vue +++ b/src/client/theme-default/components/Home.vue @@ -3,6 +3,9 @@ +
+ +
@@ -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; + } +} diff --git a/src/client/theme-default/components/HomeHero.vue b/src/client/theme-default/components/HomeHero.vue index 145a0721..3e4072b0 100644 --- a/src/client/theme-default/components/HomeHero.vue +++ b/src/client/theme-default/components/HomeHero.vue @@ -4,7 +4,7 @@ -

{{ heroText }}

+

{{ heroText }}

{{ tagline }}

void, delay: number): () => void { - let timeout: NodeJS.Timeout + let timeout: number let called = false return () => { diff --git a/src/client/theme-default/styles/code.css b/src/client/theme-default/styles/code.css index adc2a221..e27762ce 100644 --- a/src/client/theme-default/styles/code.css +++ b/src/client/theme-default/styles/code.css @@ -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 { diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json index 08160422..6182a129 100644 --- a/src/client/tsconfig.json +++ b/src/client/tsconfig.json @@ -6,7 +6,7 @@ "target": "esnext", "module": "esnext", "lib": ["ESNext", "DOM"], - "types": ["vite"], + "types": ["vite/client"], "paths": { "/@shared/*": ["shared/*"], "/@types/*": ["../../types/*"], diff --git a/src/node/alias.ts b/src/node/alias.ts index fbe2cea5..15bc8290 100644 --- a/src/node/alias.ts +++ b/src/node/alias.ts @@ -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 diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index a9607a7b..9489364c 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -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, diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 2fed9c2e..0ae8e686 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -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[]) { diff --git a/src/node/config.ts b/src/node/config.ts index e565e6ec..f5625643 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -20,7 +20,7 @@ export interface UserConfig { locales?: Record alias?: Record markdown?: MarkdownOptions - // TODO locales support etc. + customData?: any } export interface SiteConfig { @@ -30,7 +30,7 @@ export interface SiteConfig { 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 { base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/', head: userConfig.head || [], themeConfig: userConfig.themeConfig || {}, - locales: userConfig.locales || {} + locales: userConfig.locales || {}, + customData: userConfig.customData || {} } } diff --git a/src/node/plugin.ts b/src/node/plugin.ts index e9503dd5..3dcd70f8 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -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 ): 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'] = { diff --git a/theme.d.ts b/theme.d.ts new file mode 100644 index 00000000..dd034b53 --- /dev/null +++ b/theme.d.ts @@ -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 diff --git a/types/index.d.ts b/types/index.d.ts index fb753f96..10a5d0c2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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' diff --git a/types/shared.d.ts b/types/shared.d.ts index cf2aa73a..1f14a6a5 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -17,6 +17,7 @@ export interface SiteData { head: HeadConfig[] themeConfig: ThemeConfig locales: Record + customData: any } export type HeadConfig = diff --git a/yarn.lock b/yarn.lock index f666a8e5..a837c342 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"