valaxy 0.26.7 → 0.26.9

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,9 +1,10 @@
1
1
  import type { Post } from 'valaxy'
2
2
  import type { ComputedRef } from 'vue'
3
+ import { orderByMeta, useSiteConfig } from 'valaxy'
3
4
  import { computed } from 'vue'
4
5
  import { useI18n } from 'vue-i18n'
5
6
  import { useRouterStore } from '../../stores'
6
- import { sortByDate, tObject } from '../../utils'
7
+ import { tObject } from '../../utils'
7
8
 
8
9
  export * from './usePagination'
9
10
  export * from './usePrevNext'
@@ -43,6 +44,7 @@ export function usePageList() {
43
44
  export function usePostList(params: {
44
45
  type?: string
45
46
  } = {}) {
47
+ const siteConfig = useSiteConfig()
46
48
  const pageList = usePageList()
47
49
  return computed(() => {
48
50
  const routes = pageList.value
@@ -54,11 +56,16 @@ export function usePostList(params: {
54
56
  && (!i.hide || i.hide === 'index'), // hide `hide: all` posts
55
57
  )
56
58
 
59
+ function sortBySiteConfigOrderBy(posts: Post[]) {
60
+ const orderBy = siteConfig.value.orderBy
61
+ return orderByMeta(posts, orderBy)
62
+ }
63
+
57
64
  /**
58
65
  * 置顶
59
66
  */
60
- const topPosts = sortByDate(routes.filter(i => i.top)).sort((a, b) => b.top! - a.top!)
61
- const otherPosts = sortByDate(routes.filter(i => !i.top))
67
+ const topPosts = sortBySiteConfigOrderBy(routes.filter(i => i.top)).sort((a, b) => b.top! - a.top!)
68
+ const otherPosts = sortBySiteConfigOrderBy(routes.filter(i => !i.top))
62
69
 
63
70
  return topPosts.concat(otherPosts)
64
71
  })
@@ -33,9 +33,21 @@ export function formatDate(date?: string | number | Date, options: {
33
33
  * @param desc
34
34
  */
35
35
  export function sortByDate(posts: Post[], desc = true) {
36
+ return orderByMeta(posts, 'date', desc)
37
+ }
38
+
39
+ export function sortByUpdated(posts: Post[], desc = true) {
40
+ return orderByMeta(posts, 'updated', desc)
41
+ }
42
+
43
+ /**
44
+ * sort posts by date
45
+ * @param posts
46
+ */
47
+ export function orderByMeta(posts: Post[], orderBy: 'date' | 'updated' = 'date', desc = true) {
36
48
  return posts.sort((a, b) => {
37
- const aDate = +new Date(a.updated || a.date || '')
38
- const bDate = +new Date(b.updated || b.date || '')
49
+ const aDate = +new Date(a[orderBy] || a.date || '')
50
+ const bDate = +new Date(b[orderBy] || a.date || '')
39
51
  if (desc)
40
52
  return bDate - aDate
41
53
  else
@@ -1,13 +1,15 @@
1
1
  import 'node:process';
2
2
  import 'yargs';
3
3
  import 'yargs/helpers';
4
- export { c as cli, d as registerDevCommand, r as run, a as startValaxyDev } from '../../shared/valaxy.CTxfxTHO.mjs';
4
+ export { c as cli, d as registerDevCommand, r as run, a as startValaxyDev } from '../../shared/valaxy.B5JLGXpW.mjs';
5
+ import 'node:os';
5
6
  import 'node:path';
6
7
  import 'consola';
7
8
  import 'consola/utils';
8
9
  import 'fast-glob';
9
10
  import 'fs-extra';
10
11
  import 'gray-matter';
12
+ import 'js-yaml';
11
13
  import '@antfu/utils';
12
14
  import 'debug';
13
15
  import 'pathe';
@@ -20,7 +22,6 @@ import 'ora';
20
22
  import 'cross-spawn';
21
23
  import 'mlly';
22
24
  import 'resolve-global';
23
- import 'js-yaml';
24
25
  import 'node:fs/promises';
25
26
  import 'dayjs';
26
27
  import 'feed';
@@ -56,7 +57,6 @@ import 'pascalcase';
56
57
  import 'lru-cache';
57
58
  import 'html-to-text';
58
59
  import 'unplugin-vue-router/vite';
59
- import 'node:os';
60
60
  import '@clack/prompts';
61
61
  import 'node:net';
62
62
  import 'node:child_process';
@@ -13,7 +13,7 @@ import { EditableTreeNode } from 'unplugin-vue-router';
13
13
  import Router from 'unplugin-vue-router/vite';
14
14
  import Layouts from 'vite-plugin-vue-layouts';
15
15
  import { Options as Options$1 } from 'vitepress-plugin-group-icons';
16
- import { D as DefaultTheme, R as RuntimeConfig, a as RedirectItem, V as ValaxyConfig, P as PartialDeep, b as ValaxyAddon, S as SiteConfig, U as UserSiteConfig } from '../shared/valaxy.BwiZu4ms.mjs';
16
+ import { D as DefaultTheme, R as RuntimeConfig, a as RedirectItem, V as ValaxyConfig, P as PartialDeep, b as ValaxyAddon, S as SiteConfig, U as UserSiteConfig } from '../shared/valaxy.DJquM_xq.mjs';
17
17
  import { MarkdownEnv } from 'unplugin-vue-markdown/types';
18
18
  import { KatexOptions } from 'katex';
19
19
  import MarkdownIt from 'markdown-it';
@@ -1,4 +1,4 @@
1
- export { C 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, N as createServer, L as createValaxyPlugin, D as customElements, j as defaultSiteConfig, w as defaultValaxyConfig, F as defaultViteConfig, h as defineAddon, y as defineConfig, k as defineSiteConfig, u as defineTheme, f as defineValaxyAddon, x as defineValaxyConfig, t as defineValaxyTheme, O as encryptContent, g as generateClientRedirects, Q as getGitTimestamp, e as getIndexHtml, M as getServerInfoText, R as isExternal, U as isInstalledGlobally, S as isPath, v as loadConfigFromFile, A as mergeValaxyConfig, m as mergeViteConfigs, p as postProcessForSSG, I as processValaxyOptions, d as registerDevCommand, i as resolveAddonsConfig, Y as resolveImportPath, W as resolveImportUrl, J as resolveOptions, n as resolveSiteConfig, l as resolveSiteConfigFromRoot, o as resolveThemeConfigFromRoot, K as resolveThemeValaxyConfig, q as resolveUserThemeConfig, B as resolveValaxyConfig, z as resolveValaxyConfigFromRoot, r as run, s as ssgBuild, a as startValaxyDev, X as toAtFS, T as transformObject, H as version } from '../shared/valaxy.CTxfxTHO.mjs';
1
+ export { C 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, N as createServer, L as createValaxyPlugin, D as customElements, j as defaultSiteConfig, w as defaultValaxyConfig, F as defaultViteConfig, h as defineAddon, y as defineConfig, k as defineSiteConfig, u as defineTheme, f as defineValaxyAddon, x as defineValaxyConfig, t as defineValaxyTheme, O as encryptContent, g as generateClientRedirects, Q as getGitTimestamp, e as getIndexHtml, M as getServerInfoText, R as isExternal, U as isInstalledGlobally, S as isPath, v as loadConfigFromFile, A as mergeValaxyConfig, m as mergeViteConfigs, p as postProcessForSSG, I as processValaxyOptions, d as registerDevCommand, i as resolveAddonsConfig, Y as resolveImportPath, W as resolveImportUrl, J as resolveOptions, n as resolveSiteConfig, l as resolveSiteConfigFromRoot, o as resolveThemeConfigFromRoot, K as resolveThemeValaxyConfig, q as resolveUserThemeConfig, B as resolveValaxyConfig, z as resolveValaxyConfigFromRoot, r as run, s as ssgBuild, a as startValaxyDev, X as toAtFS, T as transformObject, H as version } from '../shared/valaxy.B5JLGXpW.mjs';
2
2
  import 'node:path';
3
3
  import 'fs-extra';
4
4
  import 'consola/utils';
@@ -6,9 +6,11 @@ import 'node:process';
6
6
  import 'define-config-ts';
7
7
  import 'yargs';
8
8
  import 'yargs/helpers';
9
+ import 'node:os';
9
10
  import 'consola';
10
11
  import 'fast-glob';
11
12
  import 'gray-matter';
13
+ import 'js-yaml';
12
14
  import '@antfu/utils';
13
15
  import 'debug';
14
16
  import 'pathe';
@@ -20,7 +22,6 @@ import 'ora';
20
22
  import 'cross-spawn';
21
23
  import 'mlly';
22
24
  import 'resolve-global';
23
- import 'js-yaml';
24
25
  import 'node:fs/promises';
25
26
  import 'dayjs';
26
27
  import 'feed';
@@ -56,7 +57,6 @@ import 'pascalcase';
56
57
  import 'lru-cache';
57
58
  import 'html-to-text';
58
59
  import 'unplugin-vue-router/vite';
59
- import 'node:os';
60
60
  import '@clack/prompts';
61
61
  import 'node:net';
62
62
  import 'node:child_process';
@@ -1,12 +1,14 @@
1
1
  import process from 'node:process';
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
+ import os from 'node:os';
4
5
  import path$1, { join, dirname, resolve } from 'node:path';
5
6
  import { consola } from 'consola';
6
7
  import { colors } from 'consola/utils';
7
8
  import fg from 'fast-glob';
8
9
  import fs from 'fs-extra';
9
10
  import matter from 'gray-matter';
11
+ import yaml, { CORE_SCHEMA } from 'js-yaml';
10
12
  import { ensurePrefix, slash, uniq, objectEntries, isObject, isFunction, ensureSuffix } from '@antfu/utils';
11
13
  import _debug from 'debug';
12
14
  import path, { resolve as resolve$1, join as join$1, relative } from 'pathe';
@@ -19,7 +21,6 @@ import ora from 'ora';
19
21
  import { spawn } from 'cross-spawn';
20
22
  import { resolvePath } from 'mlly';
21
23
  import { resolveGlobal } from 'resolve-global';
22
- import yaml, { CORE_SCHEMA } from 'js-yaml';
23
24
  import { readFile } from 'node:fs/promises';
24
25
  import dayjs from 'dayjs';
25
26
  import { Feed } from 'feed';
@@ -55,7 +56,6 @@ import pascalCase from 'pascalcase';
55
56
  import { LRUCache } from 'lru-cache';
56
57
  import { convert } from 'html-to-text';
57
58
  import VueRouter from 'unplugin-vue-router/vite';
58
- import os from 'node:os';
59
59
  import { intro, confirm, select, outro } from '@clack/prompts';
60
60
  import net from 'node:net';
61
61
  import { exec } from 'node:child_process';
@@ -162,6 +162,7 @@ function getGitTimestamp(file, type = "updated") {
162
162
  }
163
163
 
164
164
  const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i;
165
+ const LOCALE_PREFIX = "$locale:";
165
166
 
166
167
  function tObject(data, lang) {
167
168
  if (data && typeof data === "object") {
@@ -1466,21 +1467,6 @@ function snippetPlugin(md, srcDir) {
1466
1467
  md.block.ruler.before("fence", "snippet", parser);
1467
1468
  }
1468
1469
 
1469
- const globalTitleCollector = /* @__PURE__ */ new Set();
1470
- function getGlobalTitleCollector() {
1471
- return globalTitleCollector;
1472
- }
1473
- function titleCollectorPlugin(md) {
1474
- const fence = md.renderer.rules.fence;
1475
- md.renderer.rules.fence = (...args) => {
1476
- const [tokens, idx] = args;
1477
- const token = tokens[idx];
1478
- const title = extractTitle(token.info);
1479
- globalTitleCollector.add(title);
1480
- return fence(...args);
1481
- };
1482
- }
1483
-
1484
1470
  const defaultCodeTheme = { light: "github-light", dark: "github-dark" };
1485
1471
  async function setupMarkdownPlugins(md, options, base = "/") {
1486
1472
  const mdOptions = options?.config.markdown || {};
@@ -1488,7 +1474,7 @@ async function setupMarkdownPlugins(md, options, base = "/") {
1488
1474
  const siteConfig = options?.config.siteConfig || {};
1489
1475
  if (mdOptions.preConfig)
1490
1476
  mdOptions.preConfig(md);
1491
- md.use(highlightLinePlugin).use(preWrapperPlugin, { theme, siteConfig }).use(snippetPlugin, options?.userRoot).use(titleCollectorPlugin).use(containerPlugin, {
1477
+ md.use(highlightLinePlugin).use(preWrapperPlugin, { theme, siteConfig }).use(snippetPlugin, options?.userRoot).use(containerPlugin, {
1492
1478
  languages: siteConfig.languages,
1493
1479
  ...mdOptions?.container,
1494
1480
  blocks: {
@@ -1568,7 +1554,7 @@ async function setupMarkdownPlugins(md, options, base = "/") {
1568
1554
  return md;
1569
1555
  }
1570
1556
 
1571
- const version = "0.26.7";
1557
+ const version = "0.26.9";
1572
1558
 
1573
1559
  const GLOBAL_STATE = {
1574
1560
  valaxyApp: void 0,
@@ -1995,7 +1981,8 @@ const defaultSiteConfig = {
1995
1981
  favicon: "/favicon.svg"
1996
1982
  },
1997
1983
  social: [],
1998
- lastUpdated: true,
1984
+ orderBy: "date",
1985
+ lastUpdated: false,
1999
1986
  license: {
2000
1987
  enabled: true,
2001
1988
  language: "",
@@ -3512,65 +3499,18 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
3512
3499
  typedoc: "vscode-icons:file-type-typedoc",
3513
3500
  eslint: "vscode-icons:file-type-eslint"
3514
3501
  };
3515
- let cachedGroupIconsCSS = null;
3516
- const generateGroupIconsCSS = (id) => {
3517
- const codeBlockTitles = getGlobalTitleCollector();
3518
- const originalPlugin = groupIconVitePlugin({
3519
- customIcon: {
3520
- ...builtinCustomIcon,
3521
- ...valaxyConfig.groupIcons?.customIcon
3522
- },
3523
- defaultLabels: [
3524
- ...valaxyConfig.groupIcons?.defaultLabels || [],
3525
- ...Object.keys(builtinCustomIcon),
3526
- ...Object.keys(valaxyConfig.groupIcons?.customIcon || {}),
3527
- ...Array.from(codeBlockTitles)
3528
- ]
3529
- });
3530
- if (originalPlugin && typeof originalPlugin === "object" && "load" in originalPlugin) {
3531
- return originalPlugin.load(id);
3532
- }
3533
- return "";
3534
- };
3535
- const dynamicGroupIconPlugin = {
3536
- name: "post-process-add-group-icons",
3537
- enforce: "post",
3538
- configureServer(server) {
3539
- const markdownGlobs = roots.map((root) => `${root}/**/*.md`);
3540
- server.watcher.add(markdownGlobs);
3541
- server.watcher.on("change", (file) => {
3542
- if (file.endsWith(".md")) {
3543
- cachedGroupIconsCSS = null;
3544
- const module = server.moduleGraph.getModuleById("\0virtual:group-icons.css");
3545
- if (module) {
3546
- server.reloadModule(module);
3547
- }
3548
- }
3549
- });
3502
+ const groupIconPlugin = groupIconVitePlugin({
3503
+ customIcon: {
3504
+ ...builtinCustomIcon,
3505
+ ...valaxyConfig.groupIcons?.customIcon
3550
3506
  },
3551
- resolveId(id) {
3552
- if (id === "virtual:group-icons.css") {
3553
- return "\0virtual:group-icons.css";
3554
- }
3555
- return void 0;
3556
- },
3557
- async load(id) {
3558
- if (id === "\0virtual:group-icons.css") {
3559
- if (cachedGroupIconsCSS !== null) {
3560
- return cachedGroupIconsCSS;
3561
- }
3562
- return generateGroupIconsCSS(id);
3563
- }
3564
- return void 0;
3565
- },
3566
- // In build mode, regenerate the CSS after all markdown files have been processed
3567
- generateBundle() {
3568
- if (this.meta.rollupVersion) {
3569
- cachedGroupIconsCSS = generateGroupIconsCSS("\0virtual:group-icons.css");
3570
- }
3571
- }
3572
- };
3573
- plugins.push(dynamicGroupIconPlugin);
3507
+ defaultLabels: [
3508
+ ...valaxyConfig.groupIcons?.defaultLabels || [],
3509
+ ...Object.keys(builtinCustomIcon),
3510
+ ...Object.keys(valaxyConfig.groupIcons?.customIcon || {})
3511
+ ]
3512
+ });
3513
+ plugins.push(groupIconPlugin);
3574
3514
  return plugins;
3575
3515
  }
3576
3516
 
@@ -3666,6 +3606,48 @@ function setupModules(node, modules) {
3666
3606
  });
3667
3607
  }
3668
3608
 
3609
+ const NODE_I18N = {
3610
+ /**
3611
+ * node 读取的 locales 数据
3612
+ */
3613
+ locales: {}
3614
+ };
3615
+ function loadLocalesYml(localesPath) {
3616
+ const locales = {};
3617
+ if (fs.existsSync(localesPath)) {
3618
+ const files = fs.readdirSync(localesPath);
3619
+ files.forEach((file) => {
3620
+ if (file.endsWith(".yml") || file.endsWith(".yaml")) {
3621
+ const lang = file.replace(/\.ya?ml$/, "");
3622
+ const filePath = `${localesPath}/${file}`;
3623
+ try {
3624
+ const content = fs.readFileSync(filePath, "utf-8");
3625
+ const data = yaml.load(content);
3626
+ locales[lang] = data || {};
3627
+ } catch (e) {
3628
+ console.error(`Error loading locale file: ${filePath}`, e);
3629
+ }
3630
+ }
3631
+ });
3632
+ }
3633
+ NODE_I18N.locales = locales;
3634
+ return locales;
3635
+ }
3636
+ function nodeT(key, lang) {
3637
+ if (key.startsWith(LOCALE_PREFIX)) {
3638
+ key = key.slice(LOCALE_PREFIX.length);
3639
+ }
3640
+ const data = NODE_I18N.locales[lang] || {};
3641
+ const keys = key.split(".");
3642
+ let result = data;
3643
+ for (const k of keys) {
3644
+ result = result?.[k];
3645
+ if (result === void 0)
3646
+ return "";
3647
+ }
3648
+ return result || "";
3649
+ }
3650
+
3669
3651
  function commonOptions(args) {
3670
3652
  return args.positional("root", {
3671
3653
  default: ".",
@@ -3674,10 +3656,19 @@ function commonOptions(args) {
3674
3656
  });
3675
3657
  }
3676
3658
 
3659
+ const isWindows = os.platform() === "win32";
3677
3660
  async function generateFuseList(options) {
3678
3661
  consola.start(`Generate List for Fuse Search by (${colors.cyan("fuse.js")}) ...`);
3679
3662
  const pattern = path$1.resolve(options.userRoot, options.config.siteConfig.fuse.pattern || "pages/**/*.md");
3680
- const files = await fg(pattern);
3663
+ const finalPattern = isWindows ? fg.convertPathToPattern(pattern) : pattern;
3664
+ const files = await fg(finalPattern);
3665
+ if (files.length > 0) {
3666
+ consola.success(`Found ${colors.dim(files.length.toString())} markdown files for fuse search.`);
3667
+ } else {
3668
+ consola.warn(`No markdown files found for fuse search. Please check your fuse pattern: ${colors.dim(finalPattern)}`);
3669
+ }
3670
+ loadLocalesYml(path$1.resolve(options.userRoot, "locales"));
3671
+ const globalAuthor = nodeT(options.config.siteConfig.author.name, options.config.siteConfig.lang || "en");
3681
3672
  const posts = [];
3682
3673
  for await (const i of files) {
3683
3674
  const raw = fs.readFileSync(i, "utf-8");
@@ -3692,15 +3683,15 @@ async function generateFuseList(options) {
3692
3683
  if (fmData.password)
3693
3684
  continue;
3694
3685
  const extendKeys = options.config.fuse?.extendKeys || [];
3695
- const relativeLink = path$1.resolve(options.config.vite?.base || "/", path$1.relative(path$1.resolve(options.userRoot, "pages"), i));
3686
+ const relativeLink = path$1.join(options.config.vite?.base || "/", path$1.relative(path$1.resolve(options.userRoot, "pages"), i)).replace(/\\/g, "/");
3696
3687
  const link = i.endsWith("index.md") ? relativeLink.replace(/\/index\.md$/, "") : relativeLink.replace(/\.md$/, "");
3697
3688
  const fuseListItem = {
3698
3689
  title: fmData.title || "",
3699
3690
  tags: (typeof fmData.tags === "string" ? [fmData.tags] : fmData.tags) || [],
3700
3691
  categories: (typeof fmData.categories === "string" ? [fmData.categories] : fmData.categories) || [],
3701
- author: options.config.siteConfig.author.name,
3692
+ author: fmData.author || globalAuthor,
3702
3693
  excerpt: excerpt || content.slice(0, 100),
3703
- // encode for chinese url
3694
+ // encode for chinese url, replace for windows path
3704
3695
  link: encodeURI(link)
3705
3696
  };
3706
3697
  if (options.config.siteConfig.fuse.options.keys?.includes("content")) {
@@ -528,8 +528,20 @@ interface SiteConfig {
528
528
  */
529
529
  intro?: string;
530
530
  };
531
+ /**
532
+ * order posts by 'date' or 'updated'
533
+ *
534
+ * - date: 按创建时间排序
535
+ * - updated: 按最后更新时间排序
536
+ *
537
+ * 当开启 `lastUpdated` 时,`updated` 会按照文件的更新时间自动赋值
538
+ *
539
+ * @default 'date'
540
+ */
541
+ orderBy: 'date' | 'updated';
531
542
  /**
532
543
  * show last updated time by git/mtime
544
+ * @default false
533
545
  */
534
546
  lastUpdated: boolean;
535
547
  /**
@@ -1,5 +1,5 @@
1
- import { c as PostFrontMatter, d as PageFrontMatter } from '../shared/valaxy.BwiZu4ms.mjs';
2
- export { A as Album, B as BaseFrontMatter, D as DefaultTheme, E as ExcerptType, F as FuseListItem, P as PartialDeep, i as Photo, g as Pkg, a as RedirectItem, f as RedirectRule, R as RuntimeConfig, S as SiteConfig, e as SocialLink, U as UserSiteConfig, h as UserValaxyConfig, b as ValaxyAddon, V as ValaxyConfig } from '../shared/valaxy.BwiZu4ms.mjs';
1
+ import { c as PostFrontMatter, d as PageFrontMatter } from '../shared/valaxy.DJquM_xq.mjs';
2
+ export { A as Album, B as BaseFrontMatter, D as DefaultTheme, E as ExcerptType, F as FuseListItem, P as PartialDeep, i as Photo, g as Pkg, a as RedirectItem, f as RedirectRule, R as RuntimeConfig, S as SiteConfig, e as SocialLink, U as UserSiteConfig, h as UserValaxyConfig, b as ValaxyAddon, V as ValaxyConfig } from '../shared/valaxy.DJquM_xq.mjs';
3
3
  import { Header } from '@valaxyjs/utils';
4
4
  import '@vueuse/integrations/useFuse';
5
5
  import 'medium-zoom';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valaxy",
3
3
  "type": "module",
4
- "version": "0.26.7",
4
+ "version": "0.26.9",
5
5
  "description": "📄 Vite & Vue powered static blog generator.",
6
6
  "author": {
7
7
  "email": "me@yunyoujun.cn",
@@ -65,7 +65,7 @@
65
65
  "@clack/prompts": "^0.11.0",
66
66
  "@iconify-json/ri": "^1.2.6",
67
67
  "@intlify/unplugin-vue-i18n": "^11.0.1",
68
- "@shikijs/transformers": "^3.14.0",
68
+ "@shikijs/transformers": "^3.15.0",
69
69
  "@types/katex": "^0.16.7",
70
70
  "@unhead/addons": "^2.0.19",
71
71
  "@unhead/schema-org": "^2.0.19",
@@ -78,7 +78,7 @@
78
78
  "consola": "^3.4.2",
79
79
  "cross-spawn": "^7.0.6",
80
80
  "css-i18n": "^0.0.5",
81
- "dayjs": "^1.11.18",
81
+ "dayjs": "^1.11.19",
82
82
  "debug": "^4.4.3",
83
83
  "define-config-ts": "^0.1.3",
84
84
  "defu": "^6.1.4",
@@ -115,32 +115,32 @@
115
115
  "ora": "^9.0.0",
116
116
  "pascalcase": "^2.0.0",
117
117
  "pathe": "^2.0.3",
118
- "pinia": "^3.0.3",
118
+ "pinia": "^3.0.4",
119
119
  "qrcode": "^1.5.4",
120
120
  "resolve-global": "^2.0.0",
121
- "sass": "^1.93.2",
122
- "shiki": "^3.14.0",
121
+ "sass": "^1.93.3",
122
+ "shiki": "^3.15.0",
123
123
  "star-markdown-css": "^0.5.3",
124
124
  "table": "^6.9.0",
125
125
  "unhead": "^2.0.19",
126
126
  "unocss": "^66.5.4",
127
127
  "unplugin-vue-components": "28.0.0",
128
128
  "unplugin-vue-markdown": "^29.2.0",
129
- "unplugin-vue-router": "^0.16.0",
129
+ "unplugin-vue-router": "^0.16.1",
130
130
  "vanilla-lazyload": "^19.1.3",
131
- "vite": "^7.1.12",
131
+ "vite": "^7.2.1",
132
132
  "vite-dev-rpc": "^1.1.0",
133
133
  "vite-plugin-vue-devtools": "^8.0.3",
134
134
  "vite-plugin-vue-layouts": "^0.11.0",
135
135
  "vite-ssg": "^28.2.2",
136
136
  "vite-ssg-sitemap": "^0.10.0",
137
137
  "vitepress-plugin-group-icons": "^1.6.5",
138
- "vue": "^3.5.22",
138
+ "vue": "^3.5.23",
139
139
  "vue-i18n": "^11.1.12",
140
140
  "vue-router": "^4.6.3",
141
141
  "yargs": "^18.0.0",
142
- "@valaxyjs/devtools": "0.26.7",
143
- "@valaxyjs/utils": "0.26.7"
142
+ "@valaxyjs/devtools": "0.26.9",
143
+ "@valaxyjs/utils": "0.26.9"
144
144
  },
145
145
  "devDependencies": {
146
146
  "@mdit-vue/plugin-component": "^3.0.2",
@@ -0,0 +1,65 @@
1
+ import fs from 'fs-extra'
2
+ import yaml from 'js-yaml'
3
+ import { LOCALE_PREFIX } from '../constants'
4
+
5
+ export const NODE_I18N: {
6
+ locales: Record<string, any>
7
+ } = {
8
+ /**
9
+ * node 读取的 locales 数据
10
+ */
11
+ locales: {},
12
+ }
13
+
14
+ /**
15
+ * 读取翻译 yml 文件
16
+ */
17
+ export function loadLocalesYml(localesPath: string): Record<string, any> {
18
+ /**
19
+ * read locales dir *.yml
20
+ */
21
+ const locales: Record<string, any> = {}
22
+ if (fs.existsSync(localesPath)) {
23
+ const files = fs.readdirSync(localesPath)
24
+ files.forEach((file) => {
25
+ if (file.endsWith('.yml') || file.endsWith('.yaml')) {
26
+ const lang = file.replace(/\.ya?ml$/, '')
27
+ const filePath = `${localesPath}/${file}`
28
+ try {
29
+ const content = fs.readFileSync(filePath, 'utf-8')
30
+ const data = yaml.load(content)
31
+ locales[lang] = data || {}
32
+ }
33
+ catch (e) {
34
+ console.error(`Error loading locale file: ${filePath}`, e)
35
+ }
36
+ }
37
+ })
38
+ }
39
+
40
+ // cache
41
+ NODE_I18N.locales = locales
42
+ return locales
43
+ }
44
+
45
+ /**
46
+ * node translate function
47
+ *
48
+ * ```ts
49
+ * nodeT('greeting.hello', 'en') // 'Hello'
50
+ * ```
51
+ */
52
+ export function nodeT(key: string, lang: string): string {
53
+ if (key.startsWith(LOCALE_PREFIX)) {
54
+ key = key.slice(LOCALE_PREFIX.length)
55
+ }
56
+ const data = NODE_I18N.locales[lang] || {}
57
+ const keys = key.split('.')
58
+ let result: any = data
59
+ for (const k of keys) {
60
+ result = result?.[k]
61
+ if (result === undefined)
62
+ return ''
63
+ }
64
+ return result || ''
65
+ }
package/types/config.ts CHANGED
@@ -125,8 +125,21 @@ export interface SiteConfig {
125
125
  intro?: string
126
126
  }
127
127
 
128
+ /**
129
+ * order posts by 'date' or 'updated'
130
+ *
131
+ * - date: 按创建时间排序
132
+ * - updated: 按最后更新时间排序
133
+ *
134
+ * 当开启 `lastUpdated` 时,`updated` 会按照文件的更新时间自动赋值
135
+ *
136
+ * @default 'date'
137
+ */
138
+ orderBy: 'date' | 'updated'
139
+
128
140
  /**
129
141
  * show last updated time by git/mtime
142
+ * @default false
130
143
  */
131
144
  lastUpdated: boolean
132
145