Skip to content

Commit

Permalink
fix several bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ikeq committed Sep 14, 2019
1 parent 7441aed commit 0275c18
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
8 changes: 8 additions & 0 deletions lib/filter/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ module.exports = function (data) {
$el.find('a.headerlink').remove().end().append(`<a href="${link}#${$el.attr('id')}"></a>`);
});

// append `link` for hash link
$('a').each(function () {
const $anchor = $(this),
href = $anchor.attr('href')

if (href && href.startsWith('#')) $anchor.attr('href', link + href)
});

return $.html();
}
};
33 changes: 21 additions & 12 deletions lib/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ module.exports = function (hexo) {

hexo.extend.generator.register('inside', function (locals) {
const sLocals = {
tags: locals.tags.sort('name').map(data => {
data.posts = data.posts.filter(published).sort('-date');
return data;
}).filter(data => data.posts.length),

categories: locals.categories.sort('name').map(data => {
data.posts = data.posts.filter(published).sort('-date');
return data;
}).filter(data => data.posts.length),

tags: getCollection(locals.tags),
categories: getCollection(locals.categories),
pages: locals.pages.filter(filterBuiltInRoutes).toArray(),

posts: locals.posts.filter(published).filter(filterBuiltInRoutes).sort('-date').toArray()
};

return flatten(generators.map(fn => fn.call(this, sLocals)));
});

// Filter built-in routes to improve compatibility
/**
* Filter built-in routes to improve compatibility
*
* @param {*} post
* @returns {boolean}
*/
function filterBuiltInRoutes(post) {
if (builtInRoutes.includes(post.path.split('/')[0])) {
hexo.log.warn(post.path + ' won\'t be rendered.');
Expand All @@ -44,4 +40,17 @@ module.exports = function (hexo) {

return true;
}

/**
* Sort posts of tag and category
*
* @param {any[]} collection
* @returns {any[]}
*/
function getCollection(collection) {
return collection.sort('name').map(data => ({
posts: data.posts.filter(published).sort('-date'),
name: data.name
})).filter(data => data.posts.length)
}
};
2 changes: 1 addition & 1 deletion lib/theme-processor/localized-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { localeId } = require('../utils');
const Pattern = require('hexo-util').Pattern;
const { Pattern } = require('hexo-util');
const { locales: localeScripts } = require('../../source/_resources.json');

module.exports = function (hexo) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ exports.parseToc = function (content, depth) {
/^<h4.*id="([^"]*)"[^>]*>(.*)<a /,
/^<h5.*id="([^"]*)"[^>]*>(.*)<a /,
].slice(0, depth + 1),
headings = content.match(/<(h[12345]).*id="([^"]*)".*>(.*)<a.*<\/\1>/g);
headings = content.match(/<(h[12345]).*?id="([^"]*)".*?>(.*?)<a.*?<\/\1>/g);

if (!headings) return [];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-inside",
"version": "2.4.0-beta.2",
"version": "2.4.0",
"description": "❤️ SPA, flat and clean theme for Hexo.",
"scripts": {
"test": "jasmine --config=test/jasmine.json"
Expand Down
2 changes: 1 addition & 1 deletion source/_resources.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":"is-a","styles":["styles.9477318680c7e6b720a2.css"],"scripts":["runtime.caef73fae70e33459c5a.js","polyfills.28555e618578fe61f50a.js"],"locales":{"en":"main.3c8fe2175e9d028e033b.js","ja":"main.45d1e4209486560b00ce.ja.js","zh-Hans":"main.5f57ed8aacba80770b83.zh-Hans.js","zh-Hant":"main.dec5dcd89e85221e092e.zh-Hant.js"}}
{"root":"is-a","styles":["styles.e987407a0a9d77c7ba00.css"],"scripts":["runtime.caef73fae70e33459c5a.js","polyfills.28555e618578fe61f50a.js"],"locales":{"en":"main.3c8fe2175e9d028e033b.js","ja":"main.45d1e4209486560b00ce.ja.js","zh-Hans":"main.5f57ed8aacba80770b83.zh-Hans.js","zh-Hant":"main.dec5dcd89e85221e092e.zh-Hant.js"}}

Large diffs are not rendered by default.

0 comments on commit 0275c18

Please sign in to comment.