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: simplify code #4409

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 1 addition & 13 deletions lib/plugins/helper/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@

const { htmlTag } = require('hexo-util');

const flatten = function(arr, result = []) {
for (const i in arr) {
const value = arr[i];
if (Array.isArray(value)) {
flatten(value, result);
} else {
result.push(value);
}
}
return result;
};

function cssHelper(...args) {
let result = '\n';

flatten(args).forEach(item => {
args.flat().forEach(item => {
// Old syntax
if (typeof item === 'string' || item instanceof String) {
let path = item;
Expand Down
16 changes: 1 addition & 15 deletions lib/plugins/helper/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,10 @@

const { htmlTag } = require('hexo-util');

/* flatten() to be replaced by Array.flat()
after Node 10 has reached EOL */
const flatten = function(arr, result = []) {
for (const i in arr) {
const value = arr[i];
if (Array.isArray(value)) {
flatten(value, result);
} else {
result.push(value);
}
}
return result;
};

function jsHelper(...args) {
let result = '\n';

flatten(args).forEach(item => {
args.flat().forEach(item => {
// Old syntax
if (typeof item === 'string' || item instanceof String) {
let path = item;
Expand Down