diff --git a/.eslintrc b/.eslintrc
index bab92d4..4bdf5ae 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -33,21 +33,6 @@
"SwitchCase": 1
}
],
- "node/no-extraneous-require": [
- "error",
- {
- "allowModules": [
- "inferno",
- "inferno-create-element",
- "hexo",
- "hexo-util",
- "hexo-log",
- "hexo-pagination",
- "cheerio",
- "moment"
- ]
- }
- ],
"react/no-unknown-property": [
"error",
{
diff --git a/include/task/check_deps.js b/include/task/dependencies.js
similarity index 50%
rename from include/task/check_deps.js
rename to include/task/dependencies.js
index b971041..46ac44a 100644
--- a/include/task/check_deps.js
+++ b/include/task/dependencies.js
@@ -1,5 +1,7 @@
const logger = require('hexo-log')();
+const packageInfo = require('../../package.json');
+// FIXME: will not check against package version
function checkDependency(name) {
try {
require.resolve(name);
@@ -10,16 +12,12 @@ function checkDependency(name) {
return false;
}
-logger.info('Checking dependencies');
-const missingDeps = [
- 'js-yaml',
- 'moment',
- 'cheerio',
- 'hexo-util',
- 'hexo-log',
- 'hexo-pagination'
-].map(checkDependency).some(installed => !installed);
+logger.info('Checking if required dependencies are installed...');
+const missingDeps = Object.keys(packageInfo.peerDependencies)
+ .map(checkDependency)
+ .some(installed => !installed);
if (missingDeps) {
logger.error('Please install the missing dependencies from the root directory of your Hexo site.');
- throw new Error();
+ /* eslint no-process-exit: "off" */
+ process.exit(-1);
}
diff --git a/layout/archive.jsx b/layout/archive.jsx
index 7455adc..b3e5f4c 100644
--- a/layout/archive.jsx
+++ b/layout/archive.jsx
@@ -21,7 +21,7 @@ module.exports = class extends Component {
post.categories.forEach((category, i) => {
categories.push({category.name});
if (i < post.categories.length - 1) {
- categories.push('/');
+ categories.push(' / ');
}
});
return
@@ -36,13 +36,7 @@ module.exports = class extends Component {
dateTime={date_xml(post.date)}>{date(post.date)}
{post.title}
-
-
- {categories.length ?
- {categories}
-
: null}
-
-
+ {categories.length ? {categories}
: null}
;
diff --git a/layout/common/article.jsx b/layout/common/article.jsx
index 7320046..0d6179e 100644
--- a/layout/common/article.jsx
+++ b/layout/common/article.jsx
@@ -45,7 +45,7 @@ module.exports = class extends Component {
page.categories.forEach((category, i) => {
categories.push({category.name});
if (i < page.categories.length - 1) {
- categories.push('/');
+ categories.push(' / ');
}
});
return categories;
@@ -62,7 +62,7 @@ module.exports = class extends Component {
{/* Visitor counter */}
{plugins && plugins.busuanzi === true ? 0')
+ __html: '' + _p('plugin.visit', ' 0')
}}> : null}
: null}
@@ -73,12 +73,12 @@ module.exports = class extends Component {
{/* Content/Excerpt */}
{/* Tags */}
- {!index && Array.isArray(page.tags) && page.tags.length ?
+ {!index && page.tags && page.tags.length ?
diff --git a/layout/widget/recent_posts.jsx b/layout/widget/recent_posts.jsx
index dfc2368..45155d1 100644
--- a/layout/widget/recent_posts.jsx
+++ b/layout/widget/recent_posts.jsx
@@ -13,7 +13,7 @@ class RecentPosts extends Component {
post.categories.forEach((category, i) => {
categories.push(
{category.name});
if (i < post.categories.length - 1) {
- categories.push('/');
+ categories.push(' / ');
}
});
return
@@ -26,7 +26,7 @@ class RecentPosts extends Component {
{post.title}
-
{categories}
+ {categories.length ?
{categories}
: null}
;
diff --git a/layout/widget/toc.jsx b/layout/widget/toc.jsx
index c91df80..c2c347a 100644
--- a/layout/widget/toc.jsx
+++ b/layout/widget/toc.jsx
@@ -1,4 +1,4 @@
-const cheerio = require('cheerio');
+const { tocObj: getTocObj } = require('hexo-util');
const { Component } = require('inferno');
const { cacheComponent } = require('../util/cache');
@@ -33,18 +33,13 @@ const { cacheComponent } = require('../util/cache');
* }
*/
function getToc(content) {
- const $ = cheerio.load(content, { decodeEntities: false });
const toc = {};
const levels = [0, 0, 0];
- // Get top 3 headings that are present in the content
- const tags = [1, 2, 3, 4, 5, 6].map(i => 'h' + i).filter(h => $(h).length > 0).slice(0, 3);
- if (tags.length === 0) {
- return toc;
- }
- $(tags.join(',')).each(function() {
- const level = tags.indexOf(this.name);
- const id = $(this).attr('id');
- const text = $(this).text();
+ 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) {
diff --git a/package.json b/package.json
index eeef64b..970c1c8 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"scripts": {
"lint": "eslint --ext .js --ext .jsx .",
"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"
+ "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",
@@ -20,5 +20,15 @@
"eslint-config-hexo": "^4.1.0",
"eslint-plugin-react": "^7.17.0",
"mocha": "^6.2.2"
+ },
+ "peerDependencies": {
+ "hexo": "^4.0.0",
+ "hexo-util": "^1.8.0",
+ "hexo-log": "^1.0.0",
+ "hexo-pagination": "^1.0.0",
+ "hexo-renderer-inferno": "^0.1.1",
+ "inferno": "^7.3.3",
+ "inferno-create-element": "^7.3.3",
+ "moment": "^2.22.2"
}
-}
+}
\ No newline at end of file
diff --git a/scripts/index.js b/scripts/index.js
index a6e5b74..cba979d 100644
--- a/scripts/index.js
+++ b/scripts/index.js
@@ -1,7 +1,7 @@
-/* global hexo*/
+/* global hexo */
require('../include/task/welcome');
-require('../include/task/check_deps');
-require('../include/task/check_config');
+require('../include/task/dependencies');
+// require('../include/task/check_config');
require('../include/generator/categories')(hexo);
require('../include/generator/category')(hexo);
require('../include/generator/tags')(hexo);