Skip to content

Commit

Permalink
1. Feature: 可關閉圖片懶加載
Browse files Browse the repository at this point in the history
2. Feature: 增加頁面排版,可選擇把右邊欄放在左邊
3. Feature: 增加 Note (Bootstrap Callout) (移植於next主題)
4. Feature: 手機上能夠查看TOC
5. Feature: 增加直達評論按鈕
6. Fix: 修復post頁在寬度1024px下的顯示bug
7. Fix: 修復代碼框部分語言沒有顯示正確的代碼語言
8. Fix: 修復設置裏把Disqus註釋掉無法運行的bug
  • Loading branch information
jerryc127 committed Aug 11, 2019
1 parent 49a9995 commit 6cdd19e
Show file tree
Hide file tree
Showing 28 changed files with 630 additions and 172 deletions.
26 changes: 22 additions & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ cdn:
jquery: https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js
fancybox: https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js
js-cookies: https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js
lozy: https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js


# Post info settings
# ---------------
Expand Down Expand Up @@ -376,10 +374,11 @@ hr:
subtitle:
enable: true
sub1: 今日事,今日畢
sub2: Never put off till tomorrow what you can do today
sub2: Never put off till tomorrow what you can do today #如果有符號 ' ,記得前面加上 \

#側邊欄顯示設置
aside:
position: right # left or right
card_author: true
card_announcement: true
card_recent_post: true
Expand Down Expand Up @@ -417,4 +416,23 @@ baidu_push:
#https://instant.page/
#prefetch預加載
instantpage:
enable: true
enable: true

note:
# Note tag style values:
# - simple bs-callout old alert style. Default.
# - modern bs-callout new (v2-v3) alert style.
# - flat flat callout style with background, like on Mozilla or StackOverflow.
# - disabled disable all CSS styles import of note tag.
style: simple
icons: true
border_radius: 3
# Offset lighter of background in % for modern and flat styles (modern: -12 | 12; flat: -18 | 6).
# Offset also applied to label tag variables. This option can work with disabled note tag.
light_bg_offset: 0


#圖片懶加載
lazyload:
enable: true
script: https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js
5 changes: 4 additions & 1 deletion layout/flink.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
each item in i.link_list
li.md-links-item
a(href=item.link title=item.name target="_blank")
img.lozad(data-src=item.avatar onerror=`onerror=null;src='${theme.lodding_bg.flink}'` height="72px")
if theme.lazyload.enable
img.lozad(data-src=item.avatar onerror=`onerror=null;src='${theme.lodding_bg.flink}'` height="72px")
else
img(src=item.avatar onerror=`onerror=null;src='${theme.lodding_bg.flink}'` height="72px")
div(class="md-links-title")= item.name
<br/>
div(class="md-links-des")=item.descr
Expand Down
6 changes: 6 additions & 0 deletions layout/includes/additional-js.pug
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv

if theme.instantpage.enable
script(src="https://cdn.jsdelivr.net/npm/[email protected]/instantpage.min.js" type="module")

if theme.lazyload.enable
script(src=url_for(theme.lazyload.script))
script.
const observer = lozad(); // lazy loads elements with default selector as '.lozad'
observer.observe();
2 changes: 1 addition & 1 deletion layout/includes/comments/disqus.pug
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if theme.disqus.enable
if theme.disqus && theme.disqus.enable
#disqus_thread
script.
var unused = null;
Expand Down
12 changes: 6 additions & 6 deletions layout/includes/comments/index.pug
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
if theme.disqus.enable
if theme.disqus && theme.disqus.enable
hr
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
span= _p('comment')
span= ' ' + _p('comment')
include ./disqus.pug
else if theme.laibili && theme.laibili.enable
hr
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
span= _p('comment')
span= ' ' + _p('comment')
include ./laibili.pug
else if theme.gitment && theme.gitment.enable
hr
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
span= _p('comment')
span= ' ' + _p('comment')
include ./gitment.pug
else if theme.gitalk && theme.gitalk.enable
hr
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
span= _p('comment')
span= ' ' + _p('comment')
include ./gitalk.pug
else if theme.valine && theme.valine.enable
hr
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
span= _p('comment')
span= ' ' + _p('comment')
include ./valine.pug
2 changes: 1 addition & 1 deletion layout/includes/header.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

