Skip to content

Commit

Permalink
feat: add an option to disable titlecase in post (#5156)
Browse files Browse the repository at this point in the history
  • Loading branch information
renbaoshuo authored Feb 27, 2023
1 parent d5f3f82 commit cb19b29
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/filter/before_post_render/titlecase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let titlecase;

function titlecaseFilter(data) {
if (!this.config.titlecase || !data.title) return;
if (!(typeof data.titlecase !== 'undefined' ? data.titlecase : this.config.titlecase) || !data.title) return;

if (!titlecase) titlecase = require('titlecase');
data.title = titlecase(data.title);
Expand Down
19 changes: 19 additions & 0 deletions test/scripts/filters/titlecase.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,23 @@ describe('Titlecase', () => {
titlecase(data);
data.title.should.eql('Today Is a Good Day');
});

it('enabled globally but disabled in a specify post', () => {
const title = 'Today is a good day';
const data = {title, titlecase: false};
hexo.config.titlecase = true;

titlecase(data);
data.title.should.eql('Today is a good day');
});

it('disabled globally but enabled in a specify post', () => {
const title = 'Today is a good day';
const data = {title, titlecase: true};
hexo.config.titlecase = false;

titlecase(data);
data.title.should.eql('Today Is a Good Day');
});

});

0 comments on commit cb19b29

Please sign in to comment.