valaxy 0.24.5 → 0.25.0

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.
@@ -1,6 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import { computed } from 'vue'
3
3
  import { useI18n } from 'vue-i18n'
4
+ import { useValaxyI18n } from '../composables'
4
5
  import { useSiteConfig } from '../config'
5
6
 
6
7
  withDefaults(defineProps<{
@@ -10,6 +11,7 @@ withDefaults(defineProps<{
10
11
  })
11
12
 
12
13
  const { t, locale } = useI18n()
14
+ const { $t } = useValaxyI18n()
13
15
 
14
16
  const siteConfig = useSiteConfig()
15
17
 
@@ -31,7 +33,7 @@ const licenseHtml = computed(() => {
31
33
  <strong>
32
34
  {{ t('post.copyright.author') + t('symbol.colon') }}
33
35
  </strong>
34
- <span>{{ t(siteConfig.author.name) }}</span>
36
+ <span>{{ $t(siteConfig.author.name) }}</span>
35
37
  </li>
36
38
  <li v-if="url" class="post-copyright-link">
37
39
  <strong>
@@ -6,7 +6,7 @@ import { computed } from 'vue'
6
6
  import { useI18n } from 'vue-i18n'
7
7
 
8
8
  import { tObject } from '../../../shared/utils/i18n'
9
- import { useFrontmatter, useValaxyHead } from '../../composables'
9
+ import { useFrontmatter, useValaxyHead, useValaxyI18n } from '../../composables'
10
10
 
11
11
  import { useTimezone } from '../../composables/global'
12
12
  // https://github.com/vueuse/head
@@ -20,6 +20,7 @@ export function useValaxyApp() {
20
20
  const fm = useFrontmatter()
21
21
 
22
22
  const { locale } = useI18n()
23
+ const { $t } = useValaxyI18n()
23
24
 
24
25
  const title = computed(() => tObject(fm.value.title || '', locale.value))
25
26
 
@@ -45,7 +46,7 @@ export function useValaxyApp() {
45
46
  // https://unhead.unjs.io/docs/schema-org/guides/recipes/identity
46
47
  // Personal Website or Blog
47
48
  definePerson({
48
- name: siteConfig.value.author.name,
49
+ name: $t(siteConfig.value.author.name),
49
50
  url: siteUrl.value,
50
51
  image: siteConfig.value.author.avatar,
51
52
  sameAs: siteConfig.value.social.map(s => s.link),
@@ -3,12 +3,13 @@ import pkg from 'valaxy/package.json'
3
3
  import { computed } from 'vue'
4
4
  import { useI18n } from 'vue-i18n'
5
5
 
6
- import { useFrontmatter } from '../../composables'
6
+ import { useFrontmatter, useValaxyI18n } from '../../composables'
7
7
  import { useSiteConfig } from '../../config'
8
8
  import { tObject } from '../../utils'
9
9
 
10
10
  export function useValaxyHead() {
11
- const { locale, t } = useI18n()
11
+ const { locale } = useI18n()
12
+ const { $t } = useValaxyI18n()
12
13
 
13
14
  const fm = useFrontmatter()
14
15
  const siteConfig = useSiteConfig()
@@ -17,7 +18,7 @@ export function useValaxyHead() {
17
18
  useHead({
18
19
  title: $title,
19
20
  titleTemplate: (title) => {
20
- const siteTitle = t(siteConfig.value.title)
21
+ const siteTitle = $t(siteConfig.value.title)
21
22
  return fm.value.titleTemplate || (title ? `${title} - ${siteTitle}` : siteTitle)
22
23
  },
23
24
  link: [
@@ -6,6 +6,7 @@ import { computed } from 'vue'
6
6
  // not optimize deps all locales
7
7
  import { useI18n } from 'vue-i18n'
8
8
  import { tObject } from '../../shared/utils/i18n'
9
+ import { LOCALE_PREFIX } from '../utils'
9
10
  import 'dayjs/locale/en'
10
11
  import 'dayjs/locale/zh-cn'
11
12
 
@@ -63,3 +64,23 @@ export function useLocaleTitle(fm: Ref<{
63
64
  return tObject(fm.value.title || '', lang) || ''
64
65
  })
65
66
  }
67
+
68
+ /**
69
+ * @experimental
70
+ * 以 `$locale:` 开头的 key 会被认为是国际化的 key
71
+ * 会从 locales/ 目录中获取对应的翻译
72
+ */
73
+ export function useValaxyI18n() {
74
+ const { t, locale } = useI18n()
75
+
76
+ return {
77
+ locale,
78
+
79
+ $t: (key: string) => {
80
+ if (key.startsWith(LOCALE_PREFIX)) {
81
+ return t(key.slice(LOCALE_PREFIX.length))
82
+ }
83
+ return key
84
+ },
85
+ }
86
+ }
@@ -4,7 +4,7 @@ import yargs from "yargs";
4
4
  import { hideBin } from "yargs/helpers";
5
5
 
6
6
  // package.json
7
- var version = "0.24.5";
7
+ var version = "0.25.0";
8
8
 
9
9
  // node/modules/fuse.ts
10
10
  import path4 from "path";
@@ -537,6 +537,11 @@ function transformObject(obj) {
537
537
  return `JSON.parse(${JSON.stringify(JSON.stringify(obj))})`;
538
538
  }
539
539
 
540
+ // node/utils/i18n.ts
541
+ function $t(key) {
542
+ return `$locale:${key}`;
543
+ }
544
+
540
545
  // node/utils/resolve.ts
541
546
  import { ensurePrefix, slash } from "@antfu/utils";
542
547
  import { consola as consola6 } from "consola";
@@ -2140,7 +2145,7 @@ function containerPlugin(md3, containerOptions = {}) {
2140
2145
  ` : `</div>
2141
2146
  `
2142
2147
  });
2143
- const languages = ["zh-CN", "en"];
2148
+ const languages = containerOptions.siteConfig?.languages || ["zh-CN", "en"];
2144
2149
  languages.forEach((lang) => {
2145
2150
  md3.use(container, lang, {
2146
2151
  render: (tokens, idx) => tokens[idx].nesting === 1 ? `<div lang="${lang}">
@@ -2556,6 +2561,7 @@ async function setupMarkdownPlugins(md3, options, base = "/") {
2556
2561
  if (mdOptions.preConfig)
2557
2562
  mdOptions.preConfig(md3);
2558
2563
  md3.use(highlightLinePlugin).use(preWrapperPlugin, { theme, siteConfig }).use(snippetPlugin, options?.userRoot).use(containerPlugin, {
2564
+ siteConfig,
2559
2565
  ...mdOptions.blocks,
2560
2566
  ...mdOptions?.container
2561
2567
  }).use(cssI18nContainer, {
@@ -3089,7 +3095,7 @@ var templateConfig = {
3089
3095
  import fs16 from "fs-extra";
3090
3096
  var templateLocales = {
3091
3097
  id: "/@valaxyjs/locales",
3092
- async getContent({ roots }) {
3098
+ async getContent({ roots, config }) {
3093
3099
  const imports = [
3094
3100
  'import { createDefu } from "defu"',
3095
3101
  'const messages = { "zh-CN": {}, en: {} }',
@@ -3102,7 +3108,7 @@ var templateLocales = {
3102
3108
  })
3103
3109
  `
3104
3110
  ];
3105
- const languages = ["zh-CN", "en"];
3111
+ const languages = config.siteConfig.languages || ["zh-CN", "en"];
3106
3112
  roots.forEach((root, i) => {
3107
3113
  languages.forEach((lang) => {
3108
3114
  const langYml = `${root}/locales/${lang}.yml`;
@@ -4064,7 +4070,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4064
4070
  console.log();
4065
4071
  }
4066
4072
  }
4067
- const customIcon = {
4073
+ const builtinCustomIcon = {
4068
4074
  nodejs: "vscode-icons:file-type-node",
4069
4075
  playwright: "vscode-icons:file-type-playwright",
4070
4076
  typedoc: "vscode-icons:file-type-typedoc",
@@ -4072,10 +4078,13 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
4072
4078
  };
4073
4079
  plugins.push(
4074
4080
  groupIconVitePlugin({
4075
- customIcon,
4076
- ...valaxyConfig.groupIcons,
4081
+ customIcon: {
4082
+ ...builtinCustomIcon,
4083
+ ...valaxyConfig.groupIcons?.customIcon
4084
+ },
4077
4085
  defaultLabels: [
4078
4086
  ...valaxyConfig.groupIcons?.defaultLabels || [],
4087
+ ...Object.keys(builtinCustomIcon),
4079
4088
  ...Object.keys(valaxyConfig.groupIcons?.customIcon || {})
4080
4089
  ]
4081
4090
  })
@@ -4809,6 +4818,7 @@ export {
4809
4818
  isExternal,
4810
4819
  isPath,
4811
4820
  transformObject,
4821
+ $t,
4812
4822
  isInstalledGlobally,
4813
4823
  resolveImportUrl,
4814
4824
  toAtFS,
@@ -3,7 +3,7 @@ import {
3
3
  registerDevCommand,
4
4
  run,
5
5
  startValaxyDev
6
- } from "../../chunk-OA6SKHSD.js";
6
+ } from "../../chunk-VNLGPNVS.js";
7
7
  export {
8
8
  cli,
9
9
  registerDevCommand,
@@ -653,6 +653,16 @@ declare function isPath(name: string): boolean;
653
653
  */
654
654
  declare function transformObject(obj: any): string;
655
655
 
656
+ /**
657
+ * @experimental 试验性
658
+ * @see https://github.com/YunYouJun/valaxy/issues/566
659
+ * @param key
660
+ *
661
+ * 声明这是一个使用国际化的 key
662
+ * 从 locales/ 目录中获取对应的翻译
663
+ */
664
+ declare function $t(key: string): string;
665
+
656
666
  declare const isInstalledGlobally: {
657
667
  value?: boolean;
658
668
  };
@@ -668,4 +678,4 @@ declare function toAtFS(path: string): string;
668
678
  declare function resolveImportPath(importName: string, ensure?: true): Promise<string>;
669
679
  declare function resolveImportPath(importName: string, ensure?: boolean): Promise<string | undefined>;
670
680
 
671
- export { ALL_ROUTE, EXCERPT_SEPARATOR, type HookResult, type LoadConfigFromFileOptions, PATHNAME_PROTOCOL_RE, type ResolvedConfig, type ResolvedValaxyOptions, type UnoSetup, type UserInputConfig, type UserValaxyNodeConfig, type ValaxyAddonExport, type ValaxyAddonFn, type ValaxyAddonLike, type ValaxyAddonResolver, type ValaxyAddons, type ValaxyApp, type ValaxyConfigExport, type ValaxyConfigExtendKey, type ValaxyConfigFn, type ValaxyEntryOptions, type ValaxyExtendConfig, type ValaxyHooks, type ValaxyNode, type ValaxyNodeConfig, type ValaxyPickConfig, type ValaxyServerOptions, type ValaxyTheme, ViteValaxyPlugins, build, createServer, createValaxyPlugin, customElements, defaultSiteConfig, defaultValaxyConfig, defaultViteConfig, defineAddon, defineConfig, defineSiteConfig, defineTheme, defineUnoSetup, defineValaxyAddon, defineValaxyConfig, defineValaxyTheme, generateClientRedirects, getGitTimestamp, getIndexHtml, getServerInfoText, isExternal, isInstalledGlobally, isPath, loadConfig, loadConfigFromFile, mergeValaxyConfig, mergeViteConfigs, postProcessForSSG, processValaxyOptions, resolveAddonsConfig, resolveImportPath, resolveImportUrl, resolveOptions, resolveSiteConfig, resolveSiteConfigFromRoot, resolveThemeConfigFromRoot, resolveThemeValaxyConfig, resolveUserThemeConfig, resolveValaxyConfig, resolveValaxyConfigFromRoot, ssgBuild, toAtFS, transformObject };
681
+ export { $t, ALL_ROUTE, EXCERPT_SEPARATOR, type HookResult, type LoadConfigFromFileOptions, PATHNAME_PROTOCOL_RE, type ResolvedConfig, type ResolvedValaxyOptions, type UnoSetup, type UserInputConfig, type UserValaxyNodeConfig, type ValaxyAddonExport, type ValaxyAddonFn, type ValaxyAddonLike, type ValaxyAddonResolver, type ValaxyAddons, type ValaxyApp, type ValaxyConfigExport, type ValaxyConfigExtendKey, type ValaxyConfigFn, type ValaxyEntryOptions, type ValaxyExtendConfig, type ValaxyHooks, type ValaxyNode, type ValaxyNodeConfig, type ValaxyPickConfig, type ValaxyServerOptions, type ValaxyTheme, ViteValaxyPlugins, build, createServer, createValaxyPlugin, customElements, defaultSiteConfig, defaultValaxyConfig, defaultViteConfig, defineAddon, defineConfig, defineSiteConfig, defineTheme, defineUnoSetup, defineValaxyAddon, defineValaxyConfig, defineValaxyTheme, generateClientRedirects, getGitTimestamp, getIndexHtml, getServerInfoText, isExternal, isInstalledGlobally, isPath, loadConfig, loadConfigFromFile, mergeValaxyConfig, mergeViteConfigs, postProcessForSSG, processValaxyOptions, resolveAddonsConfig, resolveImportPath, resolveImportUrl, resolveOptions, resolveSiteConfig, resolveSiteConfigFromRoot, resolveThemeConfigFromRoot, resolveThemeValaxyConfig, resolveUserThemeConfig, resolveValaxyConfig, resolveValaxyConfigFromRoot, ssgBuild, toAtFS, transformObject };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ $t,
2
3
  ALL_ROUTE,
3
4
  EXCERPT_SEPARATOR,
4
5
  PATHNAME_PROTOCOL_RE,
@@ -49,8 +50,9 @@ import {
49
50
  startValaxyDev,
50
51
  toAtFS,
51
52
  transformObject
52
- } from "../chunk-OA6SKHSD.js";
53
+ } from "../chunk-VNLGPNVS.js";
53
54
  export {
55
+ $t,
54
56
  ALL_ROUTE,
55
57
  EXCERPT_SEPARATOR,
56
58
  PATHNAME_PROTOCOL_RE,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valaxy",
3
3
  "type": "module",
4
- "version": "0.24.5",
4
+ "version": "0.25.0",
5
5
  "description": "📄 Vite & Vue powered static blog generator.",
6
6
  "author": {
7
7
  "email": "me@yunyoujun.cn",
@@ -132,8 +132,8 @@
132
132
  "vue-i18n": "^11.1.9",
133
133
  "vue-router": "^4.5.1",
134
134
  "yargs": "^18.0.0",
135
- "@valaxyjs/devtools": "0.24.5",
136
- "@valaxyjs/utils": "0.24.5"
135
+ "@valaxyjs/devtools": "0.25.0",
136
+ "@valaxyjs/utils": "0.25.0"
137
137
  },
138
138
  "devDependencies": {
139
139
  "@mdit-vue/plugin-component": "^2.1.4",
@@ -1 +1,8 @@
1
1
  export const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i
2
+
3
+ /**
4
+ * @experimental
5
+ * 标识这是一个使用国际化的 key
6
+ * 从 locales/ 目录中获取对应的翻译
7
+ */
8
+ export const LOCALE_PREFIX = '$locale:'