Skip to content

Commit

Permalink
feat: add permalink variable timestamp
Browse files Browse the repository at this point in the history
fix #5586
  • Loading branch information
uiolee committed Jan 9, 2025
1 parent 5db029a commit 21feccd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/plugins/filter/post_permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
16 changes: 16 additions & 0 deletions test/scripts/filters/post_permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/';

Expand Down

0 comments on commit 21feccd

Please sign in to comment.