From 21feccdc7b1ce172b9ac4f635e13942d7efb963e 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] feat: add permalink variable `timestamp` fix #5586 --- lib/plugins/filter/post_permalink.ts | 1 + test/scripts/filters/post_permalink.ts | 16 ++++++++++++++++ 2 files changed, 17 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..de9583eaa8 100644 --- a/test/scripts/filters/post_permalink.ts +++ b/test/scripts/filters/post_permalink.ts @@ -96,6 +96,22 @@ describe('post_permalink', () => { Post.removeById(post._id); }); + it('timestamp', async () => { + hexo.config.timezone = 'UTC'; + hexo.config.permalink = ':day/:hour/:timestamp/'; + const date = moment('2025-01-09 22:45:14'); + const timestamp = '1736433914'; + const post = await Post.insert({ + source: 'sub/test-timestamp-post.md', + slug: 'test-timestamp-post', + title: 'My New Post', + date: date + }); + postPermalink(post).should.eql(`09/22/${timestamp}/`); + Post.removeById(post._id); + hexo.config.timezone = ''; + }); + it('time is omitted in front-matter', async () => { hexo.config.permalink = ':year/:month/:day/:hour/:minute/:second/:post_title/';