valaxy 1.0.0-rc.2 → 1.0.0-rc.4

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.
@@ -4,6 +4,7 @@ import pkg from '../../../package.json' with { type: 'json' }
4
4
 
5
5
  import { useFrontmatter, useValaxyI18n } from '../../composables'
6
6
  import { useSiteConfig } from '../../config'
7
+ import { withBase } from '../../utils'
7
8
 
8
9
  export function useValaxyHead() {
9
10
  const { $t, $tO, locale } = useValaxyI18n()
@@ -24,7 +25,7 @@ export function useValaxyHead() {
24
25
  link: [
25
26
  {
26
27
  rel: 'icon',
27
- href: siteConfig.value.favicon,
28
+ href: withBase(siteConfig.value.favicon),
28
29
  type: siteConfig.value.favicon?.endsWith('svg') ? 'image/svg+xml' : 'image/png',
29
30
  },
30
31
  ],
@@ -4,6 +4,7 @@ export * from './code'
4
4
  export * from './content'
5
5
  export * from './helper'
6
6
  export * from './iframe'
7
+ export * from './path'
7
8
  export * from './router'
8
9
  export * from './time'
9
10
  export * from './types'
@@ -0,0 +1,18 @@
1
+ import { EXTERNAL_URL_RE } from '../../shared'
2
+
3
+ /**
4
+ * Join two URL paths while resolving a slash collision.
5
+ */
6
+ function joinPath(base: string, path: string): string {
7
+ return `${base}${path}`.replace(/\/+/g, '/')
8
+ }
9
+
10
+ /**
11
+ * Append Vite's resolved base to an internal root-absolute URL.
12
+ * External and relative URLs are returned unchanged.
13
+ */
14
+ export function withBase(path: string): string {
15
+ return EXTERNAL_URL_RE.test(path) || !path.startsWith('/')
16
+ ? path
17
+ : joinPath(import.meta.env.BASE_URL, path)
18
+ }
@@ -1,7 +1,7 @@
1
1
  import 'node:process';
2
2
  import 'yargs';
3
3
  import 'yargs/helpers';
4
- export { c as cli, I as registerDevCommand, W as run, Y as startValaxyDev } from '../../shared/valaxy.gIHfh4CV.mjs';
4
+ export { c as cli, I as registerDevCommand, W as run, Y as startValaxyDev } from '../../shared/valaxy.Dj-g4l0F.mjs';
5
5
  import 'node:os';
6
6
  import 'node:path';
7
7
  import 'consola';
@@ -1091,7 +1091,7 @@ declare function resolveOptions(options?: ValaxyEntryOptions, mode?: ResolvedVal
1091
1091
  */
1092
1092
  declare function resolveThemeValaxyConfig(options: ResolvedValaxyOptions): Promise<ValaxyNodeConfig>;
1093
1093
 
1094
- declare function ViteValaxyPlugins(valaxyApp: ValaxyNode, serverOptions?: ValaxyServerOptions): Promise<(PluginOption | PluginOption[])[]>;
1094
+ declare function ViteValaxyPlugins(valaxyApp: ValaxyNode, serverOptions?: ValaxyServerOptions, viteConfig?: InlineConfig): Promise<(PluginOption | PluginOption[])[]>;
1095
1095
 
1096
1096
  /**
1097
1097
  * @packageDocumentation valaxy plugin
@@ -1,4 +1,4 @@
1
- export { A as ALL_ROUTE, E as EXCERPT_SEPARATOR, G as GLOBAL_STATE, P as PATHNAME_PROTOCOL_RE, V as ViteValaxyPlugins, b as build, c as cli, a as createServer, d as createValaxyPlugin, e as customElements, f as defaultSiteConfig, g as defaultValaxyConfig, h as defaultViteConfig, i as defineAddon, j as defineConfig, k as defineSiteConfig, l as defineTheme, m as defineValaxyAddon, n as defineValaxyConfig, o as defineValaxyTheme, p as encryptContent, q as generateClientRedirects, r as getGitTimestamp, s as getIndexHtml, t as getServerInfoText, u as isExternal, v as isInstalledGlobally, w as isKatexEnabled, x as isKatexPluginNeeded, y as isMathJaxEnabled, z as isPath, B as loadConfigFromFile, C as mergeValaxyConfig, D as mergeViteConfigs, F as postProcessForSSG, H as processValaxyOptions, I as registerDevCommand, J as resolveAddonsConfig, K as resolveImportPath, L as resolveImportUrl, M as resolveOptions, N as resolveSiteConfig, O as resolveSiteConfigFromRoot, Q as resolveThemeConfigFromRoot, R as resolveThemeValaxyConfig, S as resolveUserThemeConfig, T as resolveValaxyConfig, U as resolveValaxyConfigFromRoot, W as run, X as ssgBuild, Y as startValaxyDev, Z as toAtFS, _ as transformObject, $ as version } from '../shared/valaxy.gIHfh4CV.mjs';
1
+ export { A as ALL_ROUTE, E as EXCERPT_SEPARATOR, G as GLOBAL_STATE, P as PATHNAME_PROTOCOL_RE, V as ViteValaxyPlugins, b as build, c as cli, a as createServer, d as createValaxyPlugin, e as customElements, f as defaultSiteConfig, g as defaultValaxyConfig, h as defaultViteConfig, i as defineAddon, j as defineConfig, k as defineSiteConfig, l as defineTheme, m as defineValaxyAddon, n as defineValaxyConfig, o as defineValaxyTheme, p as encryptContent, q as generateClientRedirects, r as getGitTimestamp, s as getIndexHtml, t as getServerInfoText, u as isExternal, v as isInstalledGlobally, w as isKatexEnabled, x as isKatexPluginNeeded, y as isMathJaxEnabled, z as isPath, B as loadConfigFromFile, C as mergeValaxyConfig, D as mergeViteConfigs, F as postProcessForSSG, H as processValaxyOptions, I as registerDevCommand, J as resolveAddonsConfig, K as resolveImportPath, L as resolveImportUrl, M as resolveOptions, N as resolveSiteConfig, O as resolveSiteConfigFromRoot, Q as resolveThemeConfigFromRoot, R as resolveThemeValaxyConfig, S as resolveUserThemeConfig, T as resolveValaxyConfig, U as resolveValaxyConfigFromRoot, W as run, X as ssgBuild, Y as startValaxyDev, Z as toAtFS, _ as transformObject, $ as version } from '../shared/valaxy.Dj-g4l0F.mjs';
2
2
  import 'node:path';
3
3
  import 'consola';
4
4
  import 'fs-extra';
@@ -2017,12 +2017,33 @@ const tocPlugin = (md, { pattern = /^\[\[toc\]\]$/i, slugify: slugify$1 = slugif
2017
2017
  }));
2018
2018
  };
2019
2019
 
2020
+ function createMarkdownBaseContext(base = "/") {
2021
+ return { value: base };
2022
+ }
2023
+ function createMarkdownBaseResolver(base) {
2024
+ return typeof base === "string" ? () => base : () => base.value;
2025
+ }
2026
+
2020
2027
  function isPromiseLike(v) {
2021
2028
  return typeof v === "object" && v !== null && typeof v.then === "function";
2022
2029
  }
2023
2030
 
2031
+ function imagePlugin(md) {
2032
+ const imageRule = md.renderer.rules.image;
2033
+ md.renderer.rules.image = (tokens, idx, options, env, self) => {
2034
+ const token = tokens[idx];
2035
+ let url = token.attrGet("src");
2036
+ if (url && !EXTERNAL_URL_RE.test(url)) {
2037
+ if (!/^\.?\//.test(url))
2038
+ url = `./${url}`;
2039
+ token.attrSet("src", decodeURIComponent(url));
2040
+ }
2041
+ return imageRule(tokens, idx, options, env, self);
2042
+ };
2043
+ }
2044
+
2024
2045
  const indexRE = /(^|.*\/)index.md(.*)$/i;
2025
- function linkPlugin(md, externalAttrs, base) {
2046
+ function linkPlugin(md, externalAttrs, resolveBase) {
2026
2047
  md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
2027
2048
  const token = tokens[idx];
2028
2049
  const hrefIndex = token.attrIndex("href");
@@ -2035,11 +2056,15 @@ function linkPlugin(md, externalAttrs, base) {
2035
2056
  token.attrSet(key, val);
2036
2057
  });
2037
2058
  hrefAttr[1] = url.replace(PATHNAME_PROTOCOL_RE, "");
2038
- } else if (
2039
- // internal anchor links
2040
- !url.startsWith("#") && !url.startsWith("mailto:") && !/\.(?!html|md)\w+($|\?)/i.test(url)
2041
- ) {
2042
- normalizeHref(hrefAttr, env);
2059
+ } else {
2060
+ if (
2061
+ // internal anchor links
2062
+ !url.startsWith("#") && !url.startsWith("mailto:") && !/\.(?!html|md)\w+($|[?#])/i.test(url)
2063
+ ) {
2064
+ normalizeHref(hrefAttr, env);
2065
+ }
2066
+ if (hrefAttr[1].startsWith("/"))
2067
+ hrefAttr[1] = `${resolveBase()}${hrefAttr[1]}`.replace(/\/+/g, "/");
2043
2068
  }
2044
2069
  hrefAttr[1] = hrefAttr[1].replace(/\bimport\.meta/g, "import%2Emeta").replace(/\bprocess\.env/g, "process%2Eenv");
2045
2070
  }
@@ -2068,8 +2093,6 @@ function linkPlugin(md, externalAttrs, base) {
2068
2093
  if (!url.startsWith("/") && !/^\.\//.test(url))
2069
2094
  url = `./${url}`;
2070
2095
  pushLink(url.replace(/\.html$/, ""), env);
2071
- if (url.startsWith("/"))
2072
- url = `${base}${url}`.replace(/\/+/g, "/");
2073
2096
  hrefAttr[1] = decodeURI(url);
2074
2097
  }
2075
2098
  function pushLink(link, env) {
@@ -2585,10 +2608,11 @@ function snippetPlugin(md, srcDir) {
2585
2608
  }
2586
2609
 
2587
2610
  const defaultCodeTheme = { light: "github-light", dark: "github-dark" };
2588
- async function setupMarkdownPlugins(md, options, base = "/") {
2611
+ async function setupMarkdownPlugins(md, options, base = options?.config.vite?.base || "/") {
2589
2612
  const mdOptions = options?.config.markdown || {};
2590
2613
  const theme = mdOptions.theme ?? defaultCodeTheme;
2591
2614
  const siteConfig = options?.config.siteConfig || {};
2615
+ const resolveBase = createMarkdownBaseResolver(base);
2592
2616
  if (mdOptions.preConfig)
2593
2617
  mdOptions.preConfig(md);
2594
2618
  md.use(highlightLinePlugin).use(preWrapperPlugin, { theme, siteConfig }).use(snippetPlugin, options?.userRoot).use(containerPlugin, {
@@ -2607,8 +2631,8 @@ async function setupMarkdownPlugins(md, options, base = "/") {
2607
2631
  rel: "noreferrer",
2608
2632
  ...mdOptions.externalLinks
2609
2633
  },
2610
- base
2611
- );
2634
+ resolveBase
2635
+ ).use(imagePlugin);
2612
2636
  md.use(lineNumberPlugin, mdOptions.lineNumbers);
2613
2637
  if (!mdOptions.attrs?.disable)
2614
2638
  md.use(attrsPlugin, mdOptions.attrs);
@@ -2727,7 +2751,7 @@ async function setupMarkdownPlugins(md, options, base = "/") {
2727
2751
  return md;
2728
2752
  }
2729
2753
 
2730
- const version = "1.0.0-rc.2";
2754
+ const version = "1.0.0-rc.4";
2731
2755
 
2732
2756
  const GLOBAL_STATE = {
2733
2757
  valaxyApp: void 0,
@@ -2841,7 +2865,7 @@ function disposeMdItInstance() {
2841
2865
  _disposeHighlighter$1?.();
2842
2866
  _disposeHighlighter$1 = void 0;
2843
2867
  }
2844
- async function createMarkdownPlugin(options) {
2868
+ async function createMarkdownPlugin(options, base) {
2845
2869
  const mdOptions = options?.config.markdown || {};
2846
2870
  const theme = mdOptions.theme ?? defaultCodeTheme;
2847
2871
  const transformIncludes = createTransformIncludes(options);
@@ -2876,7 +2900,7 @@ async function createMarkdownPlugin(options) {
2876
2900
  },
2877
2901
  async markdownItSetup(mdIt) {
2878
2902
  mdIt.linkify.set({ fuzzyLink: false });
2879
- await setupMarkdownPlugins(mdIt, options);
2903
+ await setupMarkdownPlugins(mdIt, options, base);
2880
2904
  options?.config.markdown?.markdownItSetup?.(mdIt);
2881
2905
  function initEnv(md) {
2882
2906
  md.core.ruler.push("valaxy_md_env", (state) => {
@@ -2912,7 +2936,7 @@ function disposePreviewMdItInstance() {
2912
2936
  _disposeHighlighter?.();
2913
2937
  _disposeHighlighter = void 0;
2914
2938
  }
2915
- async function createLightMarkdownRenderer(options) {
2939
+ async function createLightMarkdownRenderer(options, base) {
2916
2940
  const mdOptions = options?.config.markdown || {};
2917
2941
  const highlight = (str, _lang, _attrs) => {
2918
2942
  const escaped = str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -2925,14 +2949,14 @@ async function createLightMarkdownRenderer(options) {
2925
2949
  highlight
2926
2950
  });
2927
2951
  md.linkify.set({ fuzzyLink: false });
2928
- await setupMarkdownPlugins(md, options);
2952
+ await setupMarkdownPlugins(md, options, base);
2929
2953
  return md;
2930
2954
  }
2931
2955
 
2932
2956
  const debug$2 = _debug("valaxy:local-search");
2933
2957
  const LOCAL_SEARCH_INDEX_ID = "@localSearchIndex";
2934
2958
  const LOCAL_SEARCH_INDEX_REQUEST_PATH = `/${LOCAL_SEARCH_INDEX_ID}`;
2935
- async function localSearchPlugin(options) {
2959
+ async function localSearchPlugin(options, base) {
2936
2960
  const siteConfig = options.config.siteConfig;
2937
2961
  if (siteConfig.search?.provider !== "local") {
2938
2962
  return {
@@ -2951,7 +2975,7 @@ async function localSearchPlugin(options) {
2951
2975
  }
2952
2976
  const srcDir = path.resolve(options.userRoot, "pages");
2953
2977
  const originalPages = options.pages;
2954
- const md = await createLightMarkdownRenderer(options);
2978
+ const md = await createLightMarkdownRenderer(options, base);
2955
2979
  async function render(file) {
2956
2980
  if (!fs.existsSync(file))
2957
2981
  return "";
@@ -4467,11 +4491,11 @@ function generateAutoExcerptMd(content, length) {
4467
4491
  return "";
4468
4492
  return cleaned.length > length ? `${cleaned.slice(0, length)}...` : cleaned;
4469
4493
  }
4470
- async function createRouterPlugin(valaxyApp) {
4494
+ async function createRouterPlugin(valaxyApp, base) {
4471
4495
  const { options } = valaxyApp;
4472
4496
  const { roots, config: valaxyConfig } = options;
4473
4497
  const mdIt = new MarkdownItAsync({ html: true });
4474
- await setupMarkdownPlugins(mdIt, options);
4498
+ await setupMarkdownPlugins(mdIt, options, base);
4475
4499
  let _lastFrontmatterRef = valaxyConfig.siteConfig.frontmatter;
4476
4500
  let _cachedFrontmatter = structuredClone(valaxyConfig.siteConfig.frontmatter);
4477
4501
  return VueRouter({
@@ -4629,9 +4653,17 @@ async function createRouterPlugin(valaxyApp) {
4629
4653
  });
4630
4654
  }
4631
4655
 
4632
- async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4656
+ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {}) {
4633
4657
  const { options } = valaxyApp;
4634
4658
  const { roots, config: valaxyConfig } = options;
4659
+ const markdownBase = createMarkdownBaseContext(viteConfig.base || valaxyConfig.vite?.base || "/");
4660
+ const MarkdownBasePlugin = {
4661
+ name: "valaxy:markdown-base",
4662
+ enforce: "pre",
4663
+ configResolved(config) {
4664
+ markdownBase.value = config.base;
4665
+ }
4666
+ };
4635
4667
  const timers = {
4636
4668
  markdown: countPerformanceTime(),
4637
4669
  valaxy: countPerformanceTime(),
@@ -4650,7 +4682,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4650
4682
  LocalSearchPlugin,
4651
4683
  scannedTitles
4652
4684
  ] = await Promise.all([
4653
- createMarkdownPlugin(options).then((r) => {
4685
+ createMarkdownPlugin(options, markdownBase).then((r) => {
4654
4686
  vLogger.debug(` \u251C\u2500 createMarkdownPlugin: ${timers.markdown()}`);
4655
4687
  return r;
4656
4688
  }),
@@ -4681,7 +4713,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4681
4713
  vLogger.debug(` \u251C\u2500 plugin-vue: ${timers.vue()}`);
4682
4714
  return r;
4683
4715
  }),
4684
- createRouterPlugin(valaxyApp).then((r) => {
4716
+ createRouterPlugin(valaxyApp, markdownBase).then((r) => {
4685
4717
  vLogger.debug(` \u251C\u2500 createRouterPlugin: ${timers.router()}`);
4686
4718
  return r;
4687
4719
  }),
@@ -4689,7 +4721,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4689
4721
  vLogger.debug(` \u251C\u2500 createUnocssPlugin: ${timers.unocss()}`);
4690
4722
  return r;
4691
4723
  }),
4692
- localSearchPlugin(options).then((r) => {
4724
+ localSearchPlugin(options, markdownBase).then((r) => {
4693
4725
  vLogger.debug(` \u251C\u2500 localSearchPlugin: ${timers.localSearch()}`);
4694
4726
  return r;
4695
4727
  }),
@@ -4700,6 +4732,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4700
4732
  ]);
4701
4733
  const componentsDirs = [...roots.map((root) => `${root}/components`), ...["src/components", "components"]];
4702
4734
  const plugins = [
4735
+ MarkdownBasePlugin,
4703
4736
  createCdnPlugin(options),
4704
4737
  createLlmsPlugin(options),
4705
4738
  MarkdownPlugin,
@@ -5000,7 +5033,7 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
5000
5033
  const ssgTemp = resolve$1(outDir, ".vite-ssg-temp");
5001
5034
  const defaultConfig = {
5002
5035
  ...defaultViteConfig,
5003
- plugins: await ViteValaxyPlugins(valaxyApp),
5036
+ plugins: await ViteValaxyPlugins(valaxyApp, {}, viteConfig),
5004
5037
  // `ssr.noExternal` only affects the server build (step 2) — the client build
5005
5038
  // ignores it. See `getSsgSsrConfig` for why everything is bundled.
5006
5039
  ssr: getSsgSsrConfig(),
@@ -5089,7 +5122,7 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
5089
5122
  async function build$1(valaxyApp, viteConfig = defaultViteConfig) {
5090
5123
  const inlineConfig = mergeConfig(viteConfig, {
5091
5124
  ...defaultViteConfig,
5092
- plugins: await ViteValaxyPlugins(valaxyApp)
5125
+ plugins: await ViteValaxyPlugins(valaxyApp, {}, viteConfig)
5093
5126
  });
5094
5127
  await build$3(inlineConfig);
5095
5128
  }
@@ -5796,7 +5829,7 @@ async function createServer(valaxyApp, viteConfig = {}, serverOptions = {}) {
5796
5829
  process.env.EDITOR = process.env.EDITOR || "code";
5797
5830
  const { options } = valaxyApp;
5798
5831
  const pluginsTimer = countPerformanceTime();
5799
- const plugins = await ViteValaxyPlugins(valaxyApp, serverOptions);
5832
+ const plugins = await ViteValaxyPlugins(valaxyApp, serverOptions, viteConfig);
5800
5833
  vLogger.debug(`ViteValaxyPlugins: ${pluginsTimer()}`);
5801
5834
  const enableDevtools = options.config.devtools;
5802
5835
  const vitePlugins = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valaxy",
3
3
  "type": "module",
4
- "version": "1.0.0-rc.2",
4
+ "version": "1.0.0-rc.4",
5
5
  "description": "📄 Vite & Vue powered static blog generator.",
6
6
  "author": {
7
7
  "email": "me@yunyoujun.cn",
@@ -139,8 +139,8 @@
139
139
  "vitepress-plugin-group-icons": "^1.7.5",
140
140
  "vue-i18n": "^11.4.6",
141
141
  "yargs": "^18.0.0",
142
- "@valaxyjs/devtools": "1.0.0-rc.2",
143
- "@valaxyjs/utils": "1.0.0-rc.2"
142
+ "@valaxyjs/devtools": "1.0.0-rc.4",
143
+ "@valaxyjs/utils": "1.0.0-rc.4"
144
144
  },
145
145
  "devDependencies": {
146
146
  "@mdit-vue/plugin-component": "^3.0.2",