mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-06-06 05:11:45 +08:00
Breaking Change
1. 不再支持hexo 4.0.0以下版本 2. 添加hexo fragment_cache,加快生成速度 3. 完善V5圖標顯示,不再需要同時加載V4和v5圖標 4. 去除cheerio依賴 5. 整合豆瓣配置,增加配置遊戲,圖書頁面top_img,可設置是否設置meta,解決部分瀏覽器無法顯示圖片問題 6. 友情鏈接除列表外可自定義內容 7. 可設置主頁標題距離頂部距離 8. 側邊欄可隱藏,可設置手機頁面是否隱藏 9. 增加disqusjs和utterances 兩個評論 10. 主頁文章增加tags和更新日期顯示,可以配置post_meta 11. 首頁subtitle可關閉打字效果,可設置打字效果顯示一次或loop 12. 增加valine和gitalk的配置 13. darkmode配置整理 14. 增加404頁面 15. post_beautify改為beautify,頁面美化不再只限於post頁,page頁也一樣 16. 可設置是否顯示cover,可設置各位置的cover顯示 17. 增加mermaid,可畫流程圖、狀態圖、時序圖、甘特圖等等 18. 增加pangu配置,中英文之間添加空格 19. 整合部分配置 20. post-copyright增加decode網址 (可以顯示中文) 21. 增加部分顏色配置 Feature 1. 適配IE 2. 增加一個Tag Plugins: 圖庫集 3. 增加一個Tag Plugins: tag-hide 功能 inline/block 4. 去除page頁開頭顯示與標題一樣的內容 5. aside 公告欄設置,支持html代碼 6. 手機界面sidebar顯示進度條和加深對應的標題 7. 主頁subtitle 的 hitokoto 顯示內容出處 9. footer 的hexo鏈接改為https 10. 修改手機下,menus和toc的打開效果 11. 手機頁面下,搜索界面全屏顯示 12. SEO優化,標題欄改為h1顯示 13. 閲讀模式優化,可根據light mode 和darkmode調整背景 14. 當屏蔽js時,header會出現(之前用js控制,會隱藏) Fixed 1. 修復Tencent Analytics的script加載為https #105 2. 修復相關文章,日期顯示錯誤bug 3. 修復gitalk報錯問題 4. 修復當valine background 是絕對地址時無法顯示的bug 5. 修復medium-zoom 無法使用的bug 6. 修復在safari下,點擊或移動到首頁文章cover,圓角變成正方形的bug #114 7. 修復在部分瀏覽器下,aside,友情鏈接頭像轉動變形的bug 8. 修復在寬度限制下,表格內容溢出屏幕外而出現滾動條的bug \#138 9. 修復gitalk js 在一些沒有設置評論的page里加載的bug 10. 修復tag plugins 的gist 在不同主題下的背景顏色問題(黑色主題下,文字不易觀看) 11. 修復highlight figcaption 顯示不全的bug 12. 修復disqus評論數無法獲取的bug 13. 修復子目錄在觸摸屏下點擊,偶爾不出現的bug 14. 修復a標籤太長(連續英文字母)不會換行的bug 15. 修復toc滾動時,閲讀進度條也跟著滾動的bug 16. 修復aside的圖片,可點擊顯示大圖bug 17. 修復activate-power-mode設置參數無效bug 18. 修復語言上的錯誤 \#156 19. 修復主頁在safari桌面端,首頁滾動卡頓的bug
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
hexo.extend.generator.register('404', function(locals){
|
||||
if (!hexo.theme.config.error_404.enable) return
|
||||
return {
|
||||
path: '404.html',
|
||||
data: locals.posts,
|
||||
layout: ['404']
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('hexo-fs');
|
||||
const url_for = require('hexo-util').url_for.bind(hexo);
|
||||
|
||||
function lazyProcess(htmlContent) {
|
||||
var bg = url_for(hexo.theme.config.lodding_bg.post);
|
||||
return htmlContent.replace(/<img(\s*?)src="(.*?)"(.*?)>/gi, (str, p1, p2, p3) => {
|
||||
if (/data-src/gi.test(str)) {
|
||||
return str;
|
||||
}
|
||||
if (/class="(.*?)"/gi.test(str)){
|
||||
str = str.replace(/class="(.*?)"/gi, (classStr, p1) => {
|
||||
return classStr.replace(p1, `${p1} lazyload`);
|
||||
})
|
||||
str = str.replace(p2, `${bg}`)
|
||||
return str.replace(p3, `${p3} data-src="${p2}"`);
|
||||
}
|
||||
str = str.replace(p2, `${bg}`)
|
||||
return str.replace(p3, `${p3} class="lazyload" data-src="${p2}"`);
|
||||
});
|
||||
}
|
||||
|
||||
var processPost = function(data) {
|
||||
if (!hexo.theme.config.lazyload.enable) return;
|
||||
data.content = lazyProcess.call(this, data.content);
|
||||
return data;
|
||||
};
|
||||
|
||||
hexo.extend.filter.register('after_post_render', processPost);
|
||||
@@ -0,0 +1,23 @@
|
||||
hexo.extend.filter.register("before_post_render", function(data) {
|
||||
if (data.cover == false) {
|
||||
data.randomcover = random_cover();
|
||||
return data;
|
||||
}
|
||||
data.cover = data.cover || random_cover();
|
||||
return data;
|
||||
});
|
||||
|
||||
var random_cover = function() {
|
||||
var cover;
|
||||
var num;
|
||||
if (!Array.isArray(hexo.theme.config.cover.default_cover)) {
|
||||
cover = hexo.theme.config.cover.default_cover;
|
||||
return cover;
|
||||
} else {
|
||||
num = Math.floor(
|
||||
Math.random() * hexo.theme.config.cover.default_cover.length
|
||||
);
|
||||
cover = hexo.theme.config.cover.default_cover[num];
|
||||
return cover;
|
||||
}
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
function gallery(args, content) {
|
||||
return `<div class="justified-gallery">${hexo.render.renderSync({text: content, engine: 'markdown'})}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('gallery', gallery, {ends: true});
|
||||
@@ -1,5 +1,3 @@
|
||||
const moment = require('moment');
|
||||
|
||||
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
var relatedPosts = [];
|
||||
currentPost.tags.forEach(function (tag) {
|
||||
@@ -9,6 +7,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
title: post.title,
|
||||
path: post.path,
|
||||
cover: post.cover,
|
||||
randomcover: post.randomcover,
|
||||
weight: 1,
|
||||
updated: post.updated,
|
||||
created: post.date
|
||||
@@ -32,17 +31,9 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
const config = hexo.theme.config;
|
||||
|
||||
var limit_num = config.related_post.limit || 6
|
||||
var lang = hexoConfig.language;
|
||||
var date_type = config.related_post.date_type || 'created'
|
||||
var headline_lang;
|
||||
if (lang === 'zh-CN') {
|
||||
headline_lang = '相关推荐';
|
||||
} else if (lang === 'zh-TW') {
|
||||
headline_lang = '相關推薦';
|
||||
} else {
|
||||
headline_lang = 'Recommend';
|
||||
}
|
||||
|
||||
var headline_lang = this._p('post.recommend')
|
||||
|
||||
relatedPosts = relatedPosts.sort(compare('weight'));
|
||||
var lazy_src = config.lazyload.enable ? lazy_src = 'data-src' : lazy_src = 'src'
|
||||
var lazy_class = config.lazyload.enable ? lazy_class = 'lazyload' : lazy_class = ''
|
||||
@@ -53,15 +44,13 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
result += '<div class="relatedPosts_list">'
|
||||
|
||||
for (var i = 0; i < Math.min(relatedPosts.length, limit_num); i++) {
|
||||
|
||||
var cover = relatedPosts[i].cover
|
||||
|
||||
var cover = relatedPosts[i].cover === false ? relatedPosts[i].randomcover : relatedPosts[i].cover
|
||||
result += '<div class="relatedPosts_item"><a href="' + hexoConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title + '">';
|
||||
result += '<img class="relatedPosts_cover ' + lazy_class + '"' + lazy_src + '="' + cover + '">';
|
||||
if (date_type == 'created') {
|
||||
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i>' + ' ' + date(relatedPosts[i].created) + '</div>'
|
||||
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i>' + ' ' + this.date(relatedPosts[i].created,hexoConfig.date_format) + '</div>'
|
||||
} else {
|
||||
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-history fa-fw" aria-hidden="true"></i>' + ' ' + date(relatedPosts[i].updated) + '</div>'
|
||||
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-history fa-fw" aria-hidden="true"></i>' + ' ' + this.date(relatedPosts[i].updated,hexoConfig.date_format) + '</div>'
|
||||
}
|
||||
result += '<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>';
|
||||
result += '</div></a></div>'
|
||||
@@ -98,10 +87,4 @@ function compare(attr) {
|
||||
var val2 = b[attr];
|
||||
return val2 - val1;
|
||||
}
|
||||
}
|
||||
|
||||
function date(date) {
|
||||
var config = hexo.theme.config.rootConfig
|
||||
moment.locale(config.language)
|
||||
return moment(date).format(config.date_format)
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
'use strict';
|
||||
hexo.extend.filter.register('after_post_render', data => {
|
||||
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const $ = cheerio.load(data.content, {
|
||||
decodeEntities: false
|
||||
});
|
||||
var theme = hexo.theme.config;
|
||||
|
||||
if (theme.highlight_shrink === 'none' && !theme.highlight_lang && !theme.highlight_copy) {
|
||||
return;
|
||||
}
|
||||
|
||||
$('figure.highlight').wrap('<div class="code-area-wrap"></div>')
|
||||
var $highlight_layout = $('<div class="highlight-tools"></div>')
|
||||
|
||||
$('figure').before($highlight_layout)
|
||||
|
||||
if (theme.highlight_shrink == true) {
|
||||
var $code_expand = $('<i class="fa fa-angle-down code-expand code-closed" aria-hidden="true"></i>')
|
||||
$('.highlight-tools').append($code_expand)
|
||||
} else if (theme.highlight_shrink === false) {
|
||||
var $code_expand = $('<i class="fa fa-angle-down code-expand" aria-hidden="true"></i>')
|
||||
$('.highlight-tools').append($code_expand)
|
||||
}
|
||||
|
||||
if (theme.highlight_lang) {
|
||||
var $highlight_lang = $('<div class="code_lang"></div>')
|
||||
$('.highlight-tools').append($highlight_lang)
|
||||
var lang_name_index;
|
||||
var lang_name;
|
||||
$('figure').each(function () {
|
||||
lang_name_index = lang_name = $(this).attr('class').split(' ')[1];
|
||||
if (lang_name_index == 'js')
|
||||
lang_name = 'Javascript'
|
||||
if (lang_name_index == 'md')
|
||||
lang_name = 'Markdown'
|
||||
if (lang_name_index == 'plain')
|
||||
lang_name = 'Code'
|
||||
if (lang_name_index == 'py')
|
||||
lang_name = 'Python'
|
||||
|
||||
$(this).prev().find(".code_lang").text(lang_name)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
if (theme.highlight_copy) {
|
||||
var $copyIcon = $('<i class="fa fa-clipboard" aria-hidden="true"></i>')
|
||||
var $notice = $('<div class="copy-notice"></div>')
|
||||
$('.highlight-tools').append($notice)
|
||||
$('.highlight-tools').append($copyIcon)
|
||||
}
|
||||
|
||||
data.content = $.html();
|
||||
}, 100);
|
||||
@@ -1,49 +0,0 @@
|
||||
'use strict'
|
||||
hexo.extend.filter.register('after_post_render', data => {
|
||||
const theme = hexo.theme.config;
|
||||
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const $ = cheerio.load(data.content, { decodeEntities: false });
|
||||
|
||||
const images = $('img').not($('a>img'));
|
||||
|
||||
if (theme.fancybox.enable) {
|
||||
images.each((i, o) => {
|
||||
var lazyload_src = $(o).attr('src') ? $(o).attr('src') : $(o).attr("data-src")
|
||||
var alt = $(o).attr('alt')
|
||||
if (alt !== undefined) {
|
||||
$(o).attr('title', alt)
|
||||
}
|
||||
var $a = $(
|
||||
'<a href="' +
|
||||
lazyload_src +
|
||||
'" data-fancybox="group" data-caption="' +
|
||||
$(o).attr('alt') +
|
||||
'" class="fancybox"></a>'
|
||||
)
|
||||
$(o).wrap($a)
|
||||
});
|
||||
|
||||
}
|
||||
if (theme.medium_zoom.enable) {
|
||||
var imgList = $(".justified-gallery img")
|
||||
if (imgList.length) {
|
||||
imgList.each((i, o) => {
|
||||
var $a = $('<div></div>')
|
||||
$(o).wrap($a)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (!theme.medium_zoom.enable && !theme.fancybox.enable) {
|
||||
var imgList = $(".justified-gallery > p >img")
|
||||
if (imgList.length) {
|
||||
imgList.each((i, o) => {
|
||||
$(o).wrap('<div></div>')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
data.content = $.html();
|
||||
}, 100);
|
||||
@@ -1,25 +0,0 @@
|
||||
'use strict';
|
||||
const url_for = require('hexo-util').url_for.bind(hexo);
|
||||
|
||||
hexo.extend.filter.register('after_post_render', data => {
|
||||
var theme = hexo.theme.config;
|
||||
var bg = theme.lodding_bg.post;
|
||||
if (!theme.lazyload.enable) return;
|
||||
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const $ = cheerio.load(data.content, {decodeEntities: false});
|
||||
const images = $('img').not($('.justified-gallery img'));
|
||||
if (!images.length) return;
|
||||
|
||||
images.each((i, o) => {
|
||||
let src = $(o).attr('src');
|
||||
$(o).attr('data-src', src).removeAttr('src');
|
||||
if (bg){
|
||||
$(o).attr('src',url_for(bg))
|
||||
}
|
||||
$(o).addClass('lazyload');
|
||||
});
|
||||
|
||||
data.content = $.html();
|
||||
}, 100);
|
||||
@@ -1,18 +0,0 @@
|
||||
hexo.extend.filter.register('before_post_render', function(data){
|
||||
data.cover = data.cover || random_cover()
|
||||
return data;
|
||||
});
|
||||
|
||||
var random_cover = function () {
|
||||
var cover;
|
||||
var num;
|
||||
if (!Array.isArray(hexo.theme.config.default_cover)) {
|
||||
cover = hexo.theme.config.default_cover
|
||||
return cover
|
||||
} else {
|
||||
num = Math.floor(Math.random() * (hexo.theme.config.default_cover.length));
|
||||
cover = hexo.theme.config.default_cover[num];
|
||||
return cover
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
const url_for = require('hexo-util').url_for.bind(hexo);
|
||||
|
||||
function gallery(args, content) {
|
||||
return `<div class="justified-gallery">${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function galleryGroup(args){
|
||||
const name = args[0]
|
||||
const desrc = args[1]
|
||||
const url = url_for(args[2])
|
||||
const img = url_for(args[3])
|
||||
|
||||
return `
|
||||
<figure class="gallery-group">
|
||||
<img class="gallery-group-img" src='${img}'>
|
||||
<figcaption>
|
||||
<div class="gallery-group-name">${name}</div>
|
||||
<p>${desrc}</p>
|
||||
<a href='${url}'></a>
|
||||
</figcaption>
|
||||
</figure>
|
||||
`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('gallery', gallery, {ends: true});
|
||||
hexo.extend.tag.register('galleryGroup', galleryGroup);
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
/**
|
||||
* {% hideInline content,display,bg,color %}
|
||||
* content不能包含當引號,可用 '
|
||||
*/
|
||||
function hideInline(args) {
|
||||
args = args.join(' ').split(',')
|
||||
let content = args[0].trim()
|
||||
let display = args[1] || 'Click'
|
||||
let bg = args[2] ==='' || typeof args[2] ==='undefined' ? '' : `background-color:${args[2]}`
|
||||
let color = args[3] || '#fff'
|
||||
return `<span class="hide-inline"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display}
|
||||
</a><span class="hide-content">${content}</span></span>`
|
||||
}
|
||||
|
||||
/**
|
||||
* {% hideBlock display,bg,color %}
|
||||
* content
|
||||
* {% endhideBlock %}
|
||||
*/
|
||||
function hideBlock(args,content) {
|
||||
args = args.join(' ').split(',')
|
||||
let display = args[0] || 'Click'
|
||||
let bg = args[1] ==='' || typeof args[2] ==='undefined' ? '' : `background-color:${args[2]}`
|
||||
let color = args[2] || '#fff'
|
||||
|
||||
return `<div class="hide-block"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display}
|
||||
</a><span class="hide-content">${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}</span></div>`
|
||||
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('hideInline', hideInline);
|
||||
hexo.extend.tag.register('hideBlock', hideBlock, {ends: true});
|
||||
@@ -0,0 +1,7 @@
|
||||
function mermaid(args, content) {
|
||||
return `<div class="mermaid">
|
||||
${content}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('mermaid', mermaid, {ends: true});
|
||||
@@ -1,8 +0,0 @@
|
||||
hexo.extend.helper.register('url_check', function (p) {
|
||||
|
||||
let src = p ;
|
||||
let reg = /^https?/ig;
|
||||
return reg.test(src)
|
||||
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user