Skip to content

Commit

Permalink
detail improvements (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikeq committed Oct 3, 2019
1 parent c899f54 commit 49d96ee
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion layout/index.ejs
Expand Up @@ -24,7 +24,7 @@
<% if (theme.ga) { %><%- ga(theme.ga) %><% } -%>
</head>
<body lang="<%= config.language %>">
<%- `<${theme.runtime.rootSelector}></${theme.runtime.rootSelector}>` %>
<%- `<${theme.runtime.selector}></${theme.runtime.selector}>` %>
<%- theme.scripts %>
</body>
</html>
19 changes: 14 additions & 5 deletions lib/config.js
Expand Up @@ -7,7 +7,6 @@ const utils = require('./utils');
const pkg = require('../package.json');
const configSchema = require('./configSchema.json');
const resources = require('../source/_resources.json');
const external_regex = /^(\w+:)?\/\/\w+\.\w+/;

module.exports = function (hexo) {
hexo.on('generateBefore', function () {
Expand All @@ -24,7 +23,7 @@ module.exports = function (hexo) {
$description: site.description
});
const urlFn = result.static_prefix ?
a => external_regex.test(a) ? a : `${result.static_prefix}/${a}` :
a => utils.isExternal(a) ? a : `${result.static_prefix}/${a}` :
urlFor.bind(this);

// override default language
Expand All @@ -41,6 +40,16 @@ module.exports = function (hexo) {
delete disqus.shortname;
}

// convert menu to array
if (result.menu) {
result.menu = Object.keys(result.menu).map(k => {
const item = [k, result.menu[k]];
if (utils.isExternal(item[1])) item.push(1);
return item;
})
}

// sns
if (result.sns) {
const sns = [];
if (result.sns.email !== undefined) result.sns.email = 'mailto:' + (result.sns.email || email);
Expand Down Expand Up @@ -115,12 +124,12 @@ module.exports = function (hexo) {
}

// override boolean value to html string
if (result.footer.powered) result.footer.powered = __('footer.powered', '<a href="https://hexo.io" target="_blank" rel="external nofollow">Hexo</a>')
if (result.footer.theme) result.footer.theme = __('footer.theme') + ' - <a href="https://github.com/ikeq/hexo-theme-inside" target="_blank" rel="external nofollow">Inside</a>'
if (result.footer.powered) result.footer.powered = __('footer.powered', '<a href="https://hexo.io" target="_blank" rel="external nofollow noopener">Hexo</a>')
if (result.footer.theme) result.footer.theme = __('footer.theme') + ' - <a href="https://github.com/ikeq/hexo-theme-inside" target="_blank" rel="external nofollow noopener">Inside</a>'

result.runtime = {
// root selector
rootSelector: resources.root,
selector: resources.root,
hash: utils.md5([
...hexo.locals.getters.pages().sort('-date').toArray(),
...hexo.locals.getters.posts().sort('-date').toArray()
Expand Down
2 changes: 1 addition & 1 deletion lib/configSchema.json
Expand Up @@ -151,7 +151,7 @@
"license": {
"type": "string",
"contentMediaType": "text/html" ,
"default": "Attribution-NonCommercial-NoDerivatives 4.0 International (<a href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\" rel=\"external nofollow\" target=\"_blank\">CC BY-NC-ND 4.0</a>)"
"default": "Attribution-NonCommercial-NoDerivatives 4.0 International (<a href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\" rel=\"external nofollow noopener\" target=\"_blank\">CC BY-NC-ND 4.0</a>)"
},
"published": { "type": "boolean" },
"updated": { "type": "boolean" },
Expand Down
4 changes: 4 additions & 0 deletions lib/filter/post.js
Expand Up @@ -136,6 +136,10 @@ module.exports = function (data) {

// optimize code block
$('.highlight')
// remove unused language class
.each(function () {
$(this).attr('class', 'highlight')
})
.children('table').wrap('<div></div>');

// wrap <script> with <div class="is-snippet">
Expand Down
18 changes: 11 additions & 7 deletions lib/utils.js
@@ -1,17 +1,17 @@
const crypto = require('crypto');

exports.type = function (o) {
return Object.prototype.toString.call(o).split(' ')[1].slice(0, -1).toLowerCase()
exports.type = function (value) {
return Object.prototype.toString.call(value).slice(8, -1).toLowerCase()
}

exports.isObject = function (obj) {
return exports.type(obj) === 'object';
exports.isObject = function (value) {
return exports.type(value) === 'object';
}

exports.isEmptyObject = function (obj) {
if (!exports.isObject(obj)) return false;
exports.isEmptyObject = function (value) {
if (!exports.isObject(value)) return false;

for (const key in obj) return false;
for (const key in value) return false;
return true;
}

Expand Down Expand Up @@ -745,3 +745,7 @@ exports.parseBackground = function (value) {
image: value
}
}

exports.isExternal = function (link) {
return !!link.match(/^(\w+:)?\/\/\w+\.\w+/);
}
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-inside",
"version": "2.4.1",
"version": "2.4.2",
"description": "❤️ SPA, flat and clean theme for Hexo.",
"scripts": {
"test": "jasmine --config=test/jasmine.json"
Expand All @@ -14,9 +14,9 @@
"hexo theme",
"angular"
],
"author": "elmorec <elmore.c@outlook.com>",
"author": "ikeq <ikeq@foxmail.com>",
"maintainers": [
"elmorec <elmore.c@outlook.com>"
"ikeq <ikeq@foxmail.com>"
],
"license": "MIT",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion source/_resources.json
@@ -1 +1 @@
{"root":"is-a","styles":["styles.e987407a0a9d77c7ba00.css"],"scripts":["runtime.caef73fae70e33459c5a.js","polyfills.28555e618578fe61f50a.js"],"locales":{"zh-Hans":"main.1efb2acb62d508679d87.zh-Hans.js","zh-Hant":"main.5509fae49a8263eb6b15.zh-Hant.js","ja":"main.77374c447781af9644db.ja.js","en":"main.e456207a2fb3a1560aeb.js"}}
{"root":"is-a","styles":["styles.d1f4718a192abf1f2afd.css"],"scripts":["runtime.caef73fae70e33459c5a.js","polyfills.28555e618578fe61f50a.js"],"locales":{"zh-Hant":"main.5ac6b548dbff945e028b.zh-Hant.js","zh-Hans":"main.7773219322474154c9eb.zh-Hans.js","en":"main.a6ef31dc523c76e5118c.js","ja":"main.c145738ea9113b8ce68e.ja.js"}}
1 change: 0 additions & 1 deletion source/main.1efb2acb62d508679d87.zh-Hans.js

This file was deleted.

1 change: 0 additions & 1 deletion source/main.5509fae49a8263eb6b15.zh-Hant.js

This file was deleted.

1 change: 1 addition & 0 deletions source/main.5ac6b548dbff945e028b.zh-Hant.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion source/main.77374c447781af9644db.ja.js

This file was deleted.

1 change: 1 addition & 0 deletions source/main.7773219322474154c9eb.zh-Hans.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions source/main.a6ef31dc523c76e5118c.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions source/main.c145738ea9113b8ce68e.ja.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion source/main.e456207a2fb3a1560aeb.js

This file was deleted.

Large diffs are not rendered by default.

0 comments on commit 49d96ee

Please sign in to comment.