-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
1,149 additions
and
15,699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- "8" | ||
- "9" | ||
- "10" | ||
- "11" | ||
- "12" | ||
git: | ||
depth: 5 | ||
quiet: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* hexo-prism-plugin | ||
* author: ele828 | ||
* license: MIT | ||
* patched by SukkaW for hexo-theme-suka | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function (hexo) { | ||
// Plugin settings | ||
const config = hexo.config.suka_theme.prism; | ||
|
||
if (config.enable !== true) { | ||
return; | ||
} | ||
|
||
const Prism = require('node-prismjs'); | ||
|
||
const map = { | ||
''': '\'', | ||
'&': '&', | ||
'>': '>', | ||
'<': '<', | ||
'"': '"' | ||
}; | ||
|
||
const regex = /<pre><code class="(.*)?">([\s\S]*?)<\/code><\/pre>/igm; | ||
const captionRegex = /<p><code>(?![\s\S]*<code)(.*?)\s(.*?)\n([\s\S]*)<\/code><\/p>/igm; | ||
|
||
const line_number = config.line_number || true; | ||
|
||
/** | ||
* Unescape from Marked escape | ||
* @param {String} str | ||
* @return {String} | ||
*/ | ||
function unescape(str) { | ||
if (!str || str === null) return ''; | ||
const re = new RegExp('(' + Object.keys(map).join('|') + ')', 'g'); | ||
return String(str).replace(re, (match) => map[match]); | ||
} | ||
|
||
/** | ||
* Code transform for prism plugin. | ||
* @param {Object} data | ||
* @return {Object} | ||
*/ | ||
function PrismPlugin(data) { | ||
// Patch for caption support | ||
if (captionRegex.test(data.content)) { | ||
// Attempt to parse the code | ||
data.content = data.content.replace(captionRegex, (origin, lang, caption, code) => { | ||
if (!lang || !caption || !code) return origin; | ||
return `<figcaption>${caption}</figcaption><pre><code class="${lang}">${code}</code></pre>`; | ||
}); | ||
} | ||
|
||
data.content = data.content.replace(regex, (origin, lang, code) => { | ||
const lineNumbers = line_number ? 'line-numbers' : ''; | ||
const startTag = `<pre class="${lineNumbers} highlight language-${lang}"><code class="language-${lang}">`; | ||
const endTag = `</code></pre>`; | ||
code = unescape(code); | ||
let parsedCode = ''; | ||
if (Prism.languages[lang]) { | ||
parsedCode = Prism.highlight(code, Prism.languages[lang]); | ||
} else { | ||
parsedCode = code; | ||
} | ||
if (line_number) { | ||
const match = parsedCode.match(/\n(?!$)/g); | ||
const linesNum = match ? match.length + 1 : 1; | ||
let lines = new Array(linesNum + 1); | ||
lines = lines.join('<span></span>'); | ||
const startLine = '<span aria-hidden="true" class="line-numbers-rows">'; | ||
const endLine = '</span>'; | ||
parsedCode += startLine + lines + endLine; | ||
} | ||
return startTag + parsedCode + endTag; | ||
}); | ||
|
||
return data; | ||
} | ||
|
||
hexo.extend.filter.register('after_post_render', PrismPlugin); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module.exports = function (hexo) { | ||
if (hexo.config.suka_theme.search.enable !== true) { | ||
return; | ||
} | ||
|
||
const pathFn = require('path'); | ||
const { stripHTML } = require('hexo-util'); | ||
|
||
let config = hexo.config.suka_theme.search; | ||
|
||
// Set default search path | ||
if (!config.path) config.path = 'search.json'; | ||
|
||
function searchGenerator(locals = {}) { | ||
const url_for = hexo.extend.helper.get('url_for').bind(this); | ||
|
||
const parse = (item) => { | ||
let _item = {}; | ||
if (item.title) _item.title = item.title; | ||
if (item.date) _item.date = item.date; | ||
if (item.path) _item.url = url_for(item.path); | ||
if (item.tags && item.tags.length > 0) { | ||
_item.tags = []; | ||
item.tags.forEach((tag) => { | ||
_item.tags.push(tag.name); | ||
}); | ||
} | ||
if (item.categories && item.categories.length > 0) { | ||
_item.categories = []; | ||
item.categories.forEach((cate) => { | ||
_item.categories.push(cate.name); | ||
}); | ||
} | ||
if (item._content) { | ||
_item.content = stripHTML(item.content.trim().replace(/<pre(.*?)\<\/pre\>/gs, '')) | ||
.replace(/\n/g, ' ').replace(/\s+/g, ' ') | ||
.replace(new RegExp('(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]', 'g'), ''); | ||
} | ||
return _item; | ||
}; | ||
|
||
const searchfield = config.field; | ||
|
||
let posts, | ||
pages; | ||
|
||
if (searchfield) { | ||
if (searchfield === 'post') { | ||
posts = locals.posts.sort('-date'); | ||
} else if (searchfield === 'page') { | ||
pages = locals.pages; | ||
} else { | ||
posts = locals.posts.sort('-date'); | ||
pages = locals.pages; | ||
} | ||
} else { | ||
posts = locals.posts.sort('-date'); | ||
} | ||
|
||
let res = []; | ||
|
||
if (posts) { | ||
posts.each((post) => { | ||
res.push(parse(post)); | ||
}); | ||
} | ||
if (pages) { | ||
pages.each((page) => { | ||
res.push(parse(page)); | ||
}); | ||
} | ||
|
||
return { | ||
path: config.path, | ||
data: JSON.stringify(res) | ||
}; | ||
} | ||
|
||
if (pathFn.extname(config.path) === '.json') { | ||
hexo.extend.generator.register('json', searchGenerator); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { htmlTag } = require('hexo-util'); | ||
|
||
module.exports = function (hexo) { | ||
hexo.extend.helper.register('favicon', function () { | ||
const url_for = hexo.extend.helper.get('url_for').bind(this); | ||
const { favicon } = this.theme.head; | ||
|
||
let html = ''; | ||
|
||
if (favicon.ico) { | ||
html += htmlTag('link', { rel: 'icon', type: 'image/ico', href: url_for(favicon.ico) }); | ||
} | ||
if (favicon.apple_touch_icon) { | ||
html += htmlTag('link', { rel: 'apple-touch-icon', sizes: '180x180', href: url_for(favicon.apple_touch_icon) }); | ||
} | ||
if (favicon.large) { | ||
html += htmlTag('link', { rel: 'icon', typt: 'image/png', sizes: '192x192', href: url_for(favicon.large) }); | ||
} | ||
if (favicon.medium) { | ||
html += htmlTag('link', { rel: 'icon', typt: 'image/png', sizes: '32x32', href: url_for(favicon.medium) }); | ||
} | ||
if (favicon.small) { | ||
html += htmlTag('link', { rel: 'icon', typt: 'image/png', sizes: '16x16', href: url_for(favicon.small) }); | ||
} | ||
|
||
return html; | ||
}); | ||
|
||
hexo.extend.helper.register('site_logo', function () { | ||
const full_url_for = hexo.extend.helper.get('full_url_for').bind(this); | ||
const { favicon } = this.theme.head; | ||
const getFavicon = (type) => full_url_for(favicon[type]); | ||
|
||
if (favicon.large) return getFavicon('large'); | ||
if (favicon.apple_touch_icon) return getFavicon('apple_touch_icon'); | ||
if (favicon.medium) return getFavicon('medium'); | ||
if (favicon.small) return getFavicon('small'); | ||
if (favicon.ico) return getFavicon('ico'); | ||
|
||
return 'https://theme-suka.skk.moe/demo/img/suka-favicon.png'; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Generate title string based on page type | ||
* @example | ||
* <%- page_title(page) %> | ||
* <%- page_descr(page) %> | ||
* <%- page_tags(page) %> | ||
*/ | ||
|
||
const { stripHTML } = require('hexo-util'); | ||
|
||
module.exports = function (hexo) { | ||
hexo.extend.helper.register('page_title', function (page = null) { | ||
page = (page === null) ? this.page : page; | ||
|
||
let title = page.title; | ||
|
||
if (this.is_archive()) { | ||
title = this.__('archive'); | ||
if (this.is_month()) { | ||
title += `: ${page.year}/${page.month}`; | ||
} else if (this.is_year()) { | ||
title += `: ${page.year}`; | ||
} | ||
} else if (this.is_category()) { | ||
title = `${this.__('category')}: ${page.category}`; | ||
} else if (this.is_tag()) { | ||
title = `${this.__('tag')}: ${page.tag}`; | ||
} | ||
|
||
return [title, hexo.config.title].filter((str) => typeof (str) !== 'undefined' && str.trim() !== '').join(' | '); | ||
}); | ||
|
||
hexo.extend.helper.register('page_descr', function (page = null) { | ||
page = (page === null) ? this.page : page; | ||
|
||
let description = page.description || page.excerpt || page.content || hexo.config.description ; | ||
|
||
description = stripHTML(description).trim() // Remove prefixing/trailing spaces | ||
.replace(/^s*/, '').replace(/s*$/, '') | ||
.substring(0, 200) | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/&/g, '&') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
.replace(/\n/g, ' '); // Replace new lines by spaces | ||
|
||
return [description, hexo.config.author, hexo.config.title].filter((str) => typeof (str) !== 'undefined' && str.trim() !== '').join(' - '); | ||
}); | ||
|
||
hexo.extend.helper.register('page_tags', function (page = null) { | ||
page = (page === null) ? this.page : page; | ||
const { config } = this; | ||
|
||
let page_tags = page.keywords || page.tags, | ||
site_tags = config.keywords || this.theme.head.keywords; | ||
|
||
const parse = (tags) => { | ||
let result = []; | ||
if (tags) { | ||
if (typeof tags === 'string') { | ||
result.push(tags); | ||
} else if (tags.length) { | ||
result.push(tags.map(tag => tag.name ? tag.name : tag).filter(tags => !!tags).join(', ')); | ||
} | ||
} | ||
return result; | ||
}; | ||
|
||
return [parse(page_tags), parse(site_tags)].filter(tags => tags.length && tags.length !== 0).join(', '); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const qrImage = require('qr-image'); | ||
|
||
module.exports = function (hexo) { | ||
hexo.extend.helper.register('qrcode', (url, option) => { | ||
const qrConfig = Object.assign( | ||
{ | ||
size: 6, | ||
margin: 0 | ||
}, | ||
option || {} | ||
); | ||
|
||
const qrUrl = url.replace('index.html', ''); | ||
|
||
const buffer = qrImage.imageSync( | ||
qrUrl, | ||
{ | ||
type: 'png', | ||
size: qrConfig.size, | ||
margin: qrConfig.margin | ||
} | ||
); | ||
return `data:image/png;base64,${buffer.toString('base64')}`; | ||
}); | ||
}; |
Oops, something went wrong.