vitepress 0.22.2 → 0.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ---
7
7
 
8
- VitePress is [VuePress](http://vuepress.vuejs.org/)' spiritual successor, built on top of [vite](https://github.com/vuejs/vite).
8
+ VitePress is [VuePress](https://vuepress.vuejs.org)' spiritual successor, built on top of [vite](https://github.com/vitejs/vite).
9
9
 
10
10
  ## Documentation
11
11
 
@@ -13,14 +13,14 @@ To check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org).
13
13
 
14
14
  ## Changelog
15
15
 
16
- Detailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/master/CHANGELOG.md).
16
+ Detailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md).
17
17
 
18
18
  ## Contribution
19
19
 
20
- Please make sure to read the [Contributing Guide](./.github/contributing.md) before making a pull request.
20
+ Please make sure to read the [Contributing Guide](https://github.com/vuejs/vitepress/blob/main/.github/contributing.md) before making a pull request.
21
21
 
22
22
  ## License
23
23
 
24
- [MIT](https://opensource.org/licenses/MIT)
24
+ [MIT](https://github.com/vuejs/vitepress/blob/main/LICENSE)
25
25
 
26
26
  Copyright (c) 2019-present, Yuxi (Evan) You
@@ -5,13 +5,18 @@ export const RouterSymbol = Symbol();
5
5
  // we are just using URL to parse the pathname and hash - the base doesn't
6
6
  // matter and is only passed to support same-host hrefs.
7
7
  const fakeHost = `http://a.com`;
8
+ const notFoundPageData = {
9
+ relativePath: '',
10
+ title: '404',
11
+ description: 'Not Found',
12
+ headers: [],
13
+ frontmatter: {},
14
+ lastUpdated: 0
15
+ };
8
16
  const getDefaultRoute = () => ({
9
17
  path: '/',
10
18
  component: null,
11
- // this will be set upon initial page load, which is before
12
- // the app is mounted, so it's guaranteed to be available in
13
- // components. We just need enough data for 404 pages to render.
14
- data: { frontmatter: {} }
19
+ data: notFoundPageData
15
20
  });
16
21
  export function createRouter(loadPageModule, fallbackComponent) {
17
22
  const route = reactive(getDefaultRoute());
@@ -91,6 +96,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
91
96
  latestPendingPath = null;
92
97
  route.path = pendingPath;
93
98
  route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
99
+ route.data = notFoundPageData;
94
100
  }
95
101
  }
96
102
  }
@@ -153,7 +159,7 @@ export function useRoute() {
153
159
  function scrollTo(el, hash, smooth = false) {
154
160
  let target = null;
155
161
  try {
156
- target = el.classList.contains('.header-anchor')
162
+ target = el.classList.contains('header-anchor')
157
163
  ? el
158
164
  : document.querySelector(decodeURIComponent(hash));
159
165
  }
@@ -54,25 +54,18 @@ const { lang } = useData()
54
54
 
55
55
  // if the user has multiple locales, the search results should be filtered
56
56
  // based on the language
57
- const facetFilters: string[] = props.multilang
58
- ? ['lang:' + lang.value]
59
- : []
57
+ const facetFilters: string[] = props.multilang ? ['lang:' + lang.value] : []
60
58
 
61
59
  if (props.options.searchParameters?.facetFilters) {
62
60
  facetFilters.push(...props.options.searchParameters.facetFilters)
63
61
  }
64
62
 
65
- watch(
66
- lang,
67
- (newLang, oldLang) => {
68
- const index = facetFilters.findIndex(
69
- (filter) => filter === 'lang:' + oldLang
70
- )
71
- if (index > -1) {
72
- facetFilters.splice(index, 1, 'lang:' + newLang)
73
- }
63
+ watch(lang, (newLang, oldLang) => {
64
+ const index = facetFilters.findIndex((filter) => filter === 'lang:' + oldLang)
65
+ if (index > -1) {
66
+ facetFilters.splice(index, 1, 'lang:' + newLang)
74
67
  }
75
- )
68
+ })
76
69
 
77
70
  function initialize(userOptions: any) {
78
71
  docsearch(
@@ -7,7 +7,7 @@ const { theme, page } = useData()
7
7
  const hasLastUpdated = computed(() => {
8
8
  const lu = theme.value.lastUpdated
9
9
 
10
- return lu !== undefined && lu !== false
10
+ return lu !== undefined && lu !== false && page.value.lastUpdated !== 0
11
11
  })
12
12
 
13
13
  const prefix = computed(() => {
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var serve = require('./serve-cf4b2162.js');
3
+ var serve = require('./serve-777539c0.js');
4
4
  require('fs');
5
5
  require('path');
6
6
  require('url');
@@ -11,7 +11,7 @@ export declare function build(root: string, buildOptions?: BuildOptions & {
11
11
  mpa?: string;
12
12
  }): Promise<void>;
13
13
 
14
- export declare const createMarkdownRenderer: (srcDir: string, options?: MarkdownOptions) => MarkdownRenderer;
14
+ export declare const createMarkdownRenderer: (srcDir: string, options: MarkdownOptions | undefined, base: string) => MarkdownRenderer;
15
15
 
16
16
  export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
17
17
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serve = require('./serve-cf4b2162.js');
5
+ var serve = require('./serve-777539c0.js');
6
6
  require('vite');
7
7
  require('readline');
8
8
  require('assert');
@@ -35100,7 +35100,7 @@ const preWrapperPlugin = (md) => {
35100
35100
  };
35101
35101
 
35102
35102
  const indexRE = /(^|.*\/)index.md(#?.*)$/i;
35103
- const linkPlugin = (md, externalAttrs) => {
35103
+ const linkPlugin = (md, externalAttrs, base) => {
35104
35104
  md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
35105
35105
  const token = tokens[idx];
35106
35106
  const hrefIndex = token.attrIndex("href");
@@ -35115,7 +35115,7 @@ const linkPlugin = (md, externalAttrs) => {
35115
35115
  if (url.replace(EXTERNAL_URL_RE, "").startsWith("//localhost:")) {
35116
35116
  pushLink(url);
35117
35117
  }
35118
- } else if (!url.startsWith("#") && !url.startsWith("mailto:")) {
35118
+ } else if (!url.startsWith("#") && !url.startsWith("mailto:") && !/\.(?!html|md)\w+($|\?)/i.test(url)) {
35119
35119
  normalizeHref(hrefAttr);
35120
35120
  }
35121
35121
  hrefAttr[1] = hrefAttr[1].replace(/\bimport\.meta/g, "import%2Emeta").replace(/\bprocess\.env/g, "process%2Eenv");
@@ -35129,7 +35129,7 @@ const linkPlugin = (md, externalAttrs) => {
35129
35129
  const [, path, hash] = indexMatch;
35130
35130
  url = path + hash;
35131
35131
  } else {
35132
- let cleanUrl = url.replace(/\#.*$/, "").replace(/\?.*$/, "");
35132
+ let cleanUrl = url.replace(/[?#].*$/, "");
35133
35133
  if (cleanUrl.endsWith(".md")) {
35134
35134
  cleanUrl = cleanUrl.replace(/\.md$/, ".html");
35135
35135
  }
@@ -35143,6 +35143,9 @@ const linkPlugin = (md, externalAttrs) => {
35143
35143
  url = "./" + url;
35144
35144
  }
35145
35145
  pushLink(url.replace(/\.html$/, ""));
35146
+ if (url.startsWith("/")) {
35147
+ url = `${base}${url}`.replace(/\/+/g, "/");
35148
+ }
35146
35149
  hrefAttr[1] = decodeURI(url);
35147
35150
  }
35148
35151
  function pushLink(link) {
@@ -35171,6 +35174,17 @@ const headingPlugin = (md, include = ["h2", "h3"]) => {
35171
35174
  };
35172
35175
  };
35173
35176
 
35177
+ const imagePlugin = (md) => {
35178
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
35179
+ const token = tokens[idx];
35180
+ const url = token.attrGet("src");
35181
+ if (url && !EXTERNAL_URL_RE.test(url) && !/^\.?\//.test(url)) {
35182
+ token.attrSet("src", "./" + url);
35183
+ }
35184
+ return self.renderToken(tokens, idx, options);
35185
+ };
35186
+ };
35187
+
35174
35188
  var e=!1,n={false:"push",true:"unshift",after:"push",before:"unshift"},t={isPermalinkSymbol:!0};function r(r,a,i,l){var o;if(!e){var c="Using deprecated markdown-it-anchor permalink option, see https://github.com/valeriangalliat/markdown-it-anchor#todo-anchor-or-file";"object"==typeof process&&process&&process.emitWarning?process.emitWarning(c):console.warn(c),e=!0;}var s=[Object.assign(new i.Token("link_open","a",1),{attrs:[].concat(a.permalinkClass?[["class",a.permalinkClass]]:[],[["href",a.permalinkHref(r,i)]],Object.entries(a.permalinkAttrs(r,i)))}),Object.assign(new i.Token("html_block","",0),{content:a.permalinkSymbol,meta:t}),new i.Token("link_close","a",-1)];a.permalinkSpace&&i.tokens[l+1].children[n[a.permalinkBefore]](Object.assign(new i.Token("text","",0),{content:" "})),(o=i.tokens[l+1].children)[n[a.permalinkBefore]].apply(o,s);}function a(e){return "#"+e}function i(e){return {}}var l={class:"header-anchor",symbol:"#",renderHref:a,renderAttrs:i};function o(e){function n(t){return t=Object.assign({},n.defaults,t),function(n,r,a,i){return e(n,t,r,a,i)}}return n.defaults=Object.assign({},l),n.renderPermalinkImpl=e,n}var c=o(function(e,r,a,i,l){var o,c=[Object.assign(new i.Token("link_open","a",1),{attrs:[].concat(r.class?[["class",r.class]]:[],[["href",r.renderHref(e,i)]],r.ariaHidden?[["aria-hidden","true"]]:[],Object.entries(r.renderAttrs(e,i)))}),Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t}),new i.Token("link_close","a",-1)];r.space&&i.tokens[l+1].children[n[r.placement]](Object.assign(new i.Token("text","",0),{content:" "})),(o=i.tokens[l+1].children)[n[r.placement]].apply(o,c);});Object.assign(c.defaults,{space:!0,placement:"after",ariaHidden:!1});var s$1=o(c.renderPermalinkImpl);s$1.defaults=Object.assign({},c.defaults,{ariaHidden:!0});var d$1=o(function(e,n,t,r,a){var i=[Object.assign(new r.Token("link_open","a",1),{attrs:[].concat(n.class?[["class",n.class]]:[],[["href",n.renderHref(e,r)]],Object.entries(n.renderAttrs(e,r)))})].concat(n.safariReaderFix?[new r.Token("span_open","span",1)]:[],r.tokens[a+1].children,n.safariReaderFix?[new r.Token("span_close","span",-1)]:[],[new r.Token("link_close","a",-1)]);r.tokens[a+1]=Object.assign(new r.Token("inline","",0),{children:i});});Object.assign(d$1.defaults,{safariReaderFix:!1});var u=o(function(e,r,a,i,l){var o;if(!["visually-hidden","aria-label","aria-describedby","aria-labelledby"].includes(r.style))throw new Error("`permalink.linkAfterHeader` called with unknown style option `"+r.style+"`");if(!["aria-describedby","aria-labelledby"].includes(r.style)&&!r.assistiveText)throw new Error("`permalink.linkAfterHeader` called without the `assistiveText` option in `"+r.style+"` style");if("visually-hidden"===r.style&&!r.visuallyHiddenClass)throw new Error("`permalink.linkAfterHeader` called without the `visuallyHiddenClass` option in `visually-hidden` style");var c=i.tokens[l+1].children.filter(function(e){return "text"===e.type||"code_inline"===e.type}).reduce(function(e,n){return e+n.content},""),s=[],d=[];r.class&&d.push(["class",r.class]),d.push(["href",r.renderHref(e,i)]),d.push.apply(d,Object.entries(r.renderAttrs(e,i))),"visually-hidden"===r.style?(s.push(Object.assign(new i.Token("span_open","span",1),{attrs:[["class",r.visuallyHiddenClass]]}),Object.assign(new i.Token("text","",0),{content:r.assistiveText(c)}),new i.Token("span_close","span",-1)),r.space&&s[n[r.placement]](Object.assign(new i.Token("text","",0),{content:" "})),s[n[r.placement]](Object.assign(new i.Token("span_open","span",1),{attrs:[["aria-hidden","true"]]}),Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t}),new i.Token("span_close","span",-1))):s.push(Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t})),"aria-label"===r.style?d.push(["aria-label",r.assistiveText(c)]):["aria-describedby","aria-labelledby"].includes(r.style)&&d.push([r.style,e]);var u=[Object.assign(new i.Token("link_open","a",1),{attrs:d})].concat(s,[new i.Token("link_close","a",-1)]);(o=i.tokens).splice.apply(o,[l+3,0].concat(u));});function f(e,n,t,r){var a=e,i=r;if(t&&Object.prototype.hasOwnProperty.call(n,a))throw new Error("User defined `id` attribute `"+e+"` is not unique. Please fix it in your Markdown to continue.");for(;Object.prototype.hasOwnProperty.call(n,a);)a=e+"-"+i,i+=1;return n[a]=!0,a}function b(e,n){n=Object.assign({},b.defaults,n),e.core.ruler.push("anchor",function(e){for(var t,a={},i=e.tokens,l=Array.isArray(n.level)?(t=n.level,function(e){return t.includes(e)}):function(e){return function(n){return n>=e}}(n.level),o=0;o<i.length;o++){var c=i[o];if("heading_open"===c.type&&l(Number(c.tag.substr(1)))){var s=i[o+1].children.filter(function(e){return "text"===e.type||"code_inline"===e.type}).reduce(function(e,n){return e+n.content},""),d=c.attrGet("id");d=null==d?f(n.slugify(s),a,!1,n.uniqueSlugStartIndex):f(d,a,!0,n.uniqueSlugStartIndex),c.attrSet("id",d),!1!==n.tabIndex&&c.attrSet("tabindex",""+n.tabIndex),"function"==typeof n.permalink?n.permalink(d,n,e,o):(n.permalink||n.renderPermalink&&n.renderPermalink!==r)&&n.renderPermalink(d,n,e,o),o=i.indexOf(c),n.callback&&n.callback(c,{slug:d,title:s});}}});}Object.assign(u.defaults,{style:"visually-hidden",space:!0,placement:"after"}),b.permalink={__proto__:null,legacy:r,renderHref:a,renderAttrs:i,makePermalink:o,linkInsideHeader:c,ariaHidden:s$1,headerLink:d$1,linkAfterHeader:u},b.defaults={level:1,slugify:function(e){return encodeURIComponent(String(e).trim().toLowerCase().replace(/\s+/g,"-"))},uniqueSlugStartIndex:1,tabIndex:"-1",permalink:!1,renderPermalink:r,permalinkClass:s$1.defaults.class,permalinkSpace:s$1.defaults.space,permalinkSymbol:"¶",permalinkBefore:"before"===s$1.defaults.placement,permalinkHref:s$1.defaults.renderHref,permalinkAttrs:s$1.defaults.renderAttrs},b.default=b;
35175
35189
 
35176
35190
  var utils$1 = {};
@@ -36446,16 +36460,16 @@ var __spreadValues$2 = (a, b) => {
36446
36460
  }
36447
36461
  return a;
36448
36462
  };
36449
- const createMarkdownRenderer = (srcDir, options = {}) => {
36463
+ const createMarkdownRenderer = (srcDir, options = {}, base) => {
36450
36464
  const md = markdownIt(__spreadValues$2({
36451
36465
  html: true,
36452
36466
  linkify: true,
36453
36467
  highlight
36454
36468
  }, options));
36455
- md.use(componentPlugin).use(highlightLinePlugin).use(preWrapperPlugin).use(snippetPlugin, srcDir).use(hoistPlugin).use(containerPlugin).use(headingPlugin).use(linkPlugin, __spreadValues$2({
36469
+ md.use(componentPlugin).use(highlightLinePlugin).use(preWrapperPlugin).use(snippetPlugin, srcDir).use(hoistPlugin).use(containerPlugin).use(headingPlugin).use(imagePlugin).use(linkPlugin, __spreadValues$2({
36456
36470
  target: "_blank",
36457
36471
  rel: "noopener noreferrer"
36458
- }, options.externalLinks)).use(markdownItAttrs, options.attrs).use(b, __spreadValues$2({
36472
+ }, options.externalLinks), base).use(markdownItAttrs, options.attrs).use(b, __spreadValues$2({
36459
36473
  slugify: slugify$1,
36460
36474
  permalink: b.permalink.ariaHidden({})
36461
36475
  }, options.anchor)).use(markdownItTableOfContents, __spreadValues$2({
@@ -37109,8 +37123,8 @@ function getGitTimestamp(file) {
37109
37123
  const debug$2 = _debug("vitepress:md");
37110
37124
  const cache$1 = new lruCache({ max: 1024 });
37111
37125
  const includesRE = /<!--\s*@include:\s*(.*?)\s*-->/g;
37112
- function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, isBuild = false, includeLastUpdatedData = false) {
37113
- const md = createMarkdownRenderer(srcDir, options);
37126
+ function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, isBuild = false, base, includeLastUpdatedData = false) {
37127
+ const md = createMarkdownRenderer(srcDir, options, base);
37114
37128
  pages = pages.map((p) => slash(p.replace(/\.md$/, "")));
37115
37129
  const userDefineRegex = userDefines ? new RegExp(`\\b(${Object.keys(userDefines).map((key) => key.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&")).join("|")})`, "g") : null;
37116
37130
  return async (src, file, publicDir) => {
@@ -37149,6 +37163,8 @@ function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, i
37149
37163
  if (data.links) {
37150
37164
  const dir2 = path__default["default"].dirname(file);
37151
37165
  for (let url of data.links) {
37166
+ if (/\.(?!html|md)\w+($|\?)/i.test(url))
37167
+ continue;
37152
37168
  if (url.replace(EXTERNAL_URL_RE, "").startsWith("//localhost:")) {
37153
37169
  recordDeadLink(url);
37154
37170
  continue;
@@ -37368,7 +37384,7 @@ function createVitePressPlugin(root, siteConfig, ssr = false, pageToHashMap, cli
37368
37384
  name: "vitepress",
37369
37385
  configResolved(resolvedConfig) {
37370
37386
  config = resolvedConfig;
37371
- markdownToVue = createMarkdownToVueRenderFn(srcDir, markdown, pages, config.define, config.command === "build", siteConfig.lastUpdated);
37387
+ markdownToVue = createMarkdownToVueRenderFn(srcDir, markdown, pages, config.define, config.command === "build", config.base, siteConfig.lastUpdated);
37372
37388
  },
37373
37389
  config() {
37374
37390
  var _a, _b;
@@ -40963,7 +40979,7 @@ function renderHead(head) {
40963
40979
  return Promise.all(head.map(async ([tag, attrs = {}, innerHTML = ""]) => {
40964
40980
  const openTag = `<${tag}${renderAttrs(attrs)}>`;
40965
40981
  if (tag !== "link" && tag !== "meta") {
40966
- if (tag === "script") {
40982
+ if (tag === "script" && (attrs.type === void 0 || attrs.type.includes("javascript"))) {
40967
40983
  innerHTML = (await vite.transformWithEsbuild(innerHTML, "inline-script.js", {
40968
40984
  minify: true
40969
40985
  })).code.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitepress",
3
- "version": "0.22.2",
3
+ "version": "0.22.3",
4
4
  "description": "Vite & Vue powered static site generator",
5
5
  "main": "dist/node/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "theme.d.ts"
16
16
  ],
17
17
  "engines": {
18
- "node": ">=12.0.0"
18
+ "node": ">=14.0.0"
19
19
  },
20
20
  "gitHooks": {
21
21
  "pre-commit": "lint-staged"
@@ -134,5 +134,5 @@
134
134
  "docs-serve": "node ./bin/vitepress serve docs",
135
135
  "ci-docs": "run-s build docs-build"
136
136
  },
137
- "readme": "# (WIP) VitePress 📝💨\n\n[![Test](https://github.com/vuejs/vitepress/workflows/Test/badge.svg)](https://github.com/vuejs/vitepress/actions)\n[![npm](https://img.shields.io/npm/v/vitepress)](https://www.npmjs.com/package/vitepress)\n\n---\n\nVitePress is [VuePress](http://vuepress.vuejs.org/)' spiritual successor, built on top of [vite](https://github.com/vuejs/vite).\n\n## Documentation\n\nTo check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org).\n\n## Changelog\n\nDetailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/master/CHANGELOG.md).\n\n## Contribution\n\nPlease make sure to read the [Contributing Guide](./.github/contributing.md) before making a pull request.\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nCopyright (c) 2019-present, Yuxi (Evan) You\n"
137
+ "readme": "# (WIP) VitePress 📝💨\n\n[![Test](https://github.com/vuejs/vitepress/workflows/Test/badge.svg)](https://github.com/vuejs/vitepress/actions)\n[![npm](https://img.shields.io/npm/v/vitepress)](https://www.npmjs.com/package/vitepress)\n\n---\n\nVitePress is [VuePress](https://vuepress.vuejs.org)' spiritual successor, built on top of [vite](https://github.com/vitejs/vite).\n\n## Documentation\n\nTo check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org).\n\n## Changelog\n\nDetailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md).\n\n## Contribution\n\nPlease make sure to read the [Contributing Guide](https://github.com/vuejs/vitepress/blob/main/.github/contributing.md) before making a pull request.\n\n## License\n\n[MIT](https://github.com/vuejs/vitepress/blob/main/LICENSE)\n\nCopyright (c) 2019-present, Yuxi (Evan) You\n"
138
138
  }