From af35a4a77102c6a962aa302d3442723e12a9e59c Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:05:28 +0800 Subject: [PATCH 1/2] feat: add permalink variable `timestamp` fix #5586 --- lib/plugins/filter/post_permalink.ts | 1 + test/scripts/filters/post_permalink.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/plugins/filter/post_permalink.ts b/lib/plugins/filter/post_permalink.ts index 141408d391..d924ecd9a0 100644 --- a/lib/plugins/filter/post_permalink.ts +++ b/lib/plugins/filter/post_permalink.ts @@ -35,6 +35,7 @@ function postPermalinkFilter(this: Hexo, data: PostSchema): string { second: date.format('ss'), i_month: date.format('M'), i_day: date.format('D'), + timestamp: date.format('X'), hash, category: config.default_category }; diff --git a/test/scripts/filters/post_permalink.ts b/test/scripts/filters/post_permalink.ts index dd530ab090..3cb923a6a2 100644 --- a/test/scripts/filters/post_permalink.ts +++ b/test/scripts/filters/post_permalink.ts @@ -96,6 +96,29 @@ describe('post_permalink', () => { Post.removeById(post._id); }); + it('timestamp', async () => { + hexo.config.permalink = ':timestamp/:slug'; + const timestamp = '1736401514'; + const dates = [ + moment('2025-01-09 05:45:14Z'), + moment('2025-01-08 22:45:14-07') + ]; + const posts = await Post.insert( + dates.map((date, idx) => { + return { source: `test${idx}.md`, slug: `test${idx}`, date: date }; + }) + ); + + postPermalink(posts[0]).should.eql(`${timestamp}/test0`); + postPermalink(posts[1]).should.eql(`${timestamp}/test1`); + + await Promise.all( + posts.map(post => { + return Post.removeById(post._id); + }) + ); + }); + it('time is omitted in front-matter', async () => { hexo.config.permalink = ':year/:month/:day/:hour/:minute/:second/:post_title/'; From 91ba7d83e6dd522d772454b11bf13f39c2b3917b Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:18:24 +0800 Subject: [PATCH 2/2] test --- test/scripts/filters/post_permalink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/filters/post_permalink.ts b/test/scripts/filters/post_permalink.ts index 3cb923a6a2..219dbaa1f4 100644 --- a/test/scripts/filters/post_permalink.ts +++ b/test/scripts/filters/post_permalink.ts @@ -112,7 +112,7 @@ describe('post_permalink', () => { postPermalink(posts[0]).should.eql(`${timestamp}/test0`); postPermalink(posts[1]).should.eql(`${timestamp}/test1`); - await Promise.all( + return Promise.all( posts.map(post => { return Post.removeById(post._id); })