Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop use_date_for_updated option for updated_option #5062

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/hexo/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = {
time_format: 'HH:mm:ss',
updated_option: 'mtime',
// * mtime: file modification date (default)
// * date: use_date_for_updated
// * empty: no more update
// Pagination
per_page: 10,
Expand Down
5 changes: 0 additions & 5 deletions lib/hexo/validate_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ module.exports = ctx => {
throw new TypeError('Invalid config detected: "root" should not be empty!');
}

// Soft deprecate use_date_for_updated
if (typeof config.use_date_for_updated === 'boolean') {
log.warn('Deprecated config detected: "use_date_for_updated" is deprecated, please use "updated_option" instead. See https://hexo.io/docs/configuration for more details.');
}

// Soft deprecate external_link Boolean
if (typeof config.external_link === 'boolean') {
log.warn('Deprecated config detected: "external_link" with a Boolean value is deprecated. See https://hexo.io/docs/configuration for more details.');
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/processor/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function processPage(ctx, file) {
const doc = Page.findOne({source: path});
const { config } = ctx;
const { timezone: timezoneCfg } = config;
// Deprecated: use_date_for_updated will be removed in future
const updated_option = config.use_date_for_updated === true ? 'date' : config.updated_option;
const updated_option = config.updated_option;

if (file.type === 'skip' && doc) {
return;
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ function processPost(ctx, file) {
const doc = Post.findOne({source: file.path});
const { config } = ctx;
const { timezone: timezoneCfg } = config;
// Deprecated: use_date_for_updated will be removed in future
const updated_option = config.use_date_for_updated === true ? 'date' : config.updated_option;
const updated_option = config.updated_option;
let categories, tags;

if (file.type === 'skip' && doc) {
Expand Down
9 changes: 0 additions & 9 deletions test/scripts/hexo/validate_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ describe('Validate config', () => {
}
});

it('config.use_date_for_updated - depreacte', () => {
hexo.config.use_date_for_updated = true;

validateConfig(hexo);

logSpy.calledOnce.should.be.true;
logSpy.calledWith('Deprecated config detected: "use_date_for_updated" is deprecated, please use "updated_option" instead. See https://hexo.io/docs/configuration for more details.').should.be.true;
});

it('config.external_link - depreacte Boolean value', () => {
hexo.config.external_link = false;

Expand Down
57 changes: 0 additions & 57 deletions test/scripts/processors/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,63 +359,6 @@ describe('asset', () => {
]);
});

it('page - use_date_for_updated as fallback', async () => {
const body = [
'date: 2011-4-5 14:19:19',
'---'
].join('\n');

const file = newFile({
path: 'hello.njk',
type: 'create',
renderable: true
});

hexo.config.use_date_for_updated = true;

await writeFile(file.source, body);
await process(file);
const stats = await stat(file.source);
const page = Page.findOne({source: file.path});

page.updated.toDate().should.eql(page.date.toDate());
page.updated.toDate().should.not.eql(stats.mtime);

await Promise.all([
page.remove(),
unlink(file.source)
]);
});

it('page - ignore updated_option when use_date_for_updated is set', async () => {
const body = [
'date: 2011-4-5 14:19:19',
'---'
].join('\n');

const file = newFile({
path: 'hello.njk',
type: 'create',
renderable: true
});

hexo.config.use_date_for_updated = true;
hexo.config.updated_option = 'mtime';

await writeFile(file.source, body);
await process(file);
const stats = await stat(file.source);
const page = Page.findOne({source: file.path});

page.updated.toDate().should.eql(page.date.toDate());
page.updated.toDate().should.not.eql(stats.mtime);

await Promise.all([
page.remove(),
unlink(file.source)
]);
});

it('page - permalink', async () => {
const body = [
'title: "Hello world"',
Expand Down
60 changes: 0 additions & 60 deletions test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,66 +622,6 @@ describe('post', () => {
]);
});

it('post - use use_date_for_updated as a fallback', async () => {
const body = [
'title: "Hello world"',
'---'
].join('\n');

const file = newFile({
path: 'foo.html',
published: true,
type: 'create',
renderable: true
});

hexo.config.use_date_for_updated = true;

await writeFile(file.source, body);
const stats = await file.stat();
await process(file);
const post = Post.findOne({ source: file.path });

post.date.toDate().setMilliseconds(0).should.eql(stats.birthtime.setMilliseconds(0));
post.updated.toDate().setMilliseconds(0).should.eql(stats.birthtime.setMilliseconds(0));

return Promise.all([
post.remove(),
unlink(file.source)
]);
});

it('post - ignore updated_option when use_date_for_updated is set', async () => {
const body = [
'date: 2011-4-5 14:19:19',
'title: "Hello world"',
'---'
].join('\n');

const file = newFile({
path: 'foo.html',
published: true,
type: 'create',
renderable: true
});

hexo.config.use_date_for_updated = true;
hexo.config.updated_option = 'mtime';

await writeFile(file.source, body);
const stats = await file.stat();
await process(file);
const post = Post.findOne({ source: file.path });

post.updated.toDate().setMilliseconds(0).should.eql(post.date.toDate().setMilliseconds(0));
post.updated.toDate().setMilliseconds(0).should.not.eql(stats.mtime.setMilliseconds(0));

return Promise.all([
post.remove(),
unlink(file.source)
]);
});

it('post - photo is an alias for photos', async () => {
const body = [
'title: "Hello world"',
Expand Down