Skip to content

Commit

Permalink
feat: add permalink variable timestamp (#5611)
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored Jan 19, 2025
1 parent bcfb030 commit efe66d2
Show file tree
Hide file tree
Showing 2 changed files with 24 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
23 changes: 23 additions & 0 deletions test/scripts/filters/post_permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

return 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/';

Expand Down

0 comments on commit efe66d2

Please sign in to comment.