Skip to content

Commit

Permalink
chore(deps): update hexo-front-matter from 1.0.0 to 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jul 25, 2020
1 parent 9076422 commit 5ad9d73
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
19 changes: 9 additions & 10 deletions lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const { magenta } = require('chalk');
const { load } = require('js-yaml');
const { slugize, escapeRegExp } = require('hexo-util');
const { copyDir, exists, listDir, mkdirs, readFile, rmdir, unlink, writeFile } = require('hexo-fs');
const yfm = require('hexo-front-matter');

const { parse: yfmParse, split: yfmSplit, stringify: yfmStringify } = require('hexo-front-matter');
const preservedKeys = ['title', 'slug', 'path', 'layout', 'date', 'content'];

const rPlaceholder = /(?:<|&lt;)!--\uFFFC(\d+)--(?:>|&gt;)/g;
Expand Down Expand Up @@ -128,15 +127,15 @@ class Post {

_renderScaffold(data) {
const { tag } = this.context.extend;
let yfmSplit;
let splited;

return this._getScaffold(data.layout).then(scaffold => {
const frontMatter = prepareFrontMatter({ ...data });
yfmSplit = yfm.split(scaffold);
splited = yfmSplit(scaffold);

return tag.render(yfmSplit.data, frontMatter);
return tag.render(splited.data, frontMatter);
}).then(frontMatter => {
const { separator } = yfmSplit;
const { separator } = splited;
const jsonMode = separator.startsWith(';');

// Parse front-matter
Expand All @@ -151,14 +150,14 @@ class Post {

let content = '';
// Prepend the separator
if (yfmSplit.prefixSeparator) content += `${separator}\n`;
if (splited.prefixSeparator) content += `${separator}\n`;

content += yfm.stringify(obj, {
content += yfmStringify(obj, {
mode: jsonMode ? 'json' : ''
});

// Concat content
content += yfmSplit.content;
content += splited.content;

if (data.content) {
content += `\n${data.content}`;
Expand Down Expand Up @@ -197,7 +196,7 @@ class Post {
return readFile(src);
}).then(content => {
// Create post
Object.assign(data, yfm(content));
Object.assign(data, yfmParse(content));
data.content = data._content;
delete data._content;

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/processor/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { timezone, toDate, isExcludedFile, isMatch } = require('./common');
const Promise = require('bluebird');
const yfm = require('hexo-front-matter');
const { parse: yfm } = require('hexo-front-matter');
const { extname, relative } = require('path');
const { Pattern } = require('hexo-util');

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch } = require('./common');
const Promise = require('bluebird');
const yfm = require('hexo-front-matter');
const { parse: yfm } = require('hexo-front-matter');
const { extname, join } = require('path');
const { stat, listDir } = require('hexo-fs');
const { slugize, Pattern, Permalink } = require('hexo-util');
Expand Down
2 changes: 1 addition & 1 deletion lib/theme/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { dirname, extname, join } = require('path');
const yfm = require('hexo-front-matter');
const { parse: yfm } = require('hexo-front-matter');
const Promise = require('bluebird');

const assignIn = (target, ...sources) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"bluebird": "^3.5.2",
"chalk": "^4.0.0",
"hexo-cli": "^3.0.0",
"hexo-front-matter": "^1.0.0",
"hexo-front-matter": "^2.0.0",
"hexo-fs": "^3.1.0",
"hexo-i18n": "^1.0.0",
"hexo-log": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Promise = require('bluebird');
const { readFile, mkdirs, unlink, rmdir, writeFile, exists, stat, listDir } = require('hexo-fs');
const { highlight, escapeHTML } = require('hexo-util');
const { spy, useFakeTimers } = require('sinon');
const frontMatter = require('hexo-front-matter');
const { parse: yfm } = require('hexo-front-matter');
const fixture = require('../../fixtures/post_render');
const escapeSwigTag = str => str.replace(/{/g, '&#123;').replace(/}/g, '&#125;');

Expand Down Expand Up @@ -573,7 +573,7 @@ describe('Post', () => {
}).then(data => post.publish({
slug: 'foo'
})).then(data => {
const meta = frontMatter(data.content);
const meta = yfm(data.content);
meta.tags.should.eql(['tag', 'test']);
return unlink(data.path);
}));
Expand Down

0 comments on commit 5ad9d73

Please sign in to comment.