fix(*): layout fixes & use peer deps & del cheerio

pull/588/head
ppoffice 2019-12-24 12:28:50 -05:00
parent 8435454bb3
commit f1e22741df
8 changed files with 37 additions and 55 deletions

View File

@ -33,21 +33,6 @@
"SwitchCase": 1 "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": [ "react/no-unknown-property": [
"error", "error",
{ {

View File

@ -1,5 +1,7 @@
const logger = require('hexo-log')(); const logger = require('hexo-log')();
const packageInfo = require('../../package.json');
// FIXME: will not check against package version
function checkDependency(name) { function checkDependency(name) {
try { try {
require.resolve(name); require.resolve(name);
@ -10,16 +12,12 @@ function checkDependency(name) {
return false; return false;
} }
logger.info('Checking dependencies'); logger.info('Checking if required dependencies are installed...');
const missingDeps = [ const missingDeps = Object.keys(packageInfo.peerDependencies)
'js-yaml', .map(checkDependency)
'moment', .some(installed => !installed);
'cheerio',
'hexo-util',
'hexo-log',
'hexo-pagination'
].map(checkDependency).some(installed => !installed);
if (missingDeps) { if (missingDeps) {
logger.error('Please install the missing dependencies from the root directory of your Hexo site.'); 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);
} }

View File

@ -21,7 +21,7 @@ module.exports = class extends Component {
post.categories.forEach((category, i) => { post.categories.forEach((category, i) => {
categories.push(<a class="has-link-grey" href={category.url}>{category.name}</a>); categories.push(<a class="has-link-grey" href={category.url}>{category.name}</a>);
if (i < post.categories.length - 1) { if (i < post.categories.length - 1) {
categories.push('/'); categories.push(' / ');
} }
}); });
return <article class="media"> return <article class="media">
@ -36,13 +36,7 @@ module.exports = class extends Component {
dateTime={date_xml(post.date)}>{date(post.date)}</time> dateTime={date_xml(post.date)}>{date(post.date)}</time>
<a class="title has-link-black-ter is-size-6 has-text-weight-normal" <a class="title has-link-black-ter is-size-6 has-text-weight-normal"
href={url_for(post.link || post.path)} >{post.title}</a> href={url_for(post.link || post.path)} >{post.title}</a>
<div class="level article-meta is-mobile"> {categories.length ? <p class="is-size-7 is-uppercase">{categories}</p> : null}
<div class="level-left">
{categories.length ? <div class="level-item is-size-7 is-uppercase">
{categories}
</div> : null}
</div>
</div>
</div> </div>
</div> </div>
</article>; </article>;

View File

@ -45,7 +45,7 @@ module.exports = class extends Component {
page.categories.forEach((category, i) => { page.categories.forEach((category, i) => {
categories.push(<a class="has-link-grey" href={category.url}>{category.name}</a>); categories.push(<a class="has-link-grey" href={category.url}>{category.name}</a>);
if (i < page.categories.length - 1) { if (i < page.categories.length - 1) {
categories.push('/'); categories.push(' / ');
} }
}); });
return categories; return categories;
@ -62,7 +62,7 @@ module.exports = class extends Component {
{/* Visitor counter */} {/* Visitor counter */}
{plugins && plugins.busuanzi === true ? <span class="level-item has-text-grey" id="busuanzi_container_page_pv" {plugins && plugins.busuanzi === true ? <span class="level-item has-text-grey" id="busuanzi_container_page_pv"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: _p('plugin.visit', '<i class="far fa-eye"></i>&nbsp;&nbsp;<span id="busuanzi_value_page_pv">0</span>') __html: '<i class="far fa-eye"></i>' + _p('plugin.visit', '&nbsp;&nbsp;<span id="busuanzi_value_page_pv">0</span>')
}}></span> : null} }}></span> : null}
</div> </div>
</div> : null} </div> : null}
@ -73,12 +73,12 @@ module.exports = class extends Component {
{/* Content/Excerpt */} {/* Content/Excerpt */}
<div class="content" dangerouslySetInnerHTML={{ __html: index && page.excerpt ? page.excerpt : page.content }}></div> <div class="content" dangerouslySetInnerHTML={{ __html: index && page.excerpt ? page.excerpt : page.content }}></div>
{/* Tags */} {/* Tags */}
{!index && Array.isArray(page.tags) && page.tags.length ? <div class="level is-size-7 is-uppercase"> {!index && page.tags && page.tags.length ? <div class="level is-size-7 is-uppercase">
<div class="level-start"> <div class="level-start">
<div class="level-item"> <div class="level-item">
<span class="is-size-6 has-text-grey has-mr-7">#</span> <span class="is-size-6 has-text-grey has-mr-7">#</span>
{page.tags.map(tag => { {page.tags.map(tag => {
return <a class="has-link-grey" rel="tag" href={url_for(tag.path)}>{tag.name}</a>; return <a class="has-link-grey has-mr-6" rel="tag" href={url_for(tag.path)}>{tag.name}</a>;
})} })}
</div> </div>
</div> </div>

View File

@ -13,7 +13,7 @@ class RecentPosts extends Component {
post.categories.forEach((category, i) => { post.categories.forEach((category, i) => {
categories.push(<a class="has-link-grey" href={category.url}>{category.name}</a>); categories.push(<a class="has-link-grey" href={category.url}>{category.name}</a>);
if (i < post.categories.length - 1) { if (i < post.categories.length - 1) {
categories.push('/'); categories.push(' / ');
} }
}); });
return <article class="media"> return <article class="media">
@ -26,7 +26,7 @@ class RecentPosts extends Component {
<div class="content"> <div class="content">
<div><time class="has-text-grey is-size-7 is-uppercase" dateTime={post.dateXml}>{post.date}</time></div> <div><time class="has-text-grey is-size-7 is-uppercase" dateTime={post.dateXml}>{post.date}</time></div>
<a href={post.url} class="title has-link-black-ter is-size-6 has-text-weight-normal">{post.title}</a> <a href={post.url} class="title has-link-black-ter is-size-6 has-text-weight-normal">{post.title}</a>
<p class="is-size-7 is-uppercase">{categories}</p> {categories.length ? <p class="is-size-7 is-uppercase">{categories}</p> : null}
</div> </div>
</div> </div>
</article>; </article>;

View File

@ -1,4 +1,4 @@
const cheerio = require('cheerio'); const { tocObj: getTocObj } = require('hexo-util');
const { Component } = require('inferno'); const { Component } = require('inferno');
const { cacheComponent } = require('../util/cache'); const { cacheComponent } = require('../util/cache');
@ -33,18 +33,13 @@ const { cacheComponent } = require('../util/cache');
* } * }
*/ */
function getToc(content) { function getToc(content) {
const $ = cheerio.load(content, { decodeEntities: false });
const toc = {}; const toc = {};
const levels = [0, 0, 0]; const levels = [0, 0, 0];
// Get top 3 headings that are present in the content const tocObj = getTocObj(content, { min_depth: 1, max_depth: 6 });
const tags = [1, 2, 3, 4, 5, 6].map(i => 'h' + i).filter(h => $(h).length > 0).slice(0, 3); const minLevel = Math.min(...tocObj.map(item => item.level));
if (tags.length === 0) { tocObj.forEach(item => {
return toc; const { text, id } = item;
} const level = item.level - minLevel;
$(tags.join(',')).each(function() {
const level = tags.indexOf(this.name);
const id = $(this).attr('id');
const text = $(this).text();
for (let i = 0; i < levels.length; i++) { for (let i = 0; i < levels.length; i++) {
if (i > level) { if (i > level) {

View File

@ -12,7 +12,7 @@
"scripts": { "scripts": {
"lint": "eslint --ext .js --ext .jsx .", "lint": "eslint --ext .js --ext .jsx .",
"test": "mocha test/index.js", "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": { "devDependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
@ -20,5 +20,15 @@
"eslint-config-hexo": "^4.1.0", "eslint-config-hexo": "^4.1.0",
"eslint-plugin-react": "^7.17.0", "eslint-plugin-react": "^7.17.0",
"mocha": "^6.2.2" "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"
} }
} }

View File

@ -1,7 +1,7 @@
/* global hexo*/ /* global hexo */
require('../include/task/welcome'); require('../include/task/welcome');
require('../include/task/check_deps'); require('../include/task/dependencies');
require('../include/task/check_config'); // require('../include/task/check_config');
require('../include/generator/categories')(hexo); require('../include/generator/categories')(hexo);
require('../include/generator/category')(hexo); require('../include/generator/category')(hexo);
require('../include/generator/tags')(hexo); require('../include/generator/tags')(hexo);