valaxy 0.25.0 → 0.25.1

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.
@@ -0,0 +1,16 @@
1
+ <script setup lang="ts">
2
+ // import { useValaxyI18n } from 'valaxy'
3
+ import { useI18n } from 'vue-i18n'
4
+
5
+ defineProps<{
6
+ title: string
7
+ }>()
8
+
9
+ const { t } = useI18n()
10
+ </script>
11
+
12
+ <template>
13
+ <span>
14
+ {{ t(title) }}
15
+ </span>
16
+ </template>
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
+ import { useValaxyI18n } from 'valaxy'
2
3
  import { computed } from 'vue'
3
4
  import { useI18n } from 'vue-i18n'
4
- import { useValaxyI18n } from '../composables'
5
5
  import { useSiteConfig } from '../config'
6
6
 
7
7
  withDefaults(defineProps<{
@@ -5,7 +5,6 @@ import { useSeoMeta } from '@unhead/vue'
5
5
  import { computed } from 'vue'
6
6
  import { useI18n } from 'vue-i18n'
7
7
 
8
- import { tObject } from '../../../shared/utils/i18n'
9
8
  import { useFrontmatter, useValaxyHead, useValaxyI18n } from '../../composables'
10
9
 
11
10
  import { useTimezone } from '../../composables/global'
@@ -20,9 +19,9 @@ export function useValaxyApp() {
20
19
  const fm = useFrontmatter()
21
20
 
22
21
  const { locale } = useI18n()
23
- const { $t } = useValaxyI18n()
22
+ const { $t, $tO } = useValaxyI18n()
24
23
 
25
- const title = computed(() => tObject(fm.value.title || '', locale.value))
24
+ const title = computed(() => $tO(fm.value.title))
26
25
 
27
26
  // seo
28
27
  // todo: get first image url from markdown
@@ -35,7 +34,7 @@ export function useValaxyApp() {
35
34
  ogLocale: computed(() => locale.value || fm.value.lang || siteConfig.value.lang || 'en'),
36
35
  ogLocaleAlternate: computed(() => siteConfig.value.languages.filter(l => l !== locale.value)),
37
36
  ogSiteName: computed(() => siteConfig.value.title),
38
- ogTitle: computed(() => tObject(fm.value.title || siteConfig.value.title, locale.value)),
37
+ ogTitle: computed(() => $tO(fm.value.title || siteConfig.value.title)),
39
38
  ogImage: computed(() => fm.value.ogImage || fm.value.cover || siteConfig.value.favicon),
40
39
  ogType: 'website',
41
40
  ogUrl: siteUrl,
@@ -1,19 +1,16 @@
1
1
  import { useHead } from '@unhead/vue'
2
2
  import pkg from 'valaxy/package.json'
3
3
  import { computed } from 'vue'
4
- import { useI18n } from 'vue-i18n'
5
4
 
6
5
  import { useFrontmatter, useValaxyI18n } from '../../composables'
7
6
  import { useSiteConfig } from '../../config'
8
- import { tObject } from '../../utils'
9
7
 
10
8
  export function useValaxyHead() {
11
- const { locale } = useI18n()
12
- const { $t } = useValaxyI18n()
9
+ const { $t, $tO } = useValaxyI18n()
13
10
 
14
11
  const fm = useFrontmatter()
15
12
  const siteConfig = useSiteConfig()
16
- const $title = computed(() => tObject(fm.value.title || '', locale.value))
13
+ const $title = computed(() => $tO(fm.value.title))
17
14
 
18
15
  useHead({
19
16
  title: $title,
@@ -73,14 +73,35 @@ export function useLocaleTitle(fm: Ref<{
73
73
  export function useValaxyI18n() {
74
74
  const { t, locale } = useI18n()
75
75
 
76
+ /**
77
+ * translate `$locale:key`
78
+ * @param key
79
+ */
80
+ const $t = (key: string) => {
81
+ if (key.startsWith(LOCALE_PREFIX)) {
82
+ return t(key.slice(LOCALE_PREFIX.length))
83
+ }
84
+ return key
85
+ }
86
+
87
+ /**
88
+ * translate object
89
+ *
90
+ * {
91
+ * "zh-CN": "你好",
92
+ * "en": "Hello"
93
+ * }
94
+ */
95
+ const $tO = (data?: string | Record<string, string>) => {
96
+ return tObject(data || '', locale.value)
97
+ }
98
+
76
99
  return {
77
100
  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
- },
101
+ /**
102
+ * vue-i18n t function
103
+ */
104
+ $t,
105
+ $tO,
85
106
  }
86
107
  }
@@ -25,6 +25,7 @@ menu:
25
25
  archives: Archives
26
26
  categories: Categories
27
27
  tags: Tags
28
+ posts: Posts
28
29
  about: About
29
30
  search: Search
30
31
 
@@ -110,3 +111,10 @@ time:
110
111
 
111
112
  tooltip:
112
113
  last_updated: Last updated
114
+
115
+ blocks:
116
+ tip: TIP
117
+ warning: WARNING
118
+ danger: DANGER
119
+ info: INFO
120
+ details: DETAILS
@@ -25,6 +25,7 @@ menu:
25
25
  archives: 归档
26
26
  categories: 分类
27
27
  tags: 标签
28
+ posts: 博客文章
28
29
  about: 关于
29
30
  search: 搜索
30
31
 
@@ -109,3 +110,10 @@ time:
109
110
 
110
111
  tooltip:
111
112
  last_updated: 最后更新于
113
+
114
+ blocks:
115
+ tip: 提示
116
+ warning: 注意
117
+ danger: 警告
118
+ info: 信息
119
+ details: 详情
@@ -1,6 +1,5 @@
1
- /* stylelint-disable no-descending-specificity */
2
1
  .custom-block-title {
3
- margin-bottom: -0.4rem;
2
+ margin-bottom: 0.4rem !important;
4
3
  font-weight: 600;
5
4
  display: flex;
6
5
  align-items: center;
@@ -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.25.0";
7
+ var version = "0.25.1";
8
8
 
9
9
  // node/modules/fuse.ts
10
10
  import path4 from "path";
@@ -2055,12 +2055,13 @@ function preWrapperPlugin(md3, options) {
2055
2055
  const lang = extractLang(token.info);
2056
2056
  const rawCode = fence(...args);
2057
2057
  const codeHeightLimitClass = getCodeHeightLimitStyle(options, env);
2058
- return `<div class="language-${lang}${active}${codeHeightLimitClass}"><button title="${options.codeCopyButtonTitle}" class="copy"></button><span class="lang">${lang}</span>${rawCode}<button class="collapse"></button></div>`;
2058
+ return `<div class="language-${lang}${active}${codeHeightLimitClass}"><button title="${options.codeCopyButtonTitle || "Copy code"}" class="copy"></button><span class="lang">${lang}</span>${rawCode}<button class="collapse"></button></div>`;
2059
2059
  };
2060
2060
  }
2061
2061
 
2062
2062
  // node/plugins/markdown/plugins/markdown-it/container.ts
2063
- function createContainer(classes, { icon, color, text: defaultTitle, langs } = {}, md3) {
2063
+ function createContainer(key, block = {}, md3) {
2064
+ const classes = key;
2064
2065
  return [
2065
2066
  container,
2066
2067
  classes,
@@ -2072,15 +2073,9 @@ function createContainer(classes, { icon, color, text: defaultTitle, langs } = {
2072
2073
  const attrs = md3.renderer.renderAttrs(token);
2073
2074
  const info = token.info.trim().slice(classes.length).trim();
2074
2075
  let iconTag = "";
2075
- if (icon)
2076
- iconTag = `<i class="icon ${icon}" ${color ? `style="color: ${color}"` : ""}></i>`;
2077
- let titleWithLang = `<span lang="en">${info || defaultTitle}</span>`;
2078
- if (langs) {
2079
- Object.keys(langs).forEach((lang) => {
2080
- titleWithLang += `<span lang="${lang}">${info || langs[lang]}</span>`;
2081
- });
2082
- }
2083
- const title = md3.renderInline(titleWithLang, {});
2076
+ if (block.icon)
2077
+ iconTag = `<i class="icon ${block.icon}" ${block.color ? `style="color: ${block.color}"` : ""}></i>`;
2078
+ const title = `<ValaxyContainerBlockTitle title="blocks.${key}" />`;
2084
2079
  const titleClass = `custom-block-title${info ? "" : " custom-block-title-default"}`;
2085
2080
  if (classes === "details")
2086
2081
  return `<details ${attrs}><summary>${title}</summary>
@@ -2096,43 +2091,27 @@ function createContainer(classes, { icon, color, text: defaultTitle, langs } = {
2096
2091
  }
2097
2092
  var defaultBlocksOptions = {
2098
2093
  tip: {
2099
- text: "TIP",
2100
- langs: {
2101
- "zh-CN": "\u63D0\u793A"
2102
- }
2094
+ text: "TIP"
2103
2095
  },
2104
2096
  warning: {
2105
- text: "WARNING",
2106
- langs: {
2107
- "zh-CN": "\u6CE8\u610F"
2108
- }
2097
+ text: "WARNING"
2109
2098
  },
2110
2099
  danger: {
2111
- text: "DANGER",
2112
- langs: {
2113
- "zh-CN": "\u8B66\u544A"
2114
- }
2100
+ text: "DANGER"
2115
2101
  },
2116
2102
  info: {
2117
- text: "INFO",
2118
- langs: {
2119
- "zh-CN": "\u4FE1\u606F"
2120
- }
2103
+ text: "INFO"
2121
2104
  },
2122
2105
  details: {
2123
- text: "Details",
2124
- langs: {
2125
- "zh-CN": "\u8BE6\u60C5"
2126
- }
2106
+ text: "Details"
2127
2107
  }
2128
2108
  };
2129
2109
  function containerPlugin(md3, containerOptions = {}) {
2130
- const blockKeys = new Set(Object.keys(Object.assign(defaultBlocksOptions, containerOptions)));
2110
+ const blockKeys = new Set(Object.keys(Object.assign({}, defaultBlocksOptions, containerOptions.blocks)));
2131
2111
  blockKeys.forEach((optionKey) => {
2132
- const option = {
2133
- ...defaultBlocksOptions[optionKey],
2134
- ...containerOptions[optionKey] || {}
2135
- };
2112
+ const key = optionKey;
2113
+ const userOption = containerOptions.blocks?.[key] || {};
2114
+ const option = Object.assign({}, defaultBlocksOptions[key], userOption);
2136
2115
  md3.use(...createContainer(optionKey, option, md3));
2137
2116
  });
2138
2117
  md3.use(container, "v-pre", {
@@ -2145,7 +2124,7 @@ function containerPlugin(md3, containerOptions = {}) {
2145
2124
  ` : `</div>
2146
2125
  `
2147
2126
  });
2148
- const languages = containerOptions.siteConfig?.languages || ["zh-CN", "en"];
2127
+ const languages = containerOptions.languages || ["zh-CN", "en"];
2149
2128
  languages.forEach((lang) => {
2150
2129
  md3.use(container, lang, {
2151
2130
  render: (tokens, idx) => tokens[idx].nesting === 1 ? `<div lang="${lang}">
@@ -2561,9 +2540,12 @@ async function setupMarkdownPlugins(md3, options, base = "/") {
2561
2540
  if (mdOptions.preConfig)
2562
2541
  mdOptions.preConfig(md3);
2563
2542
  md3.use(highlightLinePlugin).use(preWrapperPlugin, { theme, siteConfig }).use(snippetPlugin, options?.userRoot).use(containerPlugin, {
2564
- siteConfig,
2565
- ...mdOptions.blocks,
2566
- ...mdOptions?.container
2543
+ languages: siteConfig.languages,
2544
+ ...mdOptions?.container,
2545
+ blocks: {
2546
+ ...mdOptions.blocks,
2547
+ ...mdOptions.container?.blocks
2548
+ }
2567
2549
  }).use(cssI18nContainer, {
2568
2550
  languages: options?.config.siteConfig.languages
2569
2551
  }).use(
@@ -3,7 +3,7 @@ import {
3
3
  registerDevCommand,
4
4
  run,
5
5
  startValaxyDev
6
- } from "../../chunk-VNLGPNVS.js";
6
+ } from "../../chunk-JXEHOFBR.js";
7
7
  export {
8
8
  cli,
9
9
  registerDevCommand,
@@ -2,9 +2,9 @@ import { ViteSSGOptions } from 'vite-ssg';
2
2
  import * as vite from 'vite';
3
3
  import { UserConfig, InlineConfig, PluginOption, Plugin } from 'vite';
4
4
  import { MarkdownEnv } from 'unplugin-vue-markdown/types';
5
- import { S as SiteConfig, D as DefaultTheme, V as ValaxyConfig, a as ValaxyAddon, P as PartialDeep, R as RuntimeConfig, b as RedirectItem, U as UserSiteConfig } from '../config-DHcACRUt.js';
5
+ import { D as DefaultTheme, V as ValaxyConfig, a as ValaxyAddon, P as PartialDeep, R as RuntimeConfig, b as RedirectItem, S as SiteConfig, U as UserSiteConfig } from '../config-DHcACRUt.js';
6
6
  import Vue from '@vitejs/plugin-vue';
7
- import { Options as Options$3 } from 'beasties';
7
+ import { Options as Options$2 } from 'beasties';
8
8
  import { Hookable } from 'hookable';
9
9
  import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
10
10
  import { presetUno, presetAttributify, presetIcons, presetTypography } from 'unocss';
@@ -14,14 +14,14 @@ import Markdown from 'unplugin-vue-markdown/vite';
14
14
  import { EditableTreeNode } from 'unplugin-vue-router';
15
15
  import Router from 'unplugin-vue-router/vite';
16
16
  import Layouts from 'vite-plugin-vue-layouts';
17
- import { Options as Options$2 } from 'vitepress-plugin-group-icons';
17
+ import { Options as Options$1 } from 'vitepress-plugin-group-icons';
18
18
  import { HeadersPluginOptions } from '@mdit-vue/plugin-headers';
19
19
  import { SfcPluginOptions } from '@mdit-vue/plugin-sfc';
20
20
  import { TocPluginOptions } from '@mdit-vue/plugin-toc';
21
21
  import { KatexOptions } from 'katex';
22
22
  import MarkdownIt from 'markdown-it';
23
23
  import anchorPlugin from 'markdown-it-anchor';
24
- import { Options as Options$1, MarkdownItAsync } from 'markdown-it-async';
24
+ import { Options, MarkdownItAsync } from 'markdown-it-async';
25
25
  import { ThemeRegistration, BuiltinTheme, LanguageInput, ShikiTransformer, Highlighter } from 'shiki';
26
26
  export { cli, registerDevCommand, run, startValaxyDev } from './cli/index.js';
27
27
  import { Awaitable } from '@antfu/utils';
@@ -46,22 +46,10 @@ declare module 'vite' {
46
46
  */
47
47
  declare function createValaxyNode(options: ResolvedValaxyOptions): ValaxyNode;
48
48
 
49
- interface Options {
50
- codeCopyButtonTitle: string;
51
- theme: ThemeOptions;
52
- siteConfig?: SiteConfig;
53
- }
54
-
55
49
  interface BlockItem {
56
50
  text?: string;
57
51
  icon?: string;
58
52
  color?: string;
59
- /**
60
- * for i18n
61
- */
62
- langs?: {
63
- [key: string]: string;
64
- };
65
53
  }
66
54
  interface Blocks {
67
55
  tip?: BlockItem;
@@ -70,7 +58,10 @@ interface Blocks {
70
58
  info?: BlockItem;
71
59
  details?: BlockItem;
72
60
  }
73
- type ContainerOptions = Blocks & Partial<Options>;
61
+ interface ContainerOptions {
62
+ blocks?: Blocks;
63
+ languages?: string[];
64
+ }
74
65
 
75
66
  type ThemeOptions = ThemeRegistration | BuiltinTheme | {
76
67
  light: ThemeRegistration | BuiltinTheme;
@@ -80,7 +71,7 @@ type ThemeOptions = ThemeRegistration | BuiltinTheme | {
80
71
  * Extend Markdown options
81
72
  * @zh 扩展 Markdown 配置,包含代码高亮、Markdown-it 和插件配置
82
73
  */
83
- interface MarkdownOptions extends Options$1 {
74
+ interface MarkdownOptions extends Options {
84
75
  /**
85
76
  * Setup markdown-it instance before applying plugins
86
77
  */
@@ -313,7 +304,7 @@ interface ValaxyExtendConfig {
313
304
  /**
314
305
  * @see https://github.com/yuyinws/vitepress-plugin-group-icons
315
306
  */
316
- groupIcons?: Partial<Options$2>;
307
+ groupIcons?: Partial<Options$1>;
317
308
  /**
318
309
  * unocss presets
319
310
  * @see https://unocss.dev/guide/presets
@@ -386,7 +377,7 @@ interface ValaxyExtendConfig {
386
377
  * beastiesOptions
387
378
  * @see https://github.com/danielroe/beasties
388
379
  */
389
- beastiesOptions?: Options$3;
380
+ beastiesOptions?: Options$2;
390
381
  }
391
382
  type ValaxyAddonLike = ValaxyAddon | false | null | undefined;
392
383
  type ValaxyAddons = (ValaxyAddon | string)[] | Record<string, ValaxyAddonLike>;
@@ -50,7 +50,7 @@ import {
50
50
  startValaxyDev,
51
51
  toAtFS,
52
52
  transformObject
53
- } from "../chunk-VNLGPNVS.js";
53
+ } from "../chunk-JXEHOFBR.js";
54
54
  export {
55
55
  $t,
56
56
  ALL_ROUTE,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valaxy",
3
3
  "type": "module",
4
- "version": "0.25.0",
4
+ "version": "0.25.1",
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.25.0",
136
- "@valaxyjs/utils": "0.25.0"
135
+ "@valaxyjs/devtools": "0.25.1",
136
+ "@valaxyjs/utils": "0.25.1"
137
137
  },
138
138
  "devDependencies": {
139
139
  "@mdit-vue/plugin-component": "^2.1.4",