valaxy 0.26.7 → 0.26.8

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,7 +1,7 @@
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.DHoKJedg.mjs';
5
5
  import 'node:path';
6
6
  import 'consola';
7
7
  import 'consola/utils';
@@ -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.DHoKJedg.mjs';
2
2
  import 'node:path';
3
3
  import 'fs-extra';
4
4
  import 'consola/utils';
@@ -1568,7 +1568,7 @@ async function setupMarkdownPlugins(md, options, base = "/") {
1568
1568
  return md;
1569
1569
  }
1570
1570
 
1571
- const version = "0.26.7";
1571
+ const version = "0.26.8";
1572
1572
 
1573
1573
  const GLOBAL_STATE = {
1574
1574
  valaxyApp: void 0,
@@ -1995,7 +1995,8 @@ const defaultSiteConfig = {
1995
1995
  favicon: "/favicon.svg"
1996
1996
  },
1997
1997
  social: [],
1998
- lastUpdated: true,
1998
+ orderBy: "date",
1999
+ lastUpdated: false,
1999
2000
  license: {
2000
2001
  enabled: true,
2001
2002
  language: "",
@@ -3677,7 +3678,12 @@ function commonOptions(args) {
3677
3678
  async function generateFuseList(options) {
3678
3679
  consola.start(`Generate List for Fuse Search by (${colors.cyan("fuse.js")}) ...`);
3679
3680
  const pattern = path$1.resolve(options.userRoot, options.config.siteConfig.fuse.pattern || "pages/**/*.md");
3680
- const files = await fg(pattern);
3681
+ const files = await fg(fg.convertPathToPattern(pattern));
3682
+ if (files.length > 0) {
3683
+ consola.success(`Found ${colors.dim(files.length.toString())} markdown files for fuse search.`);
3684
+ } else {
3685
+ consola.warn(`No markdown files found for fuse search. Please check your fuse pattern: ${colors.dim(pattern)}`);
3686
+ }
3681
3687
  const posts = [];
3682
3688
  for await (const i of files) {
3683
3689
  const raw = fs.readFileSync(i, "utf-8");
@@ -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.8",
5
5
  "description": "📄 Vite & Vue powered static blog generator.",
6
6
  "author": {
7
7
  "email": "me@yunyoujun.cn",
@@ -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",
@@ -118,7 +118,7 @@
118
118
  "pinia": "^3.0.3",
119
119
  "qrcode": "^1.5.4",
120
120
  "resolve-global": "^2.0.0",
121
- "sass": "^1.93.2",
121
+ "sass": "^1.93.3",
122
122
  "shiki": "^3.14.0",
123
123
  "star-markdown-css": "^0.5.3",
124
124
  "table": "^6.9.0",
@@ -126,7 +126,7 @@
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
131
  "vite": "^7.1.12",
132
132
  "vite-dev-rpc": "^1.1.0",
@@ -139,8 +139,8 @@
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/utils": "0.26.8",
143
+ "@valaxyjs/devtools": "0.26.8"
144
144
  },
145
145
  "devDependencies": {
146
146
  "@mdit-vue/plugin-component": "^3.0.2",
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