Skip to content

Commit b9f71af

Browse files
authored
Sort feeds based on filename date first (#1780)
Sort feeds based on filename first
1 parent f3dd225 commit b9f71af

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

.vuepress/config.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,27 @@ export default defineUserConfig({
250250
);
251251
},
252252
sorter: (a, b) => {
253-
return compareDate(
254-
a.data.git?.createdTime
255-
? new Date(a.data.git?.createdTime)
256-
: a.frontmatter.date,
257-
b.data.git?.createdTime
258-
? new Date(b.data.git?.createdTime)
259-
: b.frontmatter.date,
253+
const pathDateA = new Date(
254+
a.path.replace('/blog/', '').substring(0, 10),
260255
);
256+
const pathDateB = new Date(
257+
b.path.replace('/blog/', '').substring(0, 10),
258+
);
259+
const effectiveDateA =
260+
pathDateA != 'Invalid Date'
261+
? pathDateA
262+
: a.frontmatter.date
263+
? new Date(a.frontmatter.date)
264+
: new Date(a.data.git?.createdTime);
265+
266+
// Determine the effective date for item B
267+
const effectiveDateB =
268+
pathDateB != 'Invalid Date'
269+
? pathDateB
270+
: b.frontmatter.date
271+
? new Date(b.frontmatter.date)
272+
: new Date(b.data.git?.createdTime);
273+
return compareDate(effectiveDateA, effectiveDateB);
261274
},
262275
}),
263276
sitemapPlugin({

0 commit comments

Comments
 (0)