From e20e621c73c301c2301757fc9d0b4ca84175cd0f Mon Sep 17 00:00:00 2001 From: curben <2809763-curben@users.noreply.gitlab.com> Date: Fri, 9 Aug 2019 22:32:51 +0930 Subject: [PATCH] style: standard --- themes/typing/scripts/cloudinary.js | 3 +++ themes/typing/scripts/copy-button.js | 3 +++ themes/typing/scripts/link.js | 5 ++++- themes/typing/scripts/listTags.js | 9 ++++++--- themes/typing/scripts/openGraph.js | 9 +++++---- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/themes/typing/scripts/cloudinary.js b/themes/typing/scripts/cloudinary.js index d4c50ea..d340576 100644 --- a/themes/typing/scripts/cloudinary.js +++ b/themes/typing/scripts/cloudinary.js @@ -1,3 +1,6 @@ +'use strict' +/* global hexo */ + /* * Put {% cloudinary 'folder/filename.jpg' 'description' %} in your post. * Change the username in data-src tag diff --git a/themes/typing/scripts/copy-button.js b/themes/typing/scripts/copy-button.js index e248ba0..78301f5 100644 --- a/themes/typing/scripts/copy-button.js +++ b/themes/typing/scripts/copy-button.js @@ -1,3 +1,6 @@ +'use strict' +/* global hexo */ + /* * Add "Copy" button to code snippet * cheerio is provided by hexo package diff --git a/themes/typing/scripts/link.js b/themes/typing/scripts/link.js index bd42e9f..2ff4144 100644 --- a/themes/typing/scripts/link.js +++ b/themes/typing/scripts/link.js @@ -1,3 +1,6 @@ +'use strict' +/* global hexo */ + /* * Modified from the hexo version, * https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/link_to.js @@ -8,7 +11,7 @@ const { htmlTag } = require('hexo-util') -function linkHelper(path, text) { +function linkHelper (path, text) { if (!text) text = path.replace(/^https?:\/\/|\/$/g, '') const attrs = Object.assign({ diff --git a/themes/typing/scripts/listTags.js b/themes/typing/scripts/listTags.js index 86fd595..9768235 100644 --- a/themes/typing/scripts/listTags.js +++ b/themes/typing/scripts/listTags.js @@ -1,3 +1,6 @@ +'use strict' +/* global hexo */ + /* * Modified from the hexo version, * https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/list_tags.js @@ -7,8 +10,8 @@ 'use strict' -function listTagsHelper(tags, options) { - if (!options && (!tags || !tags.hasOwnProperty('length'))) { +function listTagsHelper (tags, options) { + if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { options = tags tags = this.site.tags } @@ -17,7 +20,7 @@ function listTagsHelper(tags, options) { options = options || {} const { style = 'list', transform, separator = ', ', suffix = '' } = options - const showCount = options.hasOwnProperty('show_count') ? options.show_count : true + const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count') ? options.show_count : true const className = options.class || 'tag' const orderby = options.orderby || 'name' const order = options.order || 1 diff --git a/themes/typing/scripts/openGraph.js b/themes/typing/scripts/openGraph.js index 4828351..b766202 100644 --- a/themes/typing/scripts/openGraph.js +++ b/themes/typing/scripts/openGraph.js @@ -1,3 +1,6 @@ +'use strict' +/* global hexo */ + /* * Modified from the hexo version, * https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/open_graph.js @@ -8,7 +11,6 @@ 'use strict' -const urlFn = require('url') const moment = require('moment') const { escapeHTML, htmlTag, stripHTML } = require('hexo-util') const cheerio = require('cheerio') @@ -102,10 +104,10 @@ function openGraphHelper (options = {}) { } images = images.map(path => { - if (!urlFn.parse(path).host) { + if (!new URL(path).host) { // resolve `path`'s absolute path relative to current page's url // `path` can be both absolute (starts with `/`) or relative. - return urlFn.resolve(url || config.url, path) + return new URL(path, url || config.url) } return path @@ -115,7 +117,6 @@ function openGraphHelper (options = {}) { result += og('og:image', path, false) }) - if (published) { if ((moment.isMoment(published) || moment.isDate(published)) && !isNaN(published.valueOf())) { // Skip timezone conversion