From fe707563663c05afe02f3681c5d7f8f1d3a06b8c Mon Sep 17 00:00:00 2001 From: ppoffice Date: Wed, 22 Jan 2020 23:07:43 -0500 Subject: [PATCH] refactor(*): use hexo-component-inferno --- include/config.js | 6 +- include/filter/locals.js | 66 ----- include/generator/categories.js | 14 - include/generator/tags.js | 14 - include/helper/cdn.js | 99 ------- include/helper/page.js | 16 - include/helper/thumbnail.js | 24 -- include/migration/v2_v3.js | 4 +- include/register.js | 19 +- include/schema/comment/.gitkeep | 0 include/schema/comment/changyan.json | 25 -- include/schema/comment/disqus.json | 20 -- include/schema/comment/disqusjs.json | 58 ---- include/schema/comment/facebook.json | 15 - include/schema/comment/gitalk.json | 83 ------ include/schema/comment/gitment.json | 53 ---- include/schema/comment/isso.json | 20 -- include/schema/comment/livere.json | 20 -- include/schema/comment/valine.json | 102 ------- include/schema/donate/.gitkeep | 0 include/schema/donate/alipay.json | 20 -- include/schema/donate/buymeacoffee.json | 20 -- include/schema/donate/patreon.json | 20 -- include/schema/donate/paypal.json | 28 -- include/schema/donate/wechat.json | 20 -- include/schema/misc/.gitkeep | 0 include/schema/misc/meta.json | 11 - include/schema/misc/open_graph.json | 81 ------ include/schema/misc/poly_links.json | 41 --- include/schema/misc/structured_data.json | 40 --- include/schema/plugin/baidu_analytics.json | 16 - include/schema/plugin/busuanzi.json | 7 - include/schema/plugin/gallery.json | 7 - include/schema/plugin/google_analytics.json | 16 - include/schema/plugin/hotjar.json | 19 -- include/schema/plugin/katex.json | 7 - include/schema/plugin/mathjax.json | 7 - include/schema/plugin/outdated_browser.json | 7 - include/schema/plugin/progressbar.json | 7 - include/schema/search/baidu.json | 15 - include/schema/search/google_cse.json | 20 -- include/schema/share/.gitkeep | 0 include/schema/share/addthis.json | 20 -- include/schema/share/addtoany.json | 15 - include/schema/share/bdshare.json | 15 - include/schema/share/sharejs.json | 15 - include/schema/share/sharethis.json | 20 -- include/schema/widget/adsense.json | 25 -- include/schema/widget/archives.json | 15 - include/schema/widget/categories.json | 15 - include/schema/widget/links.json | 32 -- include/schema/widget/recent_posts.json | 15 - include/schema/widget/subscribe_email.json | 25 -- include/schema/widget/tags.json | 15 - include/schema/widget/toc.json | 15 - include/util/migrate.js | 110 ------- include/util/schema.js | 305 -------------------- include/util/yaml.js | 43 --- layout/archive.jsx | 4 +- layout/categories.jsx | 2 +- layout/comment/.gitkeep | 0 layout/comment/changyan.jsx | 30 -- layout/comment/disqus.jsx | 41 --- layout/comment/disqusjs.jsx | 68 ----- layout/comment/facebook.jsx | 28 -- layout/comment/gitalk.jsx | 79 ----- layout/comment/gitment.jsx | 58 ---- layout/comment/isso.jsx | 26 -- layout/comment/livere.jsx | 37 --- layout/comment/valine.jsx | 69 ----- layout/common/article-media.jsx | 28 -- layout/common/comment.jsx | 3 +- layout/common/donates.jsx | 3 +- layout/common/footer.jsx | 2 +- layout/common/head.jsx | 6 +- layout/common/navbar.jsx | 4 +- layout/common/plugins.jsx | 3 +- layout/common/search.jsx | 3 +- layout/common/share.jsx | 3 +- layout/common/widgets.jsx | 5 +- layout/donate/.gitkeep | 0 layout/donate/alipay.jsx | 30 -- layout/donate/buymeacoffee.jsx | 33 --- layout/donate/patreon.jsx | 29 -- layout/donate/paypal.jsx | 37 --- layout/donate/wechat.jsx | 30 -- layout/index.jsx | 2 +- layout/layout.jsx | 2 +- layout/misc/.gitkeep | 0 layout/misc/meta.jsx | 41 --- layout/misc/open_graph.jsx | 145 ---------- layout/misc/paginator.jsx | 53 ---- layout/misc/structured_data.jsx | 56 ---- layout/plugin/animejs.jsx | 2 +- layout/plugin/back_to_top.jsx | 2 +- layout/plugin/baidu_analytics.jsx | 28 -- layout/plugin/busuanzi.jsx | 15 - layout/plugin/gallery.jsx | 36 --- layout/plugin/google_analytics.jsx | 29 -- layout/plugin/hotjar.jsx | 31 -- layout/plugin/katex.jsx | 33 --- layout/plugin/mathjax.jsx | 43 --- layout/plugin/outdated_browser.jsx | 42 --- layout/plugin/progressbar.jsx | 20 -- layout/search/baidu.jsx | 48 --- layout/search/google_cse.jsx | 86 ------ layout/search/insight.jsx | 2 +- layout/share/.gitkeep | 0 layout/share/addthis.jsx | 26 -- layout/share/addtoany.jsx | 22 -- layout/share/bdshare.jsx | 23 -- layout/share/sharejs.jsx | 22 -- layout/share/sharethis.jsx | 26 -- layout/tags.jsx | 2 +- layout/util/cache.jsx | 48 --- layout/util/classname.jsx | 12 - layout/widget/adsense.jsx | 41 --- layout/widget/archives.jsx | 105 ------- layout/widget/categories.jsx | 108 ------- layout/widget/links.jsx | 45 --- layout/widget/profile.jsx | 2 +- layout/widget/recent_posts.jsx | 47 --- layout/widget/subscribe_email.jsx | 45 --- layout/widget/tags.jsx | 60 ---- layout/widget/toc.jsx | 126 -------- package.json | 8 +- source/css/base.styl | 28 -- source/css/plugin/back-to-top.styl | 12 + source/css/plugin/progressbar.styl | 14 + source/css/style.styl | 3 + 130 files changed, 75 insertions(+), 3894 deletions(-) delete mode 100644 include/filter/locals.js delete mode 100644 include/generator/categories.js delete mode 100644 include/generator/tags.js delete mode 100644 include/helper/cdn.js delete mode 100644 include/helper/page.js delete mode 100644 include/helper/thumbnail.js create mode 100644 include/schema/comment/.gitkeep delete mode 100644 include/schema/comment/changyan.json delete mode 100644 include/schema/comment/disqus.json delete mode 100644 include/schema/comment/disqusjs.json delete mode 100644 include/schema/comment/facebook.json delete mode 100644 include/schema/comment/gitalk.json delete mode 100644 include/schema/comment/gitment.json delete mode 100644 include/schema/comment/isso.json delete mode 100644 include/schema/comment/livere.json delete mode 100644 include/schema/comment/valine.json create mode 100644 include/schema/donate/.gitkeep delete mode 100644 include/schema/donate/alipay.json delete mode 100644 include/schema/donate/buymeacoffee.json delete mode 100644 include/schema/donate/patreon.json delete mode 100644 include/schema/donate/paypal.json delete mode 100644 include/schema/donate/wechat.json create mode 100644 include/schema/misc/.gitkeep delete mode 100644 include/schema/misc/meta.json delete mode 100644 include/schema/misc/open_graph.json delete mode 100644 include/schema/misc/poly_links.json delete mode 100644 include/schema/misc/structured_data.json delete mode 100644 include/schema/plugin/baidu_analytics.json delete mode 100644 include/schema/plugin/busuanzi.json delete mode 100644 include/schema/plugin/gallery.json delete mode 100644 include/schema/plugin/google_analytics.json delete mode 100644 include/schema/plugin/hotjar.json delete mode 100644 include/schema/plugin/katex.json delete mode 100644 include/schema/plugin/mathjax.json delete mode 100644 include/schema/plugin/outdated_browser.json delete mode 100644 include/schema/plugin/progressbar.json delete mode 100644 include/schema/search/baidu.json delete mode 100644 include/schema/search/google_cse.json create mode 100644 include/schema/share/.gitkeep delete mode 100644 include/schema/share/addthis.json delete mode 100644 include/schema/share/addtoany.json delete mode 100644 include/schema/share/bdshare.json delete mode 100644 include/schema/share/sharejs.json delete mode 100644 include/schema/share/sharethis.json delete mode 100644 include/schema/widget/adsense.json delete mode 100644 include/schema/widget/archives.json delete mode 100644 include/schema/widget/categories.json delete mode 100644 include/schema/widget/links.json delete mode 100644 include/schema/widget/recent_posts.json delete mode 100644 include/schema/widget/subscribe_email.json delete mode 100644 include/schema/widget/tags.json delete mode 100644 include/schema/widget/toc.json delete mode 100644 include/util/migrate.js delete mode 100644 include/util/schema.js delete mode 100644 include/util/yaml.js create mode 100644 layout/comment/.gitkeep delete mode 100644 layout/comment/changyan.jsx delete mode 100644 layout/comment/disqus.jsx delete mode 100644 layout/comment/disqusjs.jsx delete mode 100644 layout/comment/facebook.jsx delete mode 100644 layout/comment/gitalk.jsx delete mode 100644 layout/comment/gitment.jsx delete mode 100644 layout/comment/isso.jsx delete mode 100644 layout/comment/livere.jsx delete mode 100644 layout/comment/valine.jsx delete mode 100644 layout/common/article-media.jsx create mode 100644 layout/donate/.gitkeep delete mode 100644 layout/donate/alipay.jsx delete mode 100644 layout/donate/buymeacoffee.jsx delete mode 100644 layout/donate/patreon.jsx delete mode 100644 layout/donate/paypal.jsx delete mode 100644 layout/donate/wechat.jsx create mode 100644 layout/misc/.gitkeep delete mode 100644 layout/misc/meta.jsx delete mode 100644 layout/misc/open_graph.jsx delete mode 100644 layout/misc/paginator.jsx delete mode 100644 layout/misc/structured_data.jsx delete mode 100644 layout/plugin/baidu_analytics.jsx delete mode 100644 layout/plugin/busuanzi.jsx delete mode 100644 layout/plugin/gallery.jsx delete mode 100644 layout/plugin/google_analytics.jsx delete mode 100644 layout/plugin/hotjar.jsx delete mode 100644 layout/plugin/katex.jsx delete mode 100644 layout/plugin/mathjax.jsx delete mode 100644 layout/plugin/outdated_browser.jsx delete mode 100644 layout/plugin/progressbar.jsx delete mode 100644 layout/search/baidu.jsx delete mode 100644 layout/search/google_cse.jsx create mode 100644 layout/share/.gitkeep delete mode 100644 layout/share/addthis.jsx delete mode 100644 layout/share/addtoany.jsx delete mode 100644 layout/share/bdshare.jsx delete mode 100644 layout/share/sharejs.jsx delete mode 100644 layout/share/sharethis.jsx delete mode 100644 layout/util/cache.jsx delete mode 100644 layout/util/classname.jsx delete mode 100644 layout/widget/adsense.jsx delete mode 100644 layout/widget/archives.jsx delete mode 100644 layout/widget/categories.jsx delete mode 100644 layout/widget/links.jsx delete mode 100644 layout/widget/recent_posts.jsx delete mode 100644 layout/widget/subscribe_email.jsx delete mode 100644 layout/widget/tags.jsx delete mode 100644 layout/widget/toc.jsx create mode 100644 source/css/plugin/back-to-top.styl create mode 100644 source/css/plugin/progressbar.styl diff --git a/include/config.js b/include/config.js index e5c7092..f154fce 100644 --- a/include/config.js +++ b/include/config.js @@ -10,8 +10,8 @@ module.exports = hexo => { const SCHEMA_ROOT = path.join(hexo.theme_dir, 'include/schema/'); const CONFIG_PATH = path.join(hexo.theme_dir, '_config.yml'); - const yaml = require('../include/util/yaml'); - const { SchemaLoader } = require('../include/util/schema'); + const yaml = require('hexo-component-inferno/lib/util/yaml'); + const { SchemaLoader } = require('hexo-component-inferno/lib/core/schema'); const loader = SchemaLoader.load(require(path.join(SCHEMA_ROOT, 'config.json')), SCHEMA_ROOT); const schema = loader.getSchema('/config.json'); logger.info('=== Checking the configuration file ==='); @@ -32,7 +32,7 @@ module.exports = hexo => { let cfg = yaml.parse(cfgStr); // Check config version if (!process.argv.includes('--icarus-dont-upgrade-config')) { - const migrator = new(require('../include/util/migrate'))(path.join(hexo.theme_dir, 'include/migration')); + const migrator = new(require('hexo-component-inferno/lib/core/migrate'))(path.join(hexo.theme_dir, 'include/migration')); // Upgrade config if (migrator.isOudated(cfg.version)) { logger.info(`Your configuration file is outdated (${cfg.version} < ${migrator.getLatestVersion()}). ` diff --git a/include/filter/locals.js b/include/filter/locals.js deleted file mode 100644 index b2413e5..0000000 --- a/include/filter/locals.js +++ /dev/null @@ -1,66 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const yaml = require('js-yaml'); - -module.exports = hexo => { - const RESERVED_KEYS = { - post: Object.keys(require('hexo/lib/models/post')(hexo).paths), - page: Object.keys(require('hexo/lib/models/page')(hexo).paths) - }; - - function getThemeConfig(extension) { - if (fs.existsSync(path.join(hexo.theme_dir, '_config' + extension + '.yml'))) { - return yaml.safeLoad(fs.readFileSync(path.join(hexo.theme_dir, '_config' + extension + '.yml'))); - } - return null; - } - - const ALTERNATIVE_CONFIG = { - post: getThemeConfig('.post'), - page: getThemeConfig('.page') - }; - - function getExtraConfig(source, reservedKeys) { - const result = {}; - for (const key in source) { - if (!key.startsWith('_') && !reservedKeys.includes(key) && typeof source[key] !== 'function') { - result[key] = source[key]; - } - } - return result; - } - - hexo.extend.filter.register('template_locals', locals => { - // inject helper functions - locals.helper = {}; - const helpers = hexo.extend.helper.list(); - for (const name in helpers) { - locals.helper[name] = helpers[name].bind(locals); - } - if (typeof locals.__ === 'function') { - locals.helper.__ = locals.__; - } - if (typeof locals._p === 'function') { - locals.helper._p = locals._p; - } - - const page = locals.page; - if (page) { - if ((page.layout !== 'page' || page.layout !== 'post') && ALTERNATIVE_CONFIG[page.layout]) { - // load alternative config if exists - locals.config = Object.assign({}, Object.getPrototypeOf(locals).theme || locals.theme, ALTERNATIVE_CONFIG[page.layout]); - } else { - // site config already merged into theme config in hexo/lib/hexo/index.js#Hexo.prototype._generateLocals() - locals.config = Object.assign({}, Object.getPrototypeOf(locals).theme || locals.theme); - } - // merge page configs - if (page.__post === true) { - Object.assign(locals.config, getExtraConfig(page, RESERVED_KEYS.page)); - } else if (page.__page === true) { - Object.assign(locals.config, getExtraConfig(page, RESERVED_KEYS.page)); - } - } - - return locals; - }); -}; diff --git a/include/generator/categories.js b/include/generator/categories.js deleted file mode 100644 index e208ad4..0000000 --- a/include/generator/categories.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Category list page generator - */ -module.exports = function(hexo) { - hexo.extend.generator.register('categories', locals => { - return { - path: 'categories/', - layout: ['categories'], - data: Object.assign({}, locals, { - __categories: true - }) - }; - }); -}; diff --git a/include/generator/tags.js b/include/generator/tags.js deleted file mode 100644 index 87b9c7b..0000000 --- a/include/generator/tags.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Tag list page generator - */ -module.exports = function(hexo) { - hexo.extend.generator.register('tags', locals => { - return { - path: 'tags/', - layout: ['tags'], - data: Object.assign({}, locals, { - __tags: true - }) - }; - }); -}; diff --git a/include/helper/cdn.js b/include/helper/cdn.js deleted file mode 100644 index 7b65de9..0000000 --- a/include/helper/cdn.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * CDN static file resolvers. - * - * @example - * <%- cdn(package, version, filename) %> - * <%- fontcdn(fontName) %> - * <%- iconcdn() %> - */ - -const PROVIDERS = { - LIBRARY: { - cdnjs: '[cdnjs]https://cdnjs.cloudflare.com/ajax/libs/${ package }/${ version }/${ filename }', - loli: '[cdnjs]https://cdnjs.loli.net/ajax/libs/${ package }/${ version }/${ filename }', - jsdelivr: 'https://cdn.jsdelivr.net/npm/${ package }@${ version }/${ filename }', - unpkg: 'https://unpkg.com/${ package }@${ version }/${ filename }' - }, - FONT: { - google: 'https://fonts.googleapis.com/${ type }?family=${ fontname }', - loli: 'https://fonts.loli.net/${ type }?family=${ fontname }' - }, - ICON: { - fontawesome: 'https://use.fontawesome.com/releases/v5.12.0/css/all.css' - } -}; - -/** - * Convert npm library path to CDN.js path - */ -const CDNJS_FIXTURES = { - 'moment': (ver, fname) => [ - 'moment.js', ver, fname.startsWith('min/') ? fname.substr(4) : fname - ], - 'outdatedbrowser': (ver, fname) => [ - 'outdated-browser', ver, fname.startsWith('outdatedbrowser/') ? fname.substr(16) : fname - ], - 'highlight.js': (ver, fname) => [ - 'highlight.js', ver, fname.endsWith('.css') && fname.indexOf('.min.') === -1 - ? fname.substr(0, fname.length - 4) + '.min.css' : fname - ], - 'mathjax': (ver, fname) => [ - 'mathjax', ver, fname.startsWith('unpacked/') ? fname.substr(9) : fname - ], - 'katex': (ver, fname) => [ - 'KaTeX', ver, fname - ], - 'pace-js': (ver, fname) => [ - 'pace', ver, fname - ], - 'clipboard': (ver, fname) => [ - 'clipboard.js', ver, fname - ], - // disqusjs is not hosted on CDN.js - 'disqusjs': (ver, fname) => [] -}; - -module.exports = function(hexo) { - hexo.extend.helper.register('cdn', function(_package, version, filename) { - let { cdn = 'jsdelivr' } = typeof this.config.providers === 'object' ? this.config.providers : {}; - if (cdn in PROVIDERS.LIBRARY) { - cdn = PROVIDERS.LIBRARY[cdn]; - } - // cdn.js does not follow a GitHub npm style like jsdeliver and unpkg do. Patch it! - if (cdn === 'cdnjs' || cdn.startsWith('[cdnjs]')) { - if (cdn.startsWith('[cdnjs]')) { - cdn = cdn.substr(7); - } - if (filename.startsWith('dist/')) { - filename = filename.substr(5); - } - if (Object.prototype.hasOwnProperty.call(CDNJS_FIXTURES, _package)) { - [_package, version, filename] = CDNJS_FIXTURES[_package](version, filename); - // package is not hosted on CDN.js - if (!_package) { - cdn = 'jsdelivr'; - } - } - } - return cdn.replace(/\${\s*package\s*}/gi, _package) - .replace(/\${\s*version\s*}/gi, version) - .replace(/\${\s*filename\s*}/gi, filename); - }); - - hexo.extend.helper.register('fontcdn', function(fontName, type = 'css') { - let { fontcdn = 'google' } = typeof this.config.providers === 'object' ? this.config.providers : {}; - if (fontcdn in PROVIDERS.FONT) { - fontcdn = PROVIDERS.FONT[fontcdn]; - } - return fontcdn.replace(/\${\s*fontname\s*}/gi, fontName) - .replace(/\${\s*type\s*}/gi, type); - }); - - hexo.extend.helper.register('iconcdn', function() { - let { iconfont = 'fontawesome' } = typeof this.config.providers === 'object' ? this.config.providers : {}; - if (iconfont in PROVIDERS.ICON) { - iconfont = PROVIDERS.ICON[iconfont]; - } - return iconfont; - }); -}; diff --git a/include/helper/page.js b/include/helper/page.js deleted file mode 100644 index c010e6b..0000000 --- a/include/helper/page.js +++ /dev/null @@ -1,16 +0,0 @@ -/** -* Helper functions for page/post. -* -* @example -* <%- is_categories(page) %> -* <%- is_tags(page) %> -*/ -module.exports = function(hexo) { - hexo.extend.helper.register('is_categories', function(page = null) { - return (page === null ? this.page : page).__categories === true; - }); - - hexo.extend.helper.register('is_tags', function(page = null) { - return (page === null ? this.page : page).__tags === true; - }); -}; diff --git a/include/helper/thumbnail.js b/include/helper/thumbnail.js deleted file mode 100644 index 98f9a51..0000000 --- a/include/helper/thumbnail.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* Helper functions for post thumbnail. -* -* @example -* <%- has_thumbnail(post) %> -* <%- get_thumbnail(post) %> -*/ -module.exports = function(hexo) { - hexo.extend.helper.register('has_thumbnail', function(post) { - const { article } = this.config; - if (typeof post !== 'object') { - return false; - } - if (article && article.thumbnail === false) { - return false; - } - return 'thumbnail' in post && post.thumbnail; - }); - - hexo.extend.helper.register('get_thumbnail', function(post) { - const { url_for, has_thumbnail } = this.helper; - return url_for(has_thumbnail.call(this, post) ? post.thumbnail : '/img/thumbnail.svg'); - }); -}; diff --git a/include/migration/v2_v3.js b/include/migration/v2_v3.js index c35f522..67cbff5 100644 --- a/include/migration/v2_v3.js +++ b/include/migration/v2_v3.js @@ -1,13 +1,13 @@ const logger = require('hexo-log')(); const deepmerge = require('deepmerge'); -const Migration = require('../util/migrate').Migration; +const Migration = require('hexo-component-inferno/lib/core/migrate').Migration; module.exports = class extends Migration { constructor() { super('3.0.0', null); } - doMigrate(config) { + upgrade(config) { const result = deepmerge({}, config); result.head = { favicon: config.favicon || null, diff --git a/include/register.js b/include/register.js index 39bffd0..816b14f 100644 --- a/include/register.js +++ b/include/register.js @@ -1,15 +1,16 @@ const logger = require('hexo-log')(); module.exports = hexo => { - logger.info('=== Patching Hexo ==='); - require('../include/generator/categories')(hexo); - require('../include/generator/category')(hexo); - require('../include/generator/tags')(hexo); - require('../include/generator/insight')(hexo); - require('../include/filter/locals')(hexo); - require('../include/helper/cdn')(hexo); - require('../include/helper/page')(hexo); - require('../include/helper/thumbnail')(hexo); + logger.info('=== Registering Hexo extensions ==='); + require('hexo-component-inferno/lib/hexo/filter/locals')(hexo); + require('./generator/category')(hexo); + require('./generator/insight')(hexo); + require('hexo-component-inferno/lib/hexo/generator/categories')(hexo); + require('hexo-component-inferno/lib/hexo/generator/tags')(hexo); + require('hexo-component-inferno/lib/hexo/helper/cdn')(hexo); + require('hexo-component-inferno/lib/hexo/helper/page')(hexo); + require('hexo-component-inferno/lib/hexo/helper/thumbnail')(hexo); + require('hexo-component-inferno/lib/core/view').init(hexo); const hooks = [ 'after_render:html', diff --git a/include/schema/comment/.gitkeep b/include/schema/comment/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/schema/comment/changyan.json b/include/schema/comment/changyan.json deleted file mode 100644 index b27efc6..0000000 --- a/include/schema/comment/changyan.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/changyan.json", - "description": "Changyan comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "changyan" - }, - "app_id": { - "type": "string", - "description": "Changyan app ID" - }, - "conf": { - "type": "string", - "description": "Changyan configuration ID" - } - }, - "required": [ - "type", - "app_id", - "conf" - ] -} \ No newline at end of file diff --git a/include/schema/comment/disqus.json b/include/schema/comment/disqus.json deleted file mode 100644 index 1e8c07a..0000000 --- a/include/schema/comment/disqus.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/disqus.json", - "description": "Disqus comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "disqus" - }, - "shortname": { - "type": "string", - "description": "Disqus shortname" - } - }, - "required": [ - "type", - "shortname" - ] -} \ No newline at end of file diff --git a/include/schema/comment/disqusjs.json b/include/schema/comment/disqusjs.json deleted file mode 100644 index cc53d01..0000000 --- a/include/schema/comment/disqusjs.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/disqusjs.json", - "description": "DisqusJS comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "disqusjs" - }, - "shortname": { - "type": "string", - "description": "Disqus shortname" - }, - "api_key": { - "description": "Disqus application API key", - "anyOf": [ - { - "type": "string" - }, - { - "type": "array", - "items": [ - { - "type": "string" - } - ] - } - ] - }, - "api": { - "type": "string", - "description": "Disqus API endpoint" - }, - "admin": { - "type": "string", - "description": "Disqus moderator username", - "nullable": true - }, - "admin_label": { - "type": "string", - "description": "Disqus moderator badge text", - "default": false, - "nullable": true - }, - "nesting": { - "type": "integer", - "description": "Maximum number of comment nesting level", - "default": 4, - "nullable": true - } - }, - "required": [ - "type", - "shortname", - "api_key" - ] -} \ No newline at end of file diff --git a/include/schema/comment/facebook.json b/include/schema/comment/facebook.json deleted file mode 100644 index 11ceb02..0000000 --- a/include/schema/comment/facebook.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/facebook.json", - "description": "Facebook comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "facebook" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/comment/gitalk.json b/include/schema/comment/gitalk.json deleted file mode 100644 index 231cd5b..0000000 --- a/include/schema/comment/gitalk.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/gitalk.json", - "description": "Gitalk comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "gitalk" - }, - "client_id": { - "type": "string", - "description": "GitHub application client ID" - }, - "client_secret": { - "type": "string", - "description": "GitHub application client secret" - }, - "repo": { - "type": "string", - "description": "GitHub repository" - }, - "owner": { - "type": "string", - "description": "GitHub repository owner. Can be personal user or organization" - }, - "admin": { - "type": "array", - "description": "GitHub repository owner and collaborators. (Users who having write access to this repository)", - "items": { - "type": "string" - } - }, - "per_page": { - "type": "number", - "description": "Pagination size, with maximum 100", - "default": 10, - "nullable": true - }, - "distraction_free_mode": { - "type": "boolean", - "description": "Facebook-like distraction free mode", - "default": false, - "nullable": true - }, - "pager_direction": { - "type": "string", - "description": "Comment sorting direction, available values are `last` and `first`", - "default": "last", - "nullable": true - }, - "create_issue_manually": { - "type": "boolean", - "description": "Create GitHub issues manually for each page", - "default": false, - "nullable": true - }, - "proxy": { - "type": "string", - "description": "GitHub oauth request reverse proxy for CORS", - "nullable": true - }, - "flip_move_options": { - "type": "object", - "description": "Comment list animation", - "nullable": true - }, - "enable_hotkey": { - "type": "boolean", - "description": "Enable hot key (cmd|ctrl + enter) submit comment", - "default": true, - "nullable": true - } - }, - "required": [ - "type", - "client_id", - "client_secret", - "repo", - "owner", - "admin" - ] -} \ No newline at end of file diff --git a/include/schema/comment/gitment.json b/include/schema/comment/gitment.json deleted file mode 100644 index c9fd071..0000000 --- a/include/schema/comment/gitment.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/gitment.json", - "description": "Gitment comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "gitment" - }, - "owner": { - "type": "string", - "description": "Your GitHub ID" - }, - "repo": { - "type": "string", - "description": "The repository to store your comments. Make sure you're repo's owner" - }, - "client_id": { - "type": "string", - "description": "GitHub client ID" - }, - "client_secret": { - "type": "string", - "description": "GitHub client secret" - }, - "theme": { - "type": "string", - "description": "An optional Gitment theme object", - "default": "gitment.defaultTheme", - "nullable": true - }, - "per_page": { - "type": "number", - "description": "An optional number to which comments will be paginated", - "default": 20, - "nullable": true - }, - "max_comment_height": { - "type": "number", - "description": "An optional number to limit comments' max height, over which comments will be folded", - "default": 250, - "nullable": true - } - }, - "required": [ - "type", - "owner", - "repo", - "client_id", - "client_secret" - ] -} \ No newline at end of file diff --git a/include/schema/comment/isso.json b/include/schema/comment/isso.json deleted file mode 100644 index 6ad0825..0000000 --- a/include/schema/comment/isso.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/isso.json", - "description": "Isso comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "isso" - }, - "url": { - "type": "string", - "description": "URL to your Isso comment service" - } - }, - "required": [ - "type", - "url" - ] -} \ No newline at end of file diff --git a/include/schema/comment/livere.json b/include/schema/comment/livere.json deleted file mode 100644 index 1459882..0000000 --- a/include/schema/comment/livere.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/livere.json", - "description": "Livere comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "livere" - }, - "uid": { - "type": "string", - "description": "LiveRe comment service UID" - } - }, - "required": [ - "type", - "uid" - ] -} \ No newline at end of file diff --git a/include/schema/comment/valine.json b/include/schema/comment/valine.json deleted file mode 100644 index 0ae4ea9..0000000 --- a/include/schema/comment/valine.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/comment/valine.json", - "description": "Valine comment plugin configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "valine" - }, - "app_id": { - "type": "string", - "description": "Application from Leancloud" - }, - "app_key": { - "type": "string", - "description": "Application from Leancloud" - }, - "placeholder": { - "type": "string", - "description": "Comment box placeholders", - "nullable": true - }, - "notify": { - "type": "boolean", - "description": "Enable email notification when someone comments", - "default": false, - "nullable": true - }, - "verify": { - "type": "boolean", - "description": "Enable verification code service", - "default": false, - "nullable": true - }, - "avatar": { - "type": "string", - "description": "Gravatar type", - "enum": [ - "", - "mp", - "identicon", - "monsterid", - "wavatar", - "robohash", - "retro", - "hide", - "mm" - ], - "default": "mm", - "nullable": true - }, - "avatar_force": { - "type": "boolean", - "description": "Pull the latest avatar upon page visit", - "default": false, - "nullable": true - }, - "meta": { - "type": "array", - "description": "Reviewer attributes", - "items": { - "type": "string" - }, - "default": [ - "nick", - "mail", - "link" - ], - "nullable": true - }, - "page_size": { - "type": "integer", - "description": "Number of comments per page", - "default": 10, - "nullable": true - }, - "visitor": { - "type": "boolean", - "description": "Show visitor count", - "default": false, - "nullable": true - }, - "highlight": { - "type": "boolean", - "description": "Enable code highlighting", - "default": true, - "nullable": true - }, - "record_ip": { - "type": "boolean", - "description": "Record reviewer IP address", - "default": false, - "nullable": true - } - }, - "required": [ - "type", - "app_id", - "app_key" - ] -} \ No newline at end of file diff --git a/include/schema/donate/.gitkeep b/include/schema/donate/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/schema/donate/alipay.json b/include/schema/donate/alipay.json deleted file mode 100644 index 3ba2aa2..0000000 --- a/include/schema/donate/alipay.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/donate/alipay.json", - "description": "Alipay donate button configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "alipay" - }, - "qrcode": { - "type": "string", - "description": "Alipay qrcode image URL" - } - }, - "required": [ - "type", - "qrcode" - ] -} \ No newline at end of file diff --git a/include/schema/donate/buymeacoffee.json b/include/schema/donate/buymeacoffee.json deleted file mode 100644 index c51a0f7..0000000 --- a/include/schema/donate/buymeacoffee.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/donate/buymeacoffee.json", - "description": "\"Buy me a coffee\" donate button configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "buymeacoffee" - }, - "url": { - "type": "string", - "description": "URL to the \"Buy me a coffee\" page" - } - }, - "required": [ - "type", - "url" - ] -} \ No newline at end of file diff --git a/include/schema/donate/patreon.json b/include/schema/donate/patreon.json deleted file mode 100644 index f3c2c9c..0000000 --- a/include/schema/donate/patreon.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/donate/patreon.json", - "description": "Patreon donate button configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "patreon" - }, - "url": { - "type": "string", - "description": "URL to the Patreon page" - } - }, - "required": [ - "type", - "url" - ] -} \ No newline at end of file diff --git a/include/schema/donate/paypal.json b/include/schema/donate/paypal.json deleted file mode 100644 index d19a421..0000000 --- a/include/schema/donate/paypal.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/donate/paypal.json", - "description": "Paypal donate button configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "paypal" - }, - "business": { - "type": "string", - "description": "Paypal business ID or email address" - }, - "currency_code": { - "type": "string", - "description": "Currency code", - "examples": [ - "USD" - ] - } - }, - "required": [ - "type", - "business", - "currency_code" - ] -} \ No newline at end of file diff --git a/include/schema/donate/wechat.json b/include/schema/donate/wechat.json deleted file mode 100644 index a50cfc0..0000000 --- a/include/schema/donate/wechat.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/donate/wechat.json", - "description": "Wechat donate button configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "wechat" - }, - "qrcode": { - "type": "string", - "description": "Wechat qrcode image URL" - } - }, - "required": [ - "type", - "qrcode" - ] -} \ No newline at end of file diff --git a/include/schema/misc/.gitkeep b/include/schema/misc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/schema/misc/meta.json b/include/schema/misc/meta.json deleted file mode 100644 index ba24a0d..0000000 --- a/include/schema/misc/meta.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/misc/meta.json", - "description": "Additional HTML meta tags in an array", - "type": "array", - "items": { - "type": "string", - "description": "Meta tag specified in = style\nE.g., name=theme-color;content=#123456 => " - }, - "nullable": true -} \ No newline at end of file diff --git a/include/schema/misc/open_graph.json b/include/schema/misc/open_graph.json deleted file mode 100644 index 28b51d5..0000000 --- a/include/schema/misc/open_graph.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/misc/open_graph.json", - "description": "Open Graph metadata\nhttps://hexo.io/docs/helpers.html#open-graph", - "type": "object", - "properties": { - "title": { - "type": "string", - "description": "Page title (og:title) (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "type": { - "type": "string", - "description": "Page type (og:type) (optional)\nYou should leave this blank for most of the time", - "default": "blog", - "nullable": true - }, - "url": { - "type": "string", - "description": "Page URL (og:url) (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "image": { - "type": [ - "string", - "array" - ], - "description": "Page cover (og:image) (optional) Default to the Open Graph image or thumbnail of the page\nYou should leave this blank for most of the time", - "items": { - "type": "string" - }, - "nullable": true - }, - "site_name": { - "type": "string", - "description": "Site name (og:site_name) (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "author": { - "type": "string", - "description": "Page author (article:author) (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "description": { - "type": "string", - "description": "Page description (og:description) (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "twitter_card": { - "type": "string", - "description": "Twitter card type (twitter:card)", - "nullable": true - }, - "twitter_id": { - "type": "string", - "description": "Twitter ID (twitter:creator)", - "nullable": true - }, - "twitter_site": { - "type": "string", - "description": "Twitter ID (twitter:creator)", - "nullable": true - }, - "google_plus": { - "type": "string", - "description": "Google+ profile link (deprecated)", - "nullable": true - }, - "fb_admins": { - "type": "string", - "description": "Facebook admin ID", - "nullable": true - }, - "fb_app_id": { - "type": "string", - "description": "Facebook App ID", - "nullable": true - } - }, - "nullable": true -} \ No newline at end of file diff --git a/include/schema/misc/poly_links.json b/include/schema/misc/poly_links.json deleted file mode 100644 index 0ad425a..0000000 --- a/include/schema/misc/poly_links.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/misc/poly_links.json", - "description": "A polymorphic link", - "type": "object", - "patternProperties": { - ".+": { - "type": [ - "string", - "object" - ], - "description": "URL or path of the link, with/without the icon element class name", - "properties": { - "url": { - "type": "string", - "description": "URL or path of the link" - }, - "icon": { - "type": "string", - "description": "Icon element class name" - } - }, - "required": [ - "url", - "icon" - ] - } - }, - "examples": [ - { - "My GitHub Page": "https://github.com/ppoffice" - }, - { - "My GitHub Page": { - "url": "https://github.com/ppoffice", - "icon": "fab fa-github" - } - } - ], - "nullable": true -} \ No newline at end of file diff --git a/include/schema/misc/structured_data.json b/include/schema/misc/structured_data.json deleted file mode 100644 index 9ea8334..0000000 --- a/include/schema/misc/structured_data.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/misc/structured_data.json", - "description": "Structured data of the page\nhttps://developers.google.com/search/docs/guides/intro-structured-data", - "type": "object", - "properties": { - "title": { - "type": "string", - "description": "Page title (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "description": { - "type": "string", - "description": "Page description (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "url": { - "type": "string", - "description": "Page URL (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "author": { - "type": "string", - "description": "Page author (article:author) (optional)\nYou should leave this blank for most of the time", - "nullable": true - }, - "image": { - "type": [ - "string", - "array" - ], - "description": "Page images (optional) Default to the Open Graph image or thumbnail of the page\nYou should leave this blank for most of the time", - "items": { - "type": "string" - }, - "nullable": true - } - }, - "nullable": true -} \ No newline at end of file diff --git a/include/schema/plugin/baidu_analytics.json b/include/schema/plugin/baidu_analytics.json deleted file mode 100644 index 543577f..0000000 --- a/include/schema/plugin/baidu_analytics.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/baidu_analytics.json", - "description": "Baidu Analytics plugin settings\nhttps://tongji.baidu.com", - "type": "object", - "properties": { - "tracking_id": { - "type": "string", - "description": "Baidu Analytics tracking ID", - "nullable": true - } - }, - "required": [ - "tracking_id" - ] -} \ No newline at end of file diff --git a/include/schema/plugin/busuanzi.json b/include/schema/plugin/busuanzi.json deleted file mode 100644 index a9f4d27..0000000 --- a/include/schema/plugin/busuanzi.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/busuanzi.json", - "description": "BuSuanZi site/page view counter\nhttps://busuanzi.ibruce.info", - "type": "boolean", - "default": false -} \ No newline at end of file diff --git a/include/schema/plugin/gallery.json b/include/schema/plugin/gallery.json deleted file mode 100644 index b8aa3c0..0000000 --- a/include/schema/plugin/gallery.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/gallery.json", - "description": "Enable the lightGallery and Justified Gallery plugins\nhttps://ppoffice.github.io/hexo-theme-icarus/Plugins/General/gallery-plugin/", - "type": "boolean", - "default": true -} \ No newline at end of file diff --git a/include/schema/plugin/google_analytics.json b/include/schema/plugin/google_analytics.json deleted file mode 100644 index 9846152..0000000 --- a/include/schema/plugin/google_analytics.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/google_analytics.json", - "description": "Google Analytics plugin settings\nhttps://analytics.google.com", - "type": "object", - "properties": { - "tracking_id": { - "type": "string", - "description": "Google Analytics tracking ID", - "nullable": true - } - }, - "required": [ - "tracking_id" - ] -} \ No newline at end of file diff --git a/include/schema/plugin/hotjar.json b/include/schema/plugin/hotjar.json deleted file mode 100644 index 1ec6d0e..0000000 --- a/include/schema/plugin/hotjar.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/hotjar.json", - "description": "Hotjar user feedback plugin\nhttps://www.hotjar.com/", - "type": "object", - "properties": { - "site_id": { - "type": [ - "string", - "number" - ], - "description": "Hotjar site id", - "nullable": true - } - }, - "required": [ - "site_id" - ] -} \ No newline at end of file diff --git a/include/schema/plugin/katex.json b/include/schema/plugin/katex.json deleted file mode 100644 index 2991b62..0000000 --- a/include/schema/plugin/katex.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/katex.json", - "description": "Enable the KaTeX math typesetting supprot\nhttps://katex.org/", - "type": "boolean", - "default": false -} \ No newline at end of file diff --git a/include/schema/plugin/mathjax.json b/include/schema/plugin/mathjax.json deleted file mode 100644 index 26387e8..0000000 --- a/include/schema/plugin/mathjax.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/mathjax.json", - "description": "Enable the MathJax math typesetting support\nhttps://www.mathjax.org/", - "type": "boolean", - "default": false -} \ No newline at end of file diff --git a/include/schema/plugin/outdated_browser.json b/include/schema/plugin/outdated_browser.json deleted file mode 100644 index 31efbc4..0000000 --- a/include/schema/plugin/outdated_browser.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/outdated_browser.json", - "description": "Enable the Outdated Browser plugin\nhttp://outdatedbrowser.com/", - "type": "boolean", - "default": false -} \ No newline at end of file diff --git a/include/schema/plugin/progressbar.json b/include/schema/plugin/progressbar.json deleted file mode 100644 index 6ad74d1..0000000 --- a/include/schema/plugin/progressbar.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/plugin/progressbar.json", - "description": "Show a progress bar at top of the page on page loading", - "type": "boolean", - "default": true -} \ No newline at end of file diff --git a/include/schema/search/baidu.json b/include/schema/search/baidu.json deleted file mode 100644 index 7b390cd..0000000 --- a/include/schema/search/baidu.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/search/baidu.json", - "description": "Enable Baidu search", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "baidu" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/search/google_cse.json b/include/schema/search/google_cse.json deleted file mode 100644 index a2afe12..0000000 --- a/include/schema/search/google_cse.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/search/google_cse.json", - "description": "Enable Google CSE\nhttps://cse.google.com/cse/create/new", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "google_cse" - }, - "cx": { - "type": "string", - "description": "Google CSE cx value" - } - }, - "required": [ - "type", - "cx" - ] -} \ No newline at end of file diff --git a/include/schema/share/.gitkeep b/include/schema/share/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/schema/share/addthis.json b/include/schema/share/addthis.json deleted file mode 100644 index 603866e..0000000 --- a/include/schema/share/addthis.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/share/addthis.json", - "description": "Enable AddThis share buttons\nhttps://www.addthis.com/", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "addthis" - }, - "install_url": { - "type": "string", - "description": "URL to the AddThis share plugin script" - } - }, - "required": [ - "type", - "install_url" - ] -} \ No newline at end of file diff --git a/include/schema/share/addtoany.json b/include/schema/share/addtoany.json deleted file mode 100644 index 2ed9af7..0000000 --- a/include/schema/share/addtoany.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/share/addtoany.json", - "description": "Enable AddToAny share buttons\nhttps://www.addtoany.com/", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "addtoany" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/share/bdshare.json b/include/schema/share/bdshare.json deleted file mode 100644 index 4e310d5..0000000 --- a/include/schema/share/bdshare.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/share/bdshare.json", - "description": "Enable Baidu share buttons", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "bdshare" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/share/sharejs.json b/include/schema/share/sharejs.json deleted file mode 100644 index 9b4d330..0000000 --- a/include/schema/share/sharejs.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/share/sharejs.json", - "description": "Enable Share.js share buttons\nhttps://github.com/overtrue/share.js/", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "sharejs" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/share/sharethis.json b/include/schema/share/sharethis.json deleted file mode 100644 index 6fc6c51..0000000 --- a/include/schema/share/sharethis.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/share/sharethis.json", - "description": "Enable ShareThis share buttons\nhttps://sharethis.com/", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "sharethis" - }, - "install_url": { - "type": "string", - "description": "URL to the ShareThis share plugin script" - } - }, - "required": [ - "type", - "install_url" - ] -} \ No newline at end of file diff --git a/include/schema/widget/adsense.json b/include/schema/widget/adsense.json deleted file mode 100644 index ed3815a..0000000 --- a/include/schema/widget/adsense.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/adsense.json", - "description": "Google AdSense unit configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "adsense" - }, - "client_id": { - "type": "string", - "description": "AdSense client ID" - }, - "slot_id": { - "type": "string", - "description": "AdSense AD unit ID" - } - }, - "required": [ - "type", - "client_id", - "slot_id" - ] -} \ No newline at end of file diff --git a/include/schema/widget/archives.json b/include/schema/widget/archives.json deleted file mode 100644 index 35d9244..0000000 --- a/include/schema/widget/archives.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/archives.json", - "description": "Archives widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "archives" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/widget/categories.json b/include/schema/widget/categories.json deleted file mode 100644 index 7fc2ec4..0000000 --- a/include/schema/widget/categories.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/categories.json", - "description": "Categories widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "categories" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/widget/links.json b/include/schema/widget/links.json deleted file mode 100644 index 2088018..0000000 --- a/include/schema/widget/links.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/links.json", - "description": "Recommendation links widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "links" - }, - "links": { - "type": "object", - "description": "Names and URLs of the sites", - "patternProperties": { - ".+": { - "type": "string", - "description": "URL of the site" - } - }, - "examples": [ - { - "Hexo": "https://hexo.io", - "Bulma": "https://bulma.io" - } - ], - "nullable": true - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/widget/recent_posts.json b/include/schema/widget/recent_posts.json deleted file mode 100644 index e19cf11..0000000 --- a/include/schema/widget/recent_posts.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/recent_posts.json", - "description": "Recent posts widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "recent_posts" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/widget/subscribe_email.json b/include/schema/widget/subscribe_email.json deleted file mode 100644 index 43b2c8a..0000000 --- a/include/schema/widget/subscribe_email.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/subscribe_email.json", - "description": "Google FeedBurner email subscription widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "subscribe_email" - }, - "description": { - "type": "string", - "description": "Hint text under the email input", - "nullable": true - }, - "feedburner_id": { - "type": "string", - "description": "Feedburner ID" - } - }, - "required": [ - "type", - "feedburner_id" - ] -} \ No newline at end of file diff --git a/include/schema/widget/tags.json b/include/schema/widget/tags.json deleted file mode 100644 index 4cb438a..0000000 --- a/include/schema/widget/tags.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/tags.json", - "description": "Tags widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "tags" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/schema/widget/toc.json b/include/schema/widget/toc.json deleted file mode 100644 index 911023e..0000000 --- a/include/schema/widget/toc.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "/widget/toc.json", - "description": "Table of contents widget configurations", - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "toc" - } - }, - "required": [ - "type" - ] -} \ No newline at end of file diff --git a/include/util/migrate.js b/include/util/migrate.js deleted file mode 100644 index d19e6a6..0000000 --- a/include/util/migrate.js +++ /dev/null @@ -1,110 +0,0 @@ -const path = require('path'); -const logger = require('hexo-log')(); - -class Version { - constructor(version) { - const ver = version.split('.').map(i => parseInt(i, 10)); - if (ver.length !== 3) { - throw new Error('Malformed version number ' + version); - } - this.major = ver[0]; - this.minor = ver[1]; - this.patch = ver[2]; - } - - toString() { - return `${this.major}.${this.minor}.${this.patch}`; - } -} - -Version.compare = function(a, b) { - if (!(a instanceof Version) || !(b instanceof Version)) { - throw new Error('Cannot compare non-Versions'); - } - if (a.major !== b.major) { - return a.major - b.major; - } - if (a.minor !== b.minor) { - return a.minor - b.minor; - } - if (a.patch !== b.patch) { - return a.patch - b.patch; - } - return 0; -}; - -class Migration { - - /** - * @param {string} version Target version - * @param {string} head File name of the previous migration - */ - constructor(version, head) { - this.version = new Version(version); - this.head = head; - } - - doMigrate(config) { - throw new Error('Not implemented!'); - } - - migrate(config) { - logger.info(`Updating configurations from ${config.version} to ${this.version.toString()}...`); - const result = this.doMigrate(config); - result.version = this.version.toString(); - return result; - } -} - - -class Migrator { - constructor(root) { - this.versions = []; - this.migrations = {}; - - let head = 'head'; - while (head) { - const migration = new(require(path.join(root, head)))(); - if (!(migration instanceof Migration)) { - throw new Error(`Migration ${head} is not a Migration class.`); - } - this.versions.push(migration.version); - this.migrations[migration.version.toString()] = migration; - head = migration.head; - } - - this.versions.sort(Version.compare); - } - - isOudated(version) { - if (!this.versions.length) { - return false; - } - return Version.compare(new Version(version), this.getLatestVersion()) < 0; - } - - getLatestVersion() { - if (!this.versions.length) { - return null; - } - return this.versions[this.versions.length - 1]; - } - - migrate(config, toVersion = null) { - const fVer = new Version(config.version); - const tVer = toVersion ? new Version(toVersion) : this.getLatestVersion(); - // find all migrations whose version is larger than fromVer, smaller or equal to toVer - // and run migrations on the config one by one - return this.versions.filter(ver => Version.compare(ver, fVer) > 0 && Version.compare(ver, tVer) <= 0) - .sort(Version.compare) - .reduce((cfg, ver) => { - const migration = this.migrations[ver.toString()]; - return migration.migrate(cfg); - }, config); - } -} - -Migrator.Version = Version; -Migrator.Migration = Migration; - -module.exports = Migrator; diff --git a/include/util/schema.js b/include/util/schema.js deleted file mode 100644 index abbfb03..0000000 --- a/include/util/schema.js +++ /dev/null @@ -1,305 +0,0 @@ -const Ajv = require('ajv'); -const path = require('path'); -const deepmerge = require('deepmerge'); -const yaml = require('./yaml'); - -const MAGIC = 'c823d4d4'; - -const PRIMITIVE_DEFAULTS = { - 'null': null, - 'boolean': false, - 'number': 0, - 'integer': 0, - 'string': '', - 'array': [], - 'object': {} -}; - -class DefaultValue { - constructor(value, description) { - this.value = value; - this.description = description; - } - - merge(source) { - if ('description' in source && source.description) { - this.description = source.description; - } - if ('value' in source && source.value) { - if (this.value instanceof DefaultValue) { - this.value.merge(source.value); - } else if (Array.isArray(this.value) && Array.isArray(source.value)) { - this.value.concat(...source.value); - } else if (typeof this.value === 'object' && typeof source.value === 'object') { - for (const key in source.value) { - this.value[key] = source.value[key]; - } - } else { - this.value = deepmerge(this.value, source.value); - } - } - return this; - } - - clone() { - const result = new DefaultValue(this.value, this.description); - if (result.value instanceof DefaultValue) { - result.value = result.value.clone(); - } else if (Array.isArray(result.value)) { - result.value = [].concat(...result.value); - } else if (typeof result.value === 'object') { - result.value = Object.assign({}, result.value); - } - return result; - } - - toCommentedArray() { - return [].concat(...this.value.map(item => { - if (item instanceof DefaultValue) { - if (typeof item.description !== 'string' || !item.description.trim()) { - return [item.toCommented()]; - } - return item.description.split('\n').map((line, i) => { - return MAGIC + i + ': ' + line; - }).concat(item.toCommented()); - } - return [item]; - })); - } - - toCommentedObject() { - if (this.value instanceof DefaultValue) { - return this.value.toCommented(); - } - const result = {}; - for (const key in this.value) { - const item = this.value[key]; - if (item instanceof DefaultValue) { - if (typeof item.description === 'string' && item.description.trim()) { - item.description.split('\n').forEach((line, i) => { - result[MAGIC + key + i] = line; - }); - } - result[key] = item.toCommented(); - } else { - result[key] = item; - } - } - return result; - } - - toCommented() { - if (Array.isArray(this.value)) { - return this.toCommentedArray(); - } else if (typeof this.value === 'object' && this.value !== null) { - return this.toCommentedObject(); - } - return this.value; - } - - toYaml() { - const regex = new RegExp('^(\\s*)(?:-\\s*\\\')?' + MAGIC + '.*?:\\s*\\\'?(.*?)\\\'*$', 'mg'); - return yaml.stringify(this.toCommented()).replace(regex, '$1# $2');// restore comments - } -} - -/* eslint-disable no-use-before-define */ -class Schema { - constructor(loader, def) { - if (!(loader instanceof SchemaLoader)) { - throw new Error('loader must be an instance of SchemaLoader'); - } - if (typeof def !== 'object') { - throw new Error('schema definition must be an object'); - } - this.loader = loader; - this.def = def; - this.compiledSchema = null; - } - - validate(obj) { - if (!this.compiledSchema) { - this.compiledSchema = this.loader.compileValidator(this.def.$id); - } - return this.compiledSchema(obj) ? true : this.compiledSchema.errors; - } - - getArrayDefaultValue(def) { - let value; - const defaultValue = new DefaultValue(null, def.description); - if ('items' in def && typeof def.items === 'object') { - const items = Object.assign({}, def.items); - delete items.oneOf; - value = this.getDefaultValue(items); - } - if ('oneOf' in def.items && Array.isArray(def.items.oneOf)) { - defaultValue.value = def.items.oneOf.map(one => { - if (!(value instanceof DefaultValue)) { - return this.getDefaultValue(one); - } - return value.clone().merge(this.getDefaultValue(one)); - }); - } else { - if (!Array.isArray(value)) { - value = [value]; - } - defaultValue.value = value; - } - return defaultValue; - } - - getObjectDefaultValue(def) { - const value = {}; - if ('properties' in def && typeof def.properties === 'object') { - for (const property in def.properties) { - value[property] = this.getDefaultValue(def.properties[property]); - } - } - const defaultValue = new DefaultValue(value, def.description); - if ('oneOf' in def && Array.isArray(def.oneOf) && def.oneOf.length) { - defaultValue.merge(this.getDefaultValue(def.oneOf[0])); - defaultValue.description = def.description; - } - return defaultValue; - } - - getTypedDefaultValue(def) { - let defaultValue; - const type = Array.isArray(def.type) ? def.type[0] : def.type; - if (type === 'array') { - defaultValue = this.getArrayDefaultValue(def); - } else if (type === 'object') { - defaultValue = this.getObjectDefaultValue(def); - } else if (type in PRIMITIVE_DEFAULTS) { - if ('nullable' in def && def.nullable) { - defaultValue = new DefaultValue(null, def.description); - } else { - defaultValue = new DefaultValue(PRIMITIVE_DEFAULTS[type], def.description); - } - } else { - throw new Error(`Cannot get default value for type ${type}`); - } - // referred default value always get overwritten by its parent default value - if ('$ref' in def && def.$ref) { - defaultValue = this.getReferredDefaultValue(def).merge(defaultValue); - } - return defaultValue; - } - - getReferredDefaultValue(def) { - const schema = this.loader.getSchema(def.$ref); - if (!schema) { - throw new Error(`Schema ${def.$ref} is not loaded`); - } - return this.getDefaultValue(schema.def).merge({ description: def.description }); - } - - getDefaultValue(def = null) { - if (!def) { - def = this.def; - } - if ('const' in def) { - return new DefaultValue(def.const, def.description); - } - if ('default' in def) { - return new DefaultValue(def.default, def.description); - } - if ('examples' in def && Array.isArray(def.examples) && def.examples.length) { - return new DefaultValue(def.examples[0], def.description); - } - if ('type' in def && def.type) { - return this.getTypedDefaultValue(def); - } - // $ref only schemas - if ('$ref' in def && def.$ref) { - return this.getReferredDefaultValue(def); - } - } -} - -class SchemaLoader { - constructor() { - this.schemas = {}; - this.ajv = new Ajv({ nullable: true }); - } - - getSchema($id) { - return this.schemas[$id]; - } - - addSchema(def) { - if (!Object.prototype.hasOwnProperty.call(def, '$id')) { - throw new Error('The schema definition does not have an $id field'); - } - this.ajv.addSchema(def); - this.schemas[def.$id] = new Schema(this, def); - } - - removeSchema($id) { - this.ajv.removeSchema($id); - delete this.schemas[$id]; - } - - compileValidator($id) { - return this.ajv.compile(this.schemas[$id].def); - } -} - -function traverseObj(obj, targetKey, handler) { - if (Array.isArray(obj)) { - for (const child of obj) { - traverseObj(child, targetKey, handler); - } - } else if (typeof obj === 'object') { - for (const key in obj) { - if (key === targetKey) { - handler(obj[key]); - } else { - traverseObj(obj[key], targetKey, handler); - } - } - } -} - -SchemaLoader.load = (rootSchemaDef, resolveDirs = []) => { - if (!Array.isArray(resolveDirs)) { - resolveDirs = [resolveDirs]; - } - - const loader = new SchemaLoader(); - loader.addSchema(rootSchemaDef); - - function handler($ref) { - if (typeof $ref !== 'string') { - throw new Error('Invalid schema reference id: ' + JSON.stringify($ref)); - } - if (loader.getSchema($ref)) { - return; - } - for (const dir of resolveDirs) { - let def; - try { - def = require(path.join(dir, $ref)); - } catch (e) { - continue; - } - if (typeof def !== 'object' || def.$id !== $ref) { - continue; - } - loader.addSchema(def); - traverseObj(def, '$ref', handler); - return; - } - throw new Error('Cannot find schema definition ' + $ref + '.\n' - + 'Please check if the file exists and its $id is correct'); - } - - traverseObj(rootSchemaDef, '$ref', handler); - return loader; -}; - -module.exports = { - Schema, - SchemaLoader, - DefaultValue -}; diff --git a/include/util/yaml.js b/include/util/yaml.js deleted file mode 100644 index 8a7050c..0000000 --- a/include/util/yaml.js +++ /dev/null @@ -1,43 +0,0 @@ -const yaml = require('js-yaml'); -const YamlType = require('js-yaml/lib/js-yaml/type'); -const YamlSchema = require('js-yaml/lib/js-yaml/schema'); - -// output null as empty in yaml -const YAML_SCHEMA = new YamlSchema({ - include: [ - require('js-yaml/lib/js-yaml/schema/default_full') - ], - implicit: [ - new YamlType('tag:yaml.org,2002:null', { - kind: 'scalar', - resolve(data) { - if (data === null) { - return true; - } - const max = data.length; - return (max === 1 && data === '~') - || (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL')); - }, - construct: () => null, - predicate: object => object === null, - represent: { - empty: () => '' - }, - defaultStyle: 'empty' - }) - ] -}); - -module.exports = { - parse(str) { - return yaml.safeLoad(str); - }, - - stringify(object) { - return yaml.safeDump(object, { - indent: 4, - lineWidth: 1024, - schema: YAML_SCHEMA - }); - } -}; diff --git a/layout/archive.jsx b/layout/archive.jsx index 9aa2dbb..7516755 100644 --- a/layout/archive.jsx +++ b/layout/archive.jsx @@ -1,7 +1,7 @@ const moment = require('moment'); const { Component, Fragment } = require('inferno'); -const Paginator = require('./misc/paginator'); -const ArticleMedia = require('./common/article-media'); +const Paginator = require('hexo-component-inferno/lib/view/misc/paginator'); +const ArticleMedia = require('hexo-component-inferno/lib/view/common/article-media'); module.exports = class extends Component { render() { diff --git a/layout/categories.jsx b/layout/categories.jsx index acb8922..2efa9cb 100644 --- a/layout/categories.jsx +++ b/layout/categories.jsx @@ -1,5 +1,5 @@ const { Component } = require('inferno'); -const Categories = require('./widget/categories'); +const Categories = require('hexo-component-inferno/lib/view/widget/categories'); module.exports = class extends Component { render() { diff --git a/layout/comment/.gitkeep b/layout/comment/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/layout/comment/changyan.jsx b/layout/comment/changyan.jsx deleted file mode 100644 index c8f212d..0000000 --- a/layout/comment/changyan.jsx +++ /dev/null @@ -1,30 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class ChangeYan extends Component { - render() { - const { appId, conf, path } = this.props; - if (!appId || !conf) { - return
- You forgot to set the app_id or conf for Changyan. - Please set it in _config.yml. -
; - } - const js = `window.changyan.api.config({appid: '${appId}',conf: '${conf}'});`; - return -
- - -
; - } -} - -module.exports = cacheComponent(ChangeYan, 'comment.changyan', props => { - const { comment, page } = props; - - return { - appId: comment.app_id, - conf: comment.conf, - path: page.path - }; -}); diff --git a/layout/comment/disqus.jsx b/layout/comment/disqus.jsx deleted file mode 100644 index dd3d302..0000000 --- a/layout/comment/disqus.jsx +++ /dev/null @@ -1,41 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Disqus extends Component { - render() { - const { shortname, disqusId, path, permalink } = this.props; - if (!shortname) { - return
- You forgot to set the shortname for Disqus. - Please set it in _config.yml. -
; - } - const js = `var disqus_config = function () { - this.page.url = '${permalink}'; - this.page.identifier = '${disqusId || path}'; - }; - (function() { - var d = document, s = d.createElement('script'); - s.src = '//' + '${shortname}' + '.disqus.com/embed.js'; - s.setAttribute('data-timestamp', +new Date()); - (d.head || d.body).appendChild(s); - })();`; - return -
- -
- -
; - } -} - -module.exports = cacheComponent(Disqus, 'comment.disqus', props => { - const { comment, page } = props; - - return { - path: page.path, - shortname: comment.shortname, - disqusId: page.disqusId, - permalink: page.permalink - }; -}); diff --git a/layout/comment/disqusjs.jsx b/layout/comment/disqusjs.jsx deleted file mode 100644 index fb22307..0000000 --- a/layout/comment/disqusjs.jsx +++ /dev/null @@ -1,68 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class DisqusJs extends Component { - render() { - const { - shortname, - apiKey, - api, - admin, - adminLabel = false, - nesting = 4, - disqusId, - path, - permalink, - pageTitle, - siteTitle, - jsUrl, - cssUrl - } = this.props; - if (!shortname) { - return
- You forgot to set the shortname or api_key for Disqus. - Please set it in _config.yml. -
; - } - const js = `new DisqusJS({ - shortname: '${shortname}', - apikey: '${JSON.stringify(apiKey)}', - siteName: '${siteTitle}', - identifier: '${disqusId || path}', - url: '${permalink || path}', - title: '${pageTitle}', - api: '${api}', - admin: '${admin}', - adminLabel: '${adminLabel}', - nesting: ${nesting} - });`; - return - -
- -
- - -
; - } -} - -module.exports = cacheComponent(DisqusJs, 'comment.disqusjs', props => { - const { config, page, helper, comment } = props; - - return { - path: page.path, - shortname: comment.shortname, - apiKey: comment.api_key, - api: comment.api, - admin: comment.admin, - adminLabel: comment.admin_label, - nesting: comment.nesting, - disqusId: page.disqusId, - permalink: page.permalink, - pageTitle: page.title, - siteTitle: config.title, - jsUrl: helper.cdn('disqusjs', '1.2.5', 'dist/disqus.js'), - cssUrl: helper.cdn('disqusjs', '1.2.5', 'dist/disqusjs.css') - }; -}); diff --git a/layout/comment/facebook.jsx b/layout/comment/facebook.jsx deleted file mode 100644 index 2148d3b..0000000 --- a/layout/comment/facebook.jsx +++ /dev/null @@ -1,28 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Facebook extends Component { - render() { - const { language, permalink } = this.props; - const js = `(function(d, s, id) { - var js, fjs = d.getElementsByTagName(s)[0]; - if (d.getElementById(id)) return; - js = d.createElement(s); js.id = id; - js.src = "//connect.facebook.net/${language.split('-').join('_')}/sdk.js#xfbml=1&version=v2.8"; - fjs.parentNode.insertBefore(js, fjs); - }(document, 'script', 'facebook-jssdk'));`; - return -
- -
; - } -} - -module.exports = cacheComponent(Facebook, 'comment.facebook', props => { - const { config, page } = props; - - return { - language: page.lang || page.language || config.language || 'en', - permalink: page.permalink - }; -}); diff --git a/layout/comment/gitalk.jsx b/layout/comment/gitalk.jsx deleted file mode 100644 index ab1d27e..0000000 --- a/layout/comment/gitalk.jsx +++ /dev/null @@ -1,79 +0,0 @@ -const crypto = require('crypto'); -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Gitalk extends Component { - render() { - const { - id, - repo, - owner, - admin, - clientId, - clientSecret, - createIssueManually = false, - distractionFreeMode = false, - pagerDirection = 'last', - perPage = 10, - proxy, - flipMoveOptions, - enableHotKey, - jsUrl, - cssUrl - } = this.props; - - if (!id || !repo || !owner || !admin || !clientId || !clientSecret) { - return
- You forgot to set the owner, admin, repo, - client_id, or client_secret for Gitalk. - Please set it in _config.yml. -
; - } - const js = `var gitalk = new Gitalk({ - id: '${id}', - repo: '${repo}', - owner: '${owner}', - clientID: '${clientId}', - clientSecret: '${clientSecret}', - admin: ${JSON.stringify(admin)}, - createIssueManually: ${createIssueManually}, - distractionFreeMode: ${distractionFreeMode}, - perPage: ${perPage}, - pagerDirection: '${pagerDirection}', - ${proxy ? `proxy: '${proxy}',` : ''} - ${flipMoveOptions ? `flipMoveOptions: ${JSON.stringify(flipMoveOptions)},` : ''} - enableHotKey: ${enableHotKey ? !!enableHotKey : true} - }) - gitalk.render('comment-container')`; - return -
- - - -
; - } -} - -module.exports = cacheComponent(Gitalk, 'comment.gitalk', props => { - const { helper, comment } = props; - - // FIXME: config name change - const id = crypto.createHash('md5').update(props.page.path).digest('hex'); - return { - id, - repo: comment.repo, - owner: comment.owner, - admin: comment.admin, - clientId: comment.client_id, - clientSecret: comment.client_secret, - createIssueManually: comment.create_issue_manually, - distractionFreeMode: comment.distraction_free_mode, - pagerDirection: comment.pager_direction, - perPage: comment.per_page, - proxy: comment.proxy, - flipMoveOptions: comment.flip_move_options, - enableHotKey: comment.enable_hotkey, - cssUrl: helper.cdn('gitalk', '1.4.1', 'dist/gitalk.css'), - jsUrl: helper.cdn('gitalk', '1.4.1', 'dist/gitalk.min.js') - }; -}); diff --git a/layout/comment/gitment.jsx b/layout/comment/gitment.jsx deleted file mode 100644 index faf3061..0000000 --- a/layout/comment/gitment.jsx +++ /dev/null @@ -1,58 +0,0 @@ -const crypto = require('crypto'); -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Gitment extends Component { - render() { - const { - id, - repo, - owner, - clientId, - clientSecret, - perPage = 20, - maxCommentHeight = 250 - } = this.props; - - if (!id || !repo || !owner || !clientId || !clientSecret) { - return
- You forgot to set the owner, repo, clientId, - or clientSecret for Gitment. - Please set it in _config.yml. -
; - } - const js = `var gitment = new Gitment({ - id: '${id}', - repo: '${repo}', - owner: '${owner}', - oauth: { - client_id: '${clientId}', - client_secret: '${clientSecret}', - }, - perPage: ${perPage}, - maxCommentHeight: ${maxCommentHeight} - }) - gitment.render('comment-container')`; - return -
- - - -
; - } -} - -module.exports = cacheComponent(Gitment, 'comment.gitment', props => { - const { comment } = props; - - const id = crypto.createHash('md5').update(props.page.path).digest('hex'); - return { - id, - repo: comment.repo, - owner: comment.owner, - clientId: comment.client_id, - clientSecret: comment.client_secret, - perPage: comment.per_page, - maxCommentHeight: comment.max_comment_height - }; -}); diff --git a/layout/comment/isso.jsx b/layout/comment/isso.jsx deleted file mode 100644 index eef9965..0000000 --- a/layout/comment/isso.jsx +++ /dev/null @@ -1,26 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Isso extends Component { - render() { - const { url } = this.props; - if (!url) { - return
- You forgot to set the url for Isso. - Please set it in _config.yml. -
; - } - return -
- -
; - } -} - -module.exports = cacheComponent(Isso, 'comment.isso', props => { - const { comment } = props; - - return { - url: comment.url - }; -}); diff --git a/layout/comment/livere.jsx b/layout/comment/livere.jsx deleted file mode 100644 index 36c554c..0000000 --- a/layout/comment/livere.jsx +++ /dev/null @@ -1,37 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class LiveRe extends Component { - render() { - const { uid } = this.props; - if (!uid) { - return
- You forgot to set the uid for LiveRe. - Please set it in _config.yml. -
; - } - const js = `(function(d, s) { - var j, e = d.getElementsByTagName(s)[0]; - - if (typeof LivereTower === 'function') { return; } - - j = d.createElement(s); - j.src = 'https://cdn-city.livere.com/js/embed.dist.js'; - j.async = true; - - e.parentNode.insertBefore(j, e); - })(document, 'script');`; - return
- - -
; - } -} - -module.exports = cacheComponent(LiveRe, 'comment.livere', props => { - const { comment } = props; - - return { - uid: comment.uid - }; -}); diff --git a/layout/comment/valine.jsx b/layout/comment/valine.jsx deleted file mode 100644 index 0f48d95..0000000 --- a/layout/comment/valine.jsx +++ /dev/null @@ -1,69 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Valine extends Component { - render() { - const { - appId, - appKey, - notify, - verify, - placeholder, - avatar = 'mm', - avatarForce = false, - meta = ['nick', 'mail', 'link'], - pageSize = 10, - visitor = false, - highlight = true, - recordIp = false, - jsUrl - } = this.props; - if (!appId || !appKey) { - return
- You forgot to set the app_id or app_key for Valine. - Please set it in _config.yml. -
; - } - const js = `new Valine({ - el: '#valine-thread' , - notify: ${notify}, - verify: ${verify}, - appId: '${appId}', - appKey: '${appKey}', - placeholder: '${placeholder}', - avatar: '${avatar}', - avatarForce: ${avatarForce}, - meta: ${JSON.stringify(meta)}, - pageSize: ${pageSize}, - visitor: ${visitor}, - highlight: ${highlight}, - recordIP: ${recordIp} - });`; - return -
- - - -
; - } -} - -module.exports = cacheComponent(Valine, 'comment.valine', props => { - const { comment, helper } = props; - - return { - appId: comment.app_id, - appKey: comment.app_key, - notify: comment.notify, - verify: comment.verify, - placeholder: comment.placeholder, - avatar: comment.avatar, - avatarForce: comment.avatar_force, - meta: comment.meta, - pageSize: comment.page_size, - visitor: comment.visitor, - highlight: comment.highlight, - recordIp: comment.record_ip, - jsUrl: helper.cdn('valine', '1.3.10', 'dist/Valine.min.js') - }; -}); diff --git a/layout/common/article-media.jsx b/layout/common/article-media.jsx deleted file mode 100644 index 9ce8751..0000000 --- a/layout/common/article-media.jsx +++ /dev/null @@ -1,28 +0,0 @@ -const { Component } = require('inferno'); - -module.exports = class extends Component { - render() { - const { thumbnail, url, title, date, dateXml, categories } = this.props; - - const categoryTags = []; - categories.forEach((category, i) => { - categoryTags.push({category.name}); - if (i < categories.length - 1) { - categoryTags.push(' / '); - } - }); - - return
- {thumbnail ? -

- {title} -

-
: null} -
-

-

{title}

-

{categoryTags.length ? categoryTags : null}

-
-
; - } -}; diff --git a/layout/common/comment.jsx b/layout/common/comment.jsx index 26860b0..93e3938 100644 --- a/layout/common/comment.jsx +++ b/layout/common/comment.jsx @@ -1,5 +1,6 @@ const logger = require('hexo-log')(); const { Component } = require('inferno'); +const view = require('hexo-component-inferno/lib/core/view'); module.exports = class extends Component { render() { @@ -15,7 +16,7 @@ module.exports = class extends Component {

{__('article.comments')}

{(() => { try { - const Comment = require('../comment/' + comment.type); + const Comment = view.require('comment/' + comment.type); return ; } catch (e) { logger.w(`Icarus cannot load comment "${comment.type}"`); diff --git a/layout/common/donates.jsx b/layout/common/donates.jsx index fe39f10..abf98b6 100644 --- a/layout/common/donates.jsx +++ b/layout/common/donates.jsx @@ -1,5 +1,6 @@ const logger = require('hexo-log')(); const { Component } = require('inferno'); +const view = require('hexo-component-inferno/lib/core/view'); module.exports = class extends Component { render() { @@ -17,7 +18,7 @@ module.exports = class extends Component { const type = service.type; if (typeof type === 'string') { try { - const Donate = require('../donate/' + type); + const Donate = view.require('donate/' + type); return ; } catch (e) { logger.w(`Icarus cannot load donate button "${type}"`); diff --git a/layout/common/footer.jsx b/layout/common/footer.jsx index 12f20a5..43a20ab 100644 --- a/layout/common/footer.jsx +++ b/layout/common/footer.jsx @@ -1,5 +1,5 @@ const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); +const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); class Footer extends Component { render() { diff --git a/layout/common/head.jsx b/layout/common/head.jsx index 2d29e07..434a77c 100644 --- a/layout/common/head.jsx +++ b/layout/common/head.jsx @@ -1,7 +1,7 @@ const { Component } = require('inferno'); -const MetaTags = require('../misc/meta'); -const OpenGraph = require('../misc/open_graph'); -const StructuredData = require('../misc/structured_data'); +const MetaTags = require('hexo-component-inferno/lib/view/misc/meta'); +const OpenGraph = require('hexo-component-inferno/lib/view/misc/open_graph'); +const StructuredData = require('hexo-component-inferno/lib/view/misc/structured_data'); const Plugins = require('./plugins'); function getPageTitle(page, siteTitle, helper) { diff --git a/layout/common/navbar.jsx b/layout/common/navbar.jsx index e7b85bc..0e566dc 100644 --- a/layout/common/navbar.jsx +++ b/layout/common/navbar.jsx @@ -1,6 +1,6 @@ const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); -const classname = require('../util/classname'); +const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); +const classname = require('hexo-component-inferno/lib/util/classname'); function isSameLink(a, b) { function santize(url) { diff --git a/layout/common/plugins.jsx b/layout/common/plugins.jsx index 43114f1..a1a9920 100644 --- a/layout/common/plugins.jsx +++ b/layout/common/plugins.jsx @@ -1,5 +1,6 @@ const logger = require('hexo-log')(); const { Component, Fragment } = require('inferno'); +const view = require('hexo-component-inferno/lib/core/view'); module.exports = class extends Component { render() { @@ -13,7 +14,7 @@ module.exports = class extends Component { return null; } try { - const Plugin = require('../plugin/' + name); + const Plugin = view.require('plugin/' + name); return ; } catch (e) { logger.w(`Icarus cannot load plugin "${name}"`); diff --git a/layout/common/search.jsx b/layout/common/search.jsx index 6495459..cb8134d 100644 --- a/layout/common/search.jsx +++ b/layout/common/search.jsx @@ -1,5 +1,6 @@ const logger = require('hexo-log')(); const { Component } = require('inferno'); +const view = require('hexo-component-inferno/lib/core/view'); module.exports = class extends Component { render() { @@ -10,7 +11,7 @@ module.exports = class extends Component { } try { - const Search = require('../search/' + search.type); + const Search = view.require('search/' + search.type); return ; } catch (e) { logger.w(`Icarus cannot load search "${search.type}"`); diff --git a/layout/common/share.jsx b/layout/common/share.jsx index e127cd6..84efdf4 100644 --- a/layout/common/share.jsx +++ b/layout/common/share.jsx @@ -1,5 +1,6 @@ const logger = require('hexo-log')(); const { Component } = require('inferno'); +const view = require('hexo-component-inferno/lib/core/view'); module.exports = class extends Component { render() { @@ -10,7 +11,7 @@ module.exports = class extends Component { } try { - const Share = require('../share/' + share.type); + const Share = view.require('share/' + share.type); return ; } catch (e) { logger.w(`Icarus cannot load share button "${share.type}"`); diff --git a/layout/common/widgets.jsx b/layout/common/widgets.jsx index e1160df..2616f7f 100644 --- a/layout/common/widgets.jsx +++ b/layout/common/widgets.jsx @@ -1,6 +1,7 @@ const logger = require('hexo-log')(); const { Component } = require('inferno'); -const classname = require('../util/classname'); +const view = require('hexo-component-inferno/lib/core/view'); +const classname = require('hexo-component-inferno/lib/util/classname'); function formatWidgets(widgets) { const result = {}; @@ -80,7 +81,7 @@ class Widgets extends Component { return null; } try { - const Widget = require('../widget/' + widget.type); + const Widget = view.require('widget/' + widget.type); return ; } catch (e) { logger.w(`Icarus cannot load widget "${widget.type}"`); diff --git a/layout/donate/.gitkeep b/layout/donate/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/layout/donate/alipay.jsx b/layout/donate/alipay.jsx deleted file mode 100644 index e55ebf7..0000000 --- a/layout/donate/alipay.jsx +++ /dev/null @@ -1,30 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Alipay extends Component { - render() { - const { title, qrcode } = this.props; - if (!qrcode) { - return
- You forgot to set the qrcode for Alipay. - Please set it in _config.yml. -
; - } - return ; - } -} - -module.exports = cacheComponent(Alipay, 'donate.alipay', props => { - const { donate, helper } = props; - - return { - title: helper.__('donate.' + donate.type), - qrcode: helper.url_for(donate.qrcode) - }; -}); diff --git a/layout/donate/buymeacoffee.jsx b/layout/donate/buymeacoffee.jsx deleted file mode 100644 index d9478bb..0000000 --- a/layout/donate/buymeacoffee.jsx +++ /dev/null @@ -1,33 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class BuyMeACoffee extends Component { - render() { - const { title, url } = this.props; - if (!url) { - return
- You forgot to set the url for "Buy me a coffee". - Please set it in _config.yml. -
; - } - return ; - } -} - -module.exports = cacheComponent(BuyMeACoffee, 'donate.buymeacoffee', props => { - const { donate, helper } = props; - - return { - url: helper.url_for(donate.url), - title: helper.__('donate.' + donate.type) - }; -}); diff --git a/layout/donate/patreon.jsx b/layout/donate/patreon.jsx deleted file mode 100644 index 567d6a1..0000000 --- a/layout/donate/patreon.jsx +++ /dev/null @@ -1,29 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Patreon extends Component { - render() { - const { title, url } = this.props; - if (!url) { - return
- You forgot to set the url for Patreon. - Please set it in _config.yml. -
; - } - return ; - } -} - -module.exports = cacheComponent(Patreon, 'donate.petreon', props => { - const { donate, helper } = props; - - return { - url: helper.url_for(donate.url), - title: helper.__('donate.' + donate.type) - }; -}); diff --git a/layout/donate/paypal.jsx b/layout/donate/paypal.jsx deleted file mode 100644 index 7aee3df..0000000 --- a/layout/donate/paypal.jsx +++ /dev/null @@ -1,37 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Paypal extends Component { - render() { - const { title, business, currencyCode } = this.props; - if (!business || !currencyCode) { - return
- You forgot to set the business or currency_code for Paypal. - Please set it in _config.yml. -
; - } - return - -
- - - -
-
; - } -} - -module.exports = cacheComponent(Paypal, 'donate.paypal', props => { - const { donate, helper } = props; - - return { - business: donate.business, - currencyCode: donate.currency_code, - title: helper.__('donate.' + donate.type) - }; -}); diff --git a/layout/donate/wechat.jsx b/layout/donate/wechat.jsx deleted file mode 100644 index 93033e9..0000000 --- a/layout/donate/wechat.jsx +++ /dev/null @@ -1,30 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Wechat extends Component { - render() { - const { title, qrcode } = this.props; - if (!qrcode) { - return
- You forgot to set the qrcode for Wechat. - Please set it in _config.yml. -
; - } - return ; - } -} - -module.exports = cacheComponent(Wechat, 'donate.wechat', props => { - const { donate, helper } = props; - - return { - qrcode: helper.url_for(donate.qrcode), - title: helper.__('donate.' + donate.type) - }; -}); diff --git a/layout/index.jsx b/layout/index.jsx index 686c716..7fe8419 100644 --- a/layout/index.jsx +++ b/layout/index.jsx @@ -1,6 +1,6 @@ const { Component, Fragment } = require('inferno'); +const Paginator = require('hexo-component-inferno/lib/view/misc/paginator'); const Article = require('./common/article'); -const Paginator = require('./misc/paginator'); module.exports = class extends Component { render() { diff --git a/layout/layout.jsx b/layout/layout.jsx index 1e0e7b7..4337007 100644 --- a/layout/layout.jsx +++ b/layout/layout.jsx @@ -1,11 +1,11 @@ const { Component } = require('inferno'); +const classname = require('hexo-component-inferno/lib/util/classname'); const Head = require('./common/head'); const Navbar = require('./common/navbar'); const Widgets = require('./common/widgets'); const Footer = require('./common/footer'); const Scripts = require('./common/scripts'); const Search = require('./common/search'); -const classname = require('./util/classname'); module.exports = class extends Component { render() { diff --git a/layout/misc/.gitkeep b/layout/misc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/layout/misc/meta.jsx b/layout/misc/meta.jsx deleted file mode 100644 index a6e6073..0000000 --- a/layout/misc/meta.jsx +++ /dev/null @@ -1,41 +0,0 @@ -const { Component, Fragment } = require('inferno'); - -function trim(str) { - return str.trim().replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1'); -} - -function split(str, sep) { - const result = []; - let matched = null; - while ((matched = sep.exec(str)) !== null) { - result.push(matched[0]); - } - return result; -} - -module.exports = class extends Component { - render() { - let { meta = [] } = this.props; - if (!Array.isArray(meta)) { - meta = [meta]; - } - const tags = meta.filter(entry => typeof entry === 'string') - .map(entry => { - const props = split(entry, /(?:[^\\;]+|\\.)+/g) - .map(property => { - const entry = split(property, /(?:[^\\=]+|\\.)+/g); - if (entry.length < 2) { - return null; - } - return { [trim(entry[0])]: trim(entry[1]) }; - }).filter(property => { - return property !== null; - }).reduce((prev, current) => { - return Object.assign(prev, current); - }, {}); - return ; - }); - - return {tags}; - } -}; diff --git a/layout/misc/open_graph.jsx b/layout/misc/open_graph.jsx deleted file mode 100644 index 977e3c2..0000000 --- a/layout/misc/open_graph.jsx +++ /dev/null @@ -1,145 +0,0 @@ -// adapted from hexo/lib/plugins/helper/open_graph.js -const urlFn = require('url'); -const moment = require('moment'); -const { Component, Fragment } = require('inferno'); -const { encodeURL, stripHTML, escapeHTML } = require('hexo-util'); -const localeMap = { - 'en': 'en_US', - 'de': 'de_DE', - 'es': 'es_ES', - 'fr': 'fr_FR', - 'hu': 'hu_HU', - 'id': 'id_ID', - 'it': 'it_IT', - 'ja': 'ja_JP', - 'ko': 'ko_KR', - 'nl': 'nl_NL', - 'ru': 'ru_RU', - 'th': 'th_TH', - 'tr': 'tr_TR', - 'vi': 'vi_VN' -}; -const localeRegex = new RegExp(Object.keys(localeMap).join('|'), 'i'); - -module.exports = class extends Component { - render() { - const { - type, - title, - date, - updated, - author, - url, - siteName, - twitterCard, - twitterSite, - googlePlus, - facebookAdmins, - facebookAppId - } = this.props; - let { - description, - language, - images, - keywords, - twitterId - } = this.props; - - const htmlTags = []; - - if (description) { - description = escapeHTML(stripHTML(description).substring(0, 200).trim()) - .replace(/\n/g, ' '); - htmlTags.push(); - } - - htmlTags.push(); - htmlTags.push(); - htmlTags.push(); - htmlTags.push(); - - if (description) { - htmlTags.push(); - } - - if (language) { - if (language.length === 2) { - language = language.replace(localeRegex, str => localeMap[str]); - htmlTags.push(); - } else if (language.length === 5) { - const territory = language.slice(-2); - const territoryRegex = new RegExp(territory.concat('$')); - language = language.replace('-', '_').replace(territoryRegex, territory.toUpperCase()); - htmlTags.push(); - } - } - - if (!Array.isArray(images)) { - images = [images]; - } - images = images.map(path => { - if (!urlFn.parse(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, path); - } - htmlTags.push(); - return path; - }); - - if (date && (moment.isMoment(date) || moment.isDate(date)) && !isNaN(date.valueOf())) { - htmlTags.push(); - } - - if (updated && (moment.isMoment(updated) || moment.isDate(updated)) && !isNaN(updated.valueOf())) { - htmlTags.push(); - } - - if (author) { - htmlTags.push(); - } - - if (keywords) { - if (typeof keywords === 'string') { - keywords = keywords.split(','); - } - - keywords.map(tag => { - return tag.name ? tag.name : tag; - }).filter(Boolean).forEach(keyword => { - htmlTags.push(); - }); - } - - htmlTags.push(); - - if (images.length) { - htmlTags.push(); - } - - if (twitterId) { - if (twitterId[0] !== '@') { - twitterId = `@${twitterId}`; - } - htmlTags.push(); - } - - if (twitterSite) { - htmlTags.push(); - } - - if (googlePlus) { - htmlTags.push(); - } - - if (facebookAdmins) { - htmlTags.push(); - } - - if (facebookAppId) { - htmlTags.push(); - } - - return {htmlTags}; - } -}; diff --git a/layout/misc/paginator.jsx b/layout/misc/paginator.jsx deleted file mode 100644 index 7bb2df5..0000000 --- a/layout/misc/paginator.jsx +++ /dev/null @@ -1,53 +0,0 @@ -const { Component } = require('inferno'); - -module.exports = class extends Component { - render() { - const { current, total, baseUrl, path, urlFor, prevTitle, nextTitle } = this.props; - - function getPageUrl(i) { - return urlFor(i === 1 ? baseUrl : baseUrl + path + '/' + i + '/'); - } - - function pagination(c, m) { - const current = c; - const last = m; - const delta = 1; - const left = current - delta; - const right = current + delta + 1; - const range = []; - const elements = []; - let l; - - for (let i = 1; i <= last; i++) { - if (i === 1 || i === last || (i >= left && i < right)) { - range.push(i); - } - } - - for (const i of range) { - if (l) { - if (i - l === 2) { - elements.push(
  • {l + 1}
  • ); - } else if (i - l !== 1) { - elements.push(
  • ); - } - } - elements.push(
  • {i}
  • ); - l = i; - } - return elements; - } - - return ; - } -}; diff --git a/layout/misc/structured_data.jsx b/layout/misc/structured_data.jsx deleted file mode 100644 index bff8de3..0000000 --- a/layout/misc/structured_data.jsx +++ /dev/null @@ -1,56 +0,0 @@ -const urlFn = require('url'); -const moment = require('moment'); -const { Component } = require('inferno'); -const { stripHTML, escapeHTML } = require('hexo-util'); - -module.exports = class extends Component { - render() { - const { title, url, author } = this.props; - let { description, images, date, updated } = this.props; - - if (description) { - description = escapeHTML(stripHTML(description).substring(0, 200).trim()) - .replace(/\n/g, ' '); - } - - if (!Array.isArray(images)) { - images = [images]; - } - images = images.map(path => { - if (!urlFn.parse(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, path); - } - return path; - }).filter(url => url.endsWith('.jpg') || url.endsWith('.png') || url.endsWith('.gif')); - - if (date && (moment.isMoment(date) || moment.isDate(date)) && !isNaN(date.valueOf())) { - date = date.toISOString(); - } - - if (updated && (moment.isMoment(updated) || moment.isDate(updated)) && !isNaN(updated.valueOf())) { - updated = updated.toISOString(); - } - - const data = { - '@context': 'https://schema.org', - '@type': 'BlogPosting', - 'mainEntityOfPage': { - '@type': 'WebPage', - '@id': url - }, - 'headline': title, - 'image': images, - 'datePublished': date, - 'dateModified': updated, - 'author': { - '@type': 'Person', - 'name': author - }, - 'description': description - }; - - return ; - } -}; diff --git a/layout/plugin/animejs.jsx b/layout/plugin/animejs.jsx index 6ad398c..4382068 100644 --- a/layout/plugin/animejs.jsx +++ b/layout/plugin/animejs.jsx @@ -1,5 +1,5 @@ const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); +const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); class AnimeJs extends Component { render() { diff --git a/layout/plugin/back_to_top.jsx b/layout/plugin/back_to_top.jsx index 41b1682..b750340 100644 --- a/layout/plugin/back_to_top.jsx +++ b/layout/plugin/back_to_top.jsx @@ -1,5 +1,5 @@ const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); +const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); class BackToTop extends Component { render() { diff --git a/layout/plugin/baidu_analytics.jsx b/layout/plugin/baidu_analytics.jsx deleted file mode 100644 index b747bac..0000000 --- a/layout/plugin/baidu_analytics.jsx +++ /dev/null @@ -1,28 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class BaiduAnalytics extends Component { - render() { - const { trackingId } = this.props; - - const js = `var _hmt = _hmt || []; - (function() { - var hm = document.createElement("script"); - hm.src = "//hm.baidu.com/hm.js?${trackingId}"; - var s = document.getElementsByTagName("script")[0]; - s.parentNode.insertBefore(hm, s); - })();`; - - return ; - } -} - -module.exports = cacheComponent(BaiduAnalytics, 'plugin.baiduanalytics', props => { - const { head, plugin } = props; - if (!head || !plugin.tracking_id) { - return null; - } - return { - trackingId: plugin.tracking_id - }; -}); diff --git a/layout/plugin/busuanzi.jsx b/layout/plugin/busuanzi.jsx deleted file mode 100644 index 90bc3fa..0000000 --- a/layout/plugin/busuanzi.jsx +++ /dev/null @@ -1,15 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Busuanzi extends Component { - render() { - return ; - } -} - -module.exports = cacheComponent(Busuanzi, 'plugin.busuanzi', props => { - if (!props.head) { - return null; - } - return {}; -}); diff --git a/layout/plugin/gallery.jsx b/layout/plugin/gallery.jsx deleted file mode 100644 index e5f16aa..0000000 --- a/layout/plugin/gallery.jsx +++ /dev/null @@ -1,36 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Gallery extends Component { - render() { - const { head, jsUrl, lightGallery, justifiedGallery } = this.props; - if (head) { - return - - - ; - } - return - - - - ; - - } -} - -module.exports = cacheComponent(Gallery, 'plugin.gallery', props => { - const { head, helper } = props; - return { - head, - jsUrl: helper.url_for('/js/gallery.js'), - lightGallery: { - jsUrl: helper.cdn('lightgallery', '1.6.8', 'dist/js/lightgallery.min.js'), - cssUrl: helper.cdn('lightgallery', '1.6.8', 'dist/css/lightgallery.min.css') - }, - justifiedGallery: { - jsUrl: helper.cdn('justifiedGallery', '3.7.0', 'dist/js/jquery.justifiedGallery.min.js'), - cssUrl: helper.cdn('justifiedGallery', '3.7.0', 'dist/css/justifiedGallery.min.css') - } - }; -}); diff --git a/layout/plugin/google_analytics.jsx b/layout/plugin/google_analytics.jsx deleted file mode 100644 index 22e70ec..0000000 --- a/layout/plugin/google_analytics.jsx +++ /dev/null @@ -1,29 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class GoogleAnalytics extends Component { - render() { - const { trackingId } = this.props; - - const js = `window.dataLayer = window.dataLayer || []; - function gtag(){dataLayer.push(arguments);} - gtag('js', new Date()); - - gtag('config', '${trackingId}');`; - - return - - - ; - } -} - -module.exports = cacheComponent(GoogleAnalytics, 'plugin.googleanalytics', props => { - const { head, plugin } = props; - if (!head || !plugin.tracking_id) { - return null; - } - return { - trackingId: plugin.tracking_id - }; -}); diff --git a/layout/plugin/hotjar.jsx b/layout/plugin/hotjar.jsx deleted file mode 100644 index b52873d..0000000 --- a/layout/plugin/hotjar.jsx +++ /dev/null @@ -1,31 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Hotjar extends Component { - render() { - const { siteId } = this.props; - - const js = `(function(h,o,t,j,a,r){ - h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)}; - h._hjSettings={hjid:${siteId},hjsv:6}; - a=o.getElementsByTagName('head')[0]; - r=o.createElement('script');r.async=1; - r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv; - a.appendChild(r); - })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');`; - - return - - ; - } -} - -module.exports = cacheComponent(Hotjar, 'plugin.hotjar', props => { - const { head, plugin } = props; - if (!head || !plugin.site_id) { - return null; - } - return { - siteId: plugin.site_id - }; -}); diff --git a/layout/plugin/katex.jsx b/layout/plugin/katex.jsx deleted file mode 100644 index a251be4..0000000 --- a/layout/plugin/katex.jsx +++ /dev/null @@ -1,33 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class KaTeX extends Component { - render() { - const { cssUrl, jsUrl, autoRenderUrl } = this.props; - - const js = `document.addEventListener("DOMContentLoaded", function() { - document.querySelectorAll('[role="article"] > .content').forEach(function(element) { - renderMathInElement(element); - }); - });`; - - return - - - - - ; - } -} - -module.exports = cacheComponent(KaTeX, 'plugin.katex', props => { - const { head, helper } = props; - if (head) { - return null; - } - return { - jsUrl: helper.cdn('katex', '0.11.1', 'dist/katex.min.js'), - cssUrl: helper.cdn('katex', '0.11.1', 'dist/katex.min.css'), - autoRenderUrl: helper.cdn('katex', '0.11.1', 'dist/contrib/auto-render.min.js') - }; -}); diff --git a/layout/plugin/mathjax.jsx b/layout/plugin/mathjax.jsx deleted file mode 100644 index 738be23..0000000 --- a/layout/plugin/mathjax.jsx +++ /dev/null @@ -1,43 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Mathjax extends Component { - render() { - const { jsUrl } = this.props; - - const js = `document.addEventListener('DOMContentLoaded', function () { - MathJax.Hub.Config({ - 'HTML-CSS': { - matchFontHeight: false - }, - SVG: { - matchFontHeight: false - }, - CommonHTML: { - matchFontHeight: false - }, - tex2jax: { - inlineMath: [ - ['$','$'], - ['\\\\(','\\\\)'] - ] - } - }); - });`; - - return - - - ; - } -} - -module.exports = cacheComponent(Mathjax, 'plugin.mathjax', props => { - const { head, helper } = props; - if (head) { - return null; - } - return { - jsUrl: helper.cdn('mathjax', '2.7.5', 'unpacked/MathJax.js?config=TeX-MML-AM_CHTML') - }; -}); diff --git a/layout/plugin/outdated_browser.jsx b/layout/plugin/outdated_browser.jsx deleted file mode 100644 index b2ba55d..0000000 --- a/layout/plugin/outdated_browser.jsx +++ /dev/null @@ -1,42 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class OutdatedBrowser extends Component { - render() { - const { head, jsUrl, cssUrl } = this.props; - - const js = `document.addEventListener("DOMContentLoaded", function () { - outdatedBrowser({ - bgColor: '#f25648', - color: '#ffffff', - lowerThan: 'object-fit' // display on IE11 or below - }); - });`; - - if (head) { - return ; - } - return -
    -
    Your browser is out-of-date!
    -

    - Update your browser to view this website correctly.&npsb; - Update my browser now -

    -

    ×

    -
    - - -
    ; - - } -} - -module.exports = cacheComponent(OutdatedBrowser, 'plugin.outdatedbrowser', props => { - const { head, helper } = props; - return { - head, - cssUrl: helper.cdn('outdatedbrowser', '1.1.5', 'outdatedbrowser/outdatedbrowser.min.css'), - jsUrl: helper.cdn('outdatedbrowser', '1.1.5', 'outdatedbrowser/outdatedbrowser.min.js') - }; -}); diff --git a/layout/plugin/progressbar.jsx b/layout/plugin/progressbar.jsx deleted file mode 100644 index da0aed3..0000000 --- a/layout/plugin/progressbar.jsx +++ /dev/null @@ -1,20 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class ProgressBar extends Component { - render() { - const { jsUrl } = this.props; - - return ; - } -} - -module.exports = cacheComponent(ProgressBar, 'plugin.progressbar', props => { - const { head, helper } = props; - if (!head) { - return null; - } - return { - jsUrl: helper.cdn('pace-js', '1.0.2', 'pace.min.js') - }; -}); diff --git a/layout/search/baidu.jsx b/layout/search/baidu.jsx deleted file mode 100644 index 3bfdfb7..0000000 --- a/layout/search/baidu.jsx +++ /dev/null @@ -1,48 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Baidu extends Component { - render() { - const { url, hint } = this.props; - - const js = `(function ($) { - $('.search-form').on('submit', function (e) { - var keyword = $('.searchbox-input[name="wd"]').val(); - window.location = 'https://www.baidu.com/s?wd=site:${url.replace(/http(s)*:\/\//, '')} ' + keyword; - return false; - }); - })(jQuery); - (function (document, $) { - $(document).on('click', '.navbar-main .search', function () { - $('.searchbox').toggleClass('show'); - }).on('click', '.searchbox .searchbox-mask', function () { - $('.searchbox').removeClass('show'); - }).on('click', '.searchbox-close', function () { - $('.searchbox').removeClass('show'); - }); - })(document, jQuery);`; - - return - - - ; - } -} - -module.exports = cacheComponent(Baidu, 'search.baidu', props => { - const { config, helper } = props; - - return { - url: config.url, - hint: helper.__('search.hint') - }; -}); diff --git a/layout/search/google_cse.jsx b/layout/search/google_cse.jsx deleted file mode 100644 index 65fc973..0000000 --- a/layout/search/google_cse.jsx +++ /dev/null @@ -1,86 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Google extends Component { - render() { - const { cx, hint } = this.props; - - const js1 = `(function() { - var cx = '${cx}'; - var gcse = document.createElement('script'); - gcse.type = 'text/javascript'; - gcse.async = true; - gcse.src = 'https://cse.google.com/cse.js?cx=' + cx; - var s = document.getElementsByTagName('script')[0]; - s.parentNode.insertBefore(gcse, s); - })();`; - - const js2 = `(function (document, $) { - function debounce(func, wait, immediate) { - var timeout; - return function() { - var context = this, args = arguments; - var later = function() { - timeout = null; - if (!immediate) func.apply(context, args); - }; - var callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) func.apply(context, args); - }; - }; - - $(document).on('click', '.navbar-main .search', function () { - $('.searchbox').toggleClass('show'); - }).on('click', '.searchbox .searchbox-mask', function () { - $('.searchbox').removeClass('show'); - }).on('click', '.searchbox-close', function () { - $('.searchbox').removeClass('show'); - }).on('keydown', '.searchbox-input', debounce(function () { - var value = $(this).val(); - try { - var element = google.search.cse.element.getElement('searchresults-only0'); - if (value.trim() === '') { - element.clearAllResults(); - } else { - element.execute(value); - } - } catch (e) {} - }, 300)); - })(document, jQuery);`; - - return - - - ; - } -} - -module.exports = cacheComponent(Google, 'search.google', props => { - const { helper, search } = props; - - return { - cx: search.cx, - hint: helper.__('search.hint') - }; -}); diff --git a/layout/search/insight.jsx b/layout/search/insight.jsx index d936844..4d6ed28 100644 --- a/layout/search/insight.jsx +++ b/layout/search/insight.jsx @@ -1,5 +1,5 @@ const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); +const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); class Insight extends Component { render() { diff --git a/layout/share/.gitkeep b/layout/share/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/layout/share/addthis.jsx b/layout/share/addthis.jsx deleted file mode 100644 index 95c3d71..0000000 --- a/layout/share/addthis.jsx +++ /dev/null @@ -1,26 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class AddThis extends Component { - render() { - const { installUrl } = this.props; - if (!installUrl) { - return
    - You need to set install_url to use AddThis. - Please set it in _config.yml. -
    ; - } - return -
    - -
    ; - } -} - -module.exports = cacheComponent(AddThis, 'share.addthis', props => { - const { share } = props; - - return { - installUrl: share.install_url - }; -}); diff --git a/layout/share/addtoany.jsx b/layout/share/addtoany.jsx deleted file mode 100644 index e87b5ad..0000000 --- a/layout/share/addtoany.jsx +++ /dev/null @@ -1,22 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class AddToAny extends Component { - render() { - return -
    - - - - - - -
    - -
    ; - } -} - -module.exports = cacheComponent(AddToAny, 'share.addtoany', props => { - return {}; -}); diff --git a/layout/share/bdshare.jsx b/layout/share/bdshare.jsx deleted file mode 100644 index fcadd93..0000000 --- a/layout/share/bdshare.jsx +++ /dev/null @@ -1,23 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class BdShare extends Component { - render() { - const js = 'window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "2", "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName(\'head\')[0] || body).appendChild(createElement(\'script\')).src = \'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=\' + ~(-new Date() / 36e5)];'; - return -
    - - - - - - -
    - -
    ; - } -} - -module.exports = cacheComponent(BdShare, 'share.bdshare', props => { - return {}; -}); diff --git a/layout/share/sharejs.jsx b/layout/share/sharejs.jsx deleted file mode 100644 index 80b3657..0000000 --- a/layout/share/sharejs.jsx +++ /dev/null @@ -1,22 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class ShareJs extends Component { - render() { - const { cssUrl, jsUrl } = this.props; - return - - - - ; - } -} - -module.exports = cacheComponent(ShareJs, 'share.sharejs', props => { - const { helper } = props; - - return { - cssUrl: helper.cdn('social-share.js', '1.0.16', 'dist/css/share.min.css'), - jsUrl: helper.cdn('social-share.js', '1.0.16', 'dist/js/social-share.min.js') - }; -}); diff --git a/layout/share/sharethis.jsx b/layout/share/sharethis.jsx deleted file mode 100644 index 60a04f9..0000000 --- a/layout/share/sharethis.jsx +++ /dev/null @@ -1,26 +0,0 @@ -const { Component, Fragment } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class ShareThis extends Component { - render() { - const { installUrl } = this.props; - if (!installUrl) { - return
    - You need to set install_url to use ShareThis. - Please set it in _config.yml. -
    ; - } - return -
    - -
    ; - } -} - -module.exports = cacheComponent(ShareThis, 'share.sharethis', props => { - const { share } = props; - - return { - installUrl: share.install_url - }; -}); diff --git a/layout/tags.jsx b/layout/tags.jsx index 770db57..65cb070 100644 --- a/layout/tags.jsx +++ b/layout/tags.jsx @@ -1,5 +1,5 @@ const { Component } = require('inferno'); -const Tags = require('./widget/tags'); +const Tags = require('hexo-component-inferno/lib/view/widget/tags'); module.exports = class extends Component { render() { diff --git a/layout/util/cache.jsx b/layout/util/cache.jsx deleted file mode 100644 index b37d6a3..0000000 --- a/layout/util/cache.jsx +++ /dev/null @@ -1,48 +0,0 @@ -const crypto = require('crypto'); -const { Component } = require('inferno'); // eslint-disable-line no-unused-vars -const { createElement } = require('inferno-create-element'); - -const cache = {}; - -function computeHash(props) { - return crypto.createHash('md5').update(JSON.stringify(props)).digest('hex'); -} - -module.exports = { - - /** - * Create cached component from a given component class. - * The cache ID is caculated from the input props. - * - * @param {Component} type JSX component class - * @param {string} prefix Cache ID prefix - * @param {Function} transform Transform the input props to target props and - * its result is used to compute cache ID - * @returns A cache-enabled component. - * It returns cached JSX element when called if cache ID is found. - * It returns null if the props transform result is empty, which means the props - * passed to the createElement() indicates the element does not need to be created. - * Otherwise, it creates a new element and caches it if the transform function is provided. - * The original component can be accessed from the `_type` property of the return value. - * The props transform function can be accessed from the `_transform` property of the return value. - */ - cacheComponent(type, prefix, transform) { - const component = props => { - const targetProps = transform(props); - if (!targetProps) { - return null; - } - const cacheId = prefix + '-' + computeHash(targetProps); - if (!cacheId) { - return createElement(type, targetProps); - } - if (!cache[cacheId]) { - cache[cacheId] = createElement(type, targetProps); - } - return cache[cacheId]; - }; - component._type = type; - component._transform = transform; - return component; - } -}; diff --git a/layout/util/classname.jsx b/layout/util/classname.jsx deleted file mode 100644 index 3277c2d..0000000 --- a/layout/util/classname.jsx +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function(classname) { - if (typeof classname === 'string') { - return classname; - } - if (Array.isArray(classname)) { - return classname.join(' '); - } - if (typeof classname === 'object') { - return Object.keys(classname).filter(key => !!classname[key]).join(' '); - } - throw new Error('Cannot process class name' + JSON.stringify(classname)); -}; diff --git a/layout/widget/adsense.jsx b/layout/widget/adsense.jsx deleted file mode 100644 index df3a116..0000000 --- a/layout/widget/adsense.jsx +++ /dev/null @@ -1,41 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class AdSense extends Component { - render() { - const { title, clientId, slotId } = this.props; - if (!clientId || !slotId) { - return
    -
    -
    - You need to set client_id and slot_id to show this AD unit. - Please set it in _config.yml. -
    -
    -
    ; - } - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(AdSense, 'widget.adsense', props => { - const { widget, helper } = props; - const { client_id, slot_id } = widget; - - return { - title: helper.__('widget.adsense'), - clientId: client_id, - slotId: slot_id - }; -}); diff --git a/layout/widget/archives.jsx b/layout/widget/archives.jsx deleted file mode 100644 index a73a334..0000000 --- a/layout/widget/archives.jsx +++ /dev/null @@ -1,105 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Archives extends Component { - render() { - const { - items, - title, - showCount - } = this.props; - - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(Archives, 'widget.archives', props => { - // adapted from hexo/lib/plugins/helper/list_archives.js - const { - site, - config, - page, - helper, - type = 'monthly', - order = -1, - show_count = true, - format = null - } = props; - const { url_for, _p } = helper; - const posts = site.posts.sort('date', order); - if (!posts.length) { - return null; - } - - const language = page.lang || page.language || config.language; - - const data = []; - let length = 0; - - posts.forEach(post => { - // Clone the date object to avoid pollution - let date = post.date.clone(); - - if (config.timezone) { - date = date.tz(config.timezone); - } - if (language) { - date = date.locale(language); - } - - const year = date.year(); - const month = date.month() + 1; - const name = date.format(format || type === 'monthly' ? 'MMMM YYYY' : 'YYYY'); - const lastData = data[length - 1]; - - if (!lastData || lastData.name !== name) { - length = data.push({ - name, - year, - month, - count: 1 - }); - } else { - lastData.count++; - } - }); - - const link = item => { - let url = `${config.archive_dir}/${item.year}/`; - - if (type === 'monthly') { - if (item.month < 10) url += '0'; - url += `${item.month}/`; - } - - return url_for(url); - }; - - return { - items: data.map(item => ({ - name: item.name, - count: item.count, - url: link(item) - })), - title: _p('common.archive', Infinity), - showCount: show_count - }; -}); diff --git a/layout/widget/categories.jsx b/layout/widget/categories.jsx deleted file mode 100644 index 2441c8d..0000000 --- a/layout/widget/categories.jsx +++ /dev/null @@ -1,108 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Categories extends Component { - renderList(categories, showCount) { - return categories.map(category =>
  • - - - {category.name} - - {showCount ? - {category.count} - : null} - - {category.children.length ?
      {this.renderList(category.children, showCount)}
    : null} -
  • ); - } - - render() { - const { - title, - showCount, - categories - } = this.props; - - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(Categories, 'widget.categories', props => { - // adapted from hexo/lib/plugins/helper/list_categories.js - const { - page, - helper, - categories = props.site.categories, - orderBy = 'name', - order = 1, - show_current = false, - show_count = true - } = props; - const { url_for, _p } = helper; - - if (!categories || !categories.length) { - return null; - } - - let depth = 0; - try { - depth = parseInt(props.depth, 10); - } catch (e) { } - - function prepareQuery(parent) { - const query = {}; - - if (parent) { - query.parent = parent; - } else { - query.parent = { $exists: false }; - } - - return categories.find(query).sort(orderBy, order).filter(cat => cat.length); - } - - function hierarchicalList(level, parent) { - return prepareQuery(parent).map((cat, i) => { - let children = []; - if (!depth || level + 1 < depth) { - children = hierarchicalList(level + 1, cat._id); - } - - let isCurrent = false; - if (show_current && page) { - for (let j = 0; j < cat.length; j++) { - const post = cat.posts.data[j]; - if (post && post._id === page._id) { - isCurrent = true; - break; - } - } - // special case: category page - isCurrent = isCurrent || (page.base && page.base.startsWith(cat.path)); - } - - return { - children, - isCurrent, - name: cat.name, - count: cat.length, - url: url_for(cat.path) - }; - }); - } - - return { - showCount: show_count, - categories: hierarchicalList(0), - title: _p('common.category', Infinity) - }; -}); diff --git a/layout/widget/links.jsx b/layout/widget/links.jsx deleted file mode 100644 index 35891ef..0000000 --- a/layout/widget/links.jsx +++ /dev/null @@ -1,45 +0,0 @@ -const { URL } = require('url'); -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Links extends Component { - render() { - const { title, links } = this.props; - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(Links, 'widget.links', props => { - const { helper, widget } = props; - if (!Object.keys(widget.links).length) { - return null; - } - return { - title: helper.__('widget.links'), - links: widget.links - }; -}); diff --git a/layout/widget/profile.jsx b/layout/widget/profile.jsx index a2ac348..6625feb 100644 --- a/layout/widget/profile.jsx +++ b/layout/widget/profile.jsx @@ -1,6 +1,6 @@ const { Component } = require('inferno'); const gravatrHelper = require('hexo-util').gravatar; -const { cacheComponent } = require('../util/cache'); +const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); class Profile extends Component { renderSocialLinks(links) { diff --git a/layout/widget/recent_posts.jsx b/layout/widget/recent_posts.jsx deleted file mode 100644 index bd64d3a..0000000 --- a/layout/widget/recent_posts.jsx +++ /dev/null @@ -1,47 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); -const ArticleMedia = require('../common/article-media'); - -class RecentPosts extends Component { - render() { - const { title, posts } = this.props; - - return
    -
    - - {posts.map(post => { - return ; - })} -
    -
    ; - } -} - -module.exports = cacheComponent(RecentPosts, 'widget.recentposts', props => { - const { site, helper } = props; - const { has_thumbnail, get_thumbnail, url_for, __, date_xml, date } = helper; - if (!site.posts.length) { - return null; - } - const posts = site.posts.sort('date', -1).limit(5).map(post => ({ - url: url_for(post.link || post.path), - title: post.title, - date: date(post.date), - dateXml: date_xml(post.date), - thumbnail: has_thumbnail(post) ? get_thumbnail(post) : null, - categories: post.categories.map(category => ({ - name: category.name, - url: url_for(category.path) - })) - })); - return { - posts, - title: __('widget.recents') - }; -}); diff --git a/layout/widget/subscribe_email.jsx b/layout/widget/subscribe_email.jsx deleted file mode 100644 index 3ae8c2c..0000000 --- a/layout/widget/subscribe_email.jsx +++ /dev/null @@ -1,45 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class SubscribeEmail extends Component { - render() { - const { title, description, feedburnerId, buttonTitle } = this.props; - - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(SubscribeEmail, 'widget.subscribeemail', props => { - const { helper, widget } = props; - const { feedburner_id, description } = widget; - - return { - description, - feedburnerId: feedburner_id, - title: helper.__('widget.subscribe_email'), - buttonTitle: helper.__('widget.subscribe') - }; -}); diff --git a/layout/widget/tags.jsx b/layout/widget/tags.jsx deleted file mode 100644 index 9e7ea94..0000000 --- a/layout/widget/tags.jsx +++ /dev/null @@ -1,60 +0,0 @@ -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -class Tags extends Component { - render() { - const { - tags, - title, - showCount - } = this.props; - - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(Tags, 'widget.tags', props => { - // adapted from hexo/lib/plugins/helper/list_tags.js - const { - helper, - orderBy = 'name', - order = 1, - amount, - show_count = true - } = props; - let tags = props.tags || props.site.tags; - const { url_for, _p } = helper; - - if (!tags || !tags.length) { - return null; - } - - tags = tags.sort(orderBy, order).filter(tag => tag.length); - if (amount) { - tags = tags.limit(amount); - } - - return { - showCount: show_count, - title: _p('common.tag', Infinity), - tags: tags.map(tag => ({ - name: tag.name, - count: tag.length, - url: url_for(tag.path) - })) - }; -}); diff --git a/layout/widget/toc.jsx b/layout/widget/toc.jsx deleted file mode 100644 index e3b640c..0000000 --- a/layout/widget/toc.jsx +++ /dev/null @@ -1,126 +0,0 @@ -const { tocObj: getTocObj } = require('hexo-util'); -const { Component } = require('inferno'); -const { cacheComponent } = require('../util/cache'); - -/** - * Export a tree of headings of an article - * { - * "1": { - * "id": "How-to-enable-table-of-content-for-a-post", - * "text": "How to enable table of content for a post", - * "index": "1" - * }, - * "2": { - * "1": { - * "1": { - * "id": "Third-level-title", - * "text": "Third level title", - * "index": "2.1.1" - * }, - * "id": "Second-level-title", - * "text": "Second level title", - * "index": "2.1" - * }, - * "2": { - * "id": "Another-second-level-title", - * "text": "Another second level title", - * "index": "2.2" - * }, - * "id": "First-level-title", - * "text": "First level title", - * "index": "2" - * } - * } - */ -function getToc(content) { - const toc = {}; - const levels = [0, 0, 0]; - const tocObj = getTocObj(content, { min_depth: 1, max_depth: 6 }); - const minLevel = Math.min(...tocObj.map(item => item.level)); - tocObj.forEach(item => { - const { text, id } = item; - const level = item.level - minLevel; - - for (let i = 0; i < levels.length; i++) { - if (i > level) { - levels[i] = 0; - } else if (i < level) { - if (levels[i] === 0) { - // if headings start with a lower level heading, set the former heading index to 1 - // e.g. h3, h2, h1, h2, h3 => 1.1.1, 1.2, 2, 2.1, 2.1.1 - levels[i] = 1; - } - } else { - levels[i] += 1; - } - } - let node = toc; - for (const i of levels.slice(0, level + 1)) { - if (!(i in node)) { - node[i] = {}; - } - node = node[i]; - } - node.id = id; - node.text = text; - node.index = levels.slice(0, level + 1).join('.'); - }); - return toc; -} - -class Toc extends Component { - renderToc(toc) { - let result; - - const keys = Object.keys(toc) - .filter(key => !['id', 'index', 'text'].includes(key)) - .map(key => parseInt(key, 10)) - .sort((a, b) => a - b); - - if (keys.length > 0) { - result = ; - } - if ('id' in toc && 'index' in toc && 'text' in toc) { - result =
  • - - {toc.index} - {toc.text} - - {result} -
  • ; - } - return result; - } - - render() { - const toc = getToc(this.props.content); - if (!Object.keys(toc).length) { - return null; - } - - return
    -
    - -
    -
    ; - } -} - -module.exports = cacheComponent(Toc, 'widget.toc', props => { - const { config, page, helper } = props; - const { layout, content } = page; - - if (config.toc !== true || (layout !== 'page' && layout !== 'post')) { - return null; - } - - return { - title: helper._p('widget.catalogue', Infinity), - content - }; -}); diff --git a/package.json b/package.json index 6794ccf..5da746e 100644 --- a/package.json +++ b/package.json @@ -11,22 +11,19 @@ "license": "MIT", "scripts": { "lint": "eslint --ext .js --ext .jsx --ext .json .", - "test": "mocha test/index.js", "postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push --tags" }, "devDependencies": { - "chai": "^4.2.0", "eslint": "^6.8.0", "eslint-config-hexo": "^4.1.0", "eslint-plugin-json": "^2.0.1", - "eslint-plugin-react": "^7.17.0", - "mocha": "^6.2.2" + "eslint-plugin-react": "^7.17.0" }, "peerDependencies": { - "ajv": "^6.10.2", "bulma-stylus": "0.8.0", "deepmerge": "^4.2.2", "hexo": "^4.2.0", + "hexo-component-inferno": "^0.0.1", "hexo-log": "^1.0.0", "hexo-pagination": "^1.0.0", "hexo-renderer-inferno": "^0.1.1", @@ -34,7 +31,6 @@ "hexo-util": "^1.8.0", "inferno": "^7.3.3", "inferno-create-element": "^7.3.3", - "js-yaml": "^3.13.1", "moment": "^2.22.2", "semver": ">=5.0.0" } diff --git a/source/css/base.styl b/source/css/base.styl index 9fd12c4..6a45e14 100644 --- a/source/css/base.styl +++ b/source/css/base.styl @@ -508,34 +508,6 @@ footer.footer &.is-active display: block -#back-to-top - position: fixed - padding: 8px 0 - transition: 0.4s ease opacity, 0.4s ease width, 0.4s ease transform, 0.4s ease border-radius - opacity: 0 - line-height: 24px - outline: none - transform: translateY(120px) - &.fade-in - opacity: 1 - &.rise-up - transform: translateY(0) - -.pace - user-select: none - pointer-events: none - .pace-progress - top: 0 - right: 100% - width: 100% - height: 2px - z-index: 2000 - position: fixed - background: $primary - -.pace-inactive - display: none - // Overflow table .table-overflow overflow-x: auto diff --git a/source/css/plugin/back-to-top.styl b/source/css/plugin/back-to-top.styl new file mode 100644 index 0000000..bee9edf --- /dev/null +++ b/source/css/plugin/back-to-top.styl @@ -0,0 +1,12 @@ +#back-to-top + position: fixed + padding: 8px 0 + transition: 0.4s ease opacity, 0.4s ease width, 0.4s ease transform, 0.4s ease border-radius + opacity: 0 + line-height: 24px + outline: none + transform: translateY(120px) + &.fade-in + opacity: 1 + &.rise-up + transform: translateY(0) diff --git a/source/css/plugin/progressbar.styl b/source/css/plugin/progressbar.styl new file mode 100644 index 0000000..1fe8b93 --- /dev/null +++ b/source/css/plugin/progressbar.styl @@ -0,0 +1,14 @@ +.pace + user-select: none + pointer-events: none + .pace-progress + top: 0 + right: 100% + width: 100% + height: 2px + z-index: 2000 + position: fixed + background: $primary + +.pace-inactive + display: none \ No newline at end of file diff --git a/source/css/style.styl b/source/css/style.styl index b19399c..b7f644a 100644 --- a/source/css/style.styl +++ b/source/css/style.styl @@ -1,2 +1,5 @@ @import "base" @import "helper" + +@import "plugin/back-to-top" +@import "plugin/progressbar" \ No newline at end of file