span.pull-right.menus
.mobile_author_icon
img.lozad(data-src=theme.avatar || url_for('/img/avatar.png') onerror=`onerror=null;src='${theme.lodding_bg.flink}'`)
img.lozad(src=theme.avatar || url_for('/img/avatar.png') onerror=`onerror=null;src='${theme.lodding_bg.flink}'`)
.mobile_author-info__description= config.description
hr
.menus_item
Expand Down
6 changes: 2 additions & 4 deletions layout/includes/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ html(lang=config.language)
div!= body
else
block content
//- - var top_img = page.top_img || theme.post_meta.top_img || theme.top_img || config.top_img || true
//- - var bg_img = top_img !== true ? `background-image: url(${top_img})` : ''
//- - var footer_bg_class= bg_img ? 'footer-bg' : ''
//- footer(style=bg_img class=footer_bg_class)
footer
include ./footer.pug
i.fa.fa-arrow-up#go-up(aria-hidden="true")
include ./rightside.pug
if (is_post())
include ./post-bottom.pug
each item in theme.cdn.js
if item !== undefined
script(src=url_for(item))
Expand Down
23 changes: 17 additions & 6 deletions layout/includes/pagination.pug
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,46 @@ else
.prev-post.pull-left
- var pagination_cover = page.prev.cover || random_cover()
a(href=url_for(page.prev.path))
img.prev_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` )
if theme.lazyload.enable
img.prev_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` )
else
img.prev_cover(src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` )

.label=_p('pagination.prev')
.prev_info
span=page.prev.title
else
.prev-post.pull-full
- var pagination_cover = page.prev.cover || random_cover()
a(href=url_for(page.prev.path))
img.prev_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
if theme.lazyload.enable
img.prev_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.prev_cover(src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
.label=_p('pagination.prev')
.prev_info
span=page.prev.title



if(page.next)
if(page.prev)
.next-post.pull-right
- var pagination_cover = page.next.cover || random_cover()
a(href=url_for(page.next.path))
img.next_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
if theme.lazyload.enable
img.next_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.next_cover(src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
.label=_p('pagination.next')
.next_info
span=page.next.title
else
.next-post.pull-full
- var pagination_cover = page.next.cover || random_cover()
a(href=url_for(page.next.path))
img.next_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
if theme.lazyload.enable
img.next_cover.lozad(data-src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.next_cover(src=`${pagination_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
.label=_p('pagination.next')
.next_info
span=page.next.title
Expand Down
8 changes: 8 additions & 0 deletions layout/includes/post-bottom.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#post_bottom
#post_bottom_items
a#to_comment(href="#post-comment")
i.scroll_to_comment.fa.fa-comments
i#mobile_toc.fa.fa-list
#toc_mobile
.toc_mobile_headline= _p('sidebar.catalog')
!=toc(page.content,{"class":"toc_mobile_items"})
21 changes: 16 additions & 5 deletions layout/includes/recent-posts.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@ each article , index in page.posts.data
- var post_cover = article.cover
- var default_post_cover = random_cover()
if (post_cover)
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
if theme.lazyload.enable
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.post_bg(src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
if theme.lazyload.enable
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.post_bg(src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
.post_cover.is_right
a(href=url_for(link) title=article.title || _p('no_title'))
- var post_cover = article.cover
- var default_post_cover = random_cover()
if (post_cover)
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
if theme.lazyload.enable
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.post_bg(src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)

if theme.lazyload.enable
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
else
img.post_bg(src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
.recent-post-info
a.article-title(href=url_for(link) title= article.title || _p('no_title'))= article.title || _p('no_title')
if (article.top)
Expand Down
56 changes: 1 addition & 55 deletions layout/includes/reward.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,6 @@
ul.reward-all
each item in theme.reward.QR_code
li.reward-item
img.lozad.post-qr-code__img(data-src=(item.itemlist||item).img)
img.lozad.post-qr-code__img(src=(item.itemlist||item).img)
.post-qr-code__desc=(item.itemlist||item).text



//- donate-share样式1
//- .post-reward-share
//- .post-reward
//- a.reward-buttom
//- i.fa.fa-qrcode
//- = ' ' + _p('donate')
//- .reward-main
//- ul.reward-all
//- each item in theme.QR_code
//- li.reward-item
//- img.lozad.post-qr-code__img(data-src=(item.itemlist||item).img)
//- .post-qr-code__desc=(item.itemlist||item).text
//- .post-share
//- include share/index.pug
//- a.share-buttom
//- i.fa.fa-share-alt
//- = ' ' + _p('share')
//- donate-share样式1
//- #social
//- .social-main
//- span.social-donate
//- a#social-donate
//- i.fa.fa-qrcode
//- = _p('donate')
//- .circle
//- .circle-empty
//- span
//- span.circle_item
//- a(style="cursor:pointer")
//- .social-sharebutton
//- span.share-s
//- a(href="javascript:void(0)" id="share-s" title=_p('share'))
//- i.fa.fa-share-alt
//- = _p('share')
//- include share/index.pug
//- if (theme.QR_code)
//- if (theme.QR_code.length > 0)
//- .post-qr-code
//- each item in theme.QR_code
//- .post-qr-code-item
//- img.lozad.post-qr-code__img(data-src=(item.itemlist||item).img)
//- .post-qr-code__desc=(item.itemlist||item).text
2 changes: 1 addition & 1 deletion layout/includes/widget/card_author.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.card-content
.post_data
.data-item.text-center
img.lozad(data-src=theme.avatar || url_for('/img/avatar.png') onerror=`onerror=null;src='${theme.lodding_bg.flink}'`)
img.lozad(src=theme.avatar || url_for('/img/avatar.png') onerror=`onerror=null;src='${theme.lodding_bg.flink}'`)
p.author-info__name.text-center= config.author
p.author-info__description.text-center= config.description

Expand Down
10 changes: 8 additions & 2 deletions layout/includes/widget/card_recent_post.pug
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
- var default_post_cover = random_cover()
.aside_post_cover
if (post_cover)
img.aside_post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
if theme.lazyload.enable
img.aside_post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
else
img.aside_post_bg(src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
else
img.aside_post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
if theme.lazyload.enable
img.aside_post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
else
img.aside_post_bg(src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
div#aside_title
.aside_post_title(href=url_for(link) title=article.title || _p('no_title'))= article.title || _p('no_title')
if (theme.post_meta.date_type)
Expand Down
15 changes: 15 additions & 0 deletions scripts/note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* note.js
* transplant from hexo-theme-next
*/

'use strict';

function postNote(args, content) {
return `<div class="note ${args.join(' ')}">
${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
</div>`;
}

hexo.extend.tag.register('note', postNote, {ends: true});
hexo.extend.tag.register('subnote', postNote, {ends: true});
20 changes: 20 additions & 0 deletions scripts/post-lazyload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
let cheerio;
hexo.extend.filter.register('after_post_render', data => {
var theme = hexo.theme.config;
if (!theme.lazyload.enable) return;

if (!cheerio) cheerio = require('cheerio');

const $ = cheerio.load(data.content, {decodeEntities: false});
const images = $('img');
if (!images.length) return;

images.each((i, o) => {
let src = $(o).attr('src');
$(o).attr('data-src', src).removeAttr('src');
$(o).addClass('lozad');
});

data.content = $.html();
}, 0);
6 changes: 4 additions & 2 deletions scripts/related_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
}

relatedPosts = relatedPosts.sort(compare('weight'));
var lazy_src = hexo.theme.config.lazyload.enable ? lazy_src = 'data-src' : lazy_src = 'src'
var lazy_class = hexo.theme.config.lazyload.enable ? lazy_class = 'lozad' : lazy_class = ''

if (relatedPosts.length > 0) {
result += '<div class="relatedPosts">'
result += '<div class="relatedPosts_headline"><i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i><span>' + headline_lang + '</span></div>'
result += '<div class="relatedPosts_headline"><i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i><span>' + ' ' + headline_lang + '</span></div>'
result += '<div class="relatedPosts_list">'

for (var i = 0; i < Math.min(relatedPosts.length, limit_num); i++) {

var cover = relatedPosts[i].cover || random_cover()

result += '<div class="relatedPosts_item"><a href="' + hexo.theme.config.rootConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title + '">';
result += '<img class="relatedPosts_cover lozad" data-src="' + cover + '">';
result += '<img class="relatedPosts_cover '+ lazy_class + '"' + lazy_src + '="' + cover + '">';
result += '<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>';
result += '</a></div>'
};
Expand Down
Loading

0 comments on commit 6cdd19e

Please sign in to comment.