From 6cdd19e07fdb88037143a89cdaea8e0ce5e52768 Mon Sep 17 00:00:00 2001 From: "hwy0127@gmail.com" Date: Sun, 11 Aug 2019 19:57:09 +0800 Subject: [PATCH] =?UTF-8?q?1.=20Feature:=20=E5=8F=AF=E9=97=9C=E9=96=89?= =?UTF-8?q?=E5=9C=96=E7=89=87=E6=87=B6=E5=8A=A0=E8=BC=89=202.=20Feature:?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E9=A0=81=E9=9D=A2=E6=8E=92=E7=89=88?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E9=81=B8=E6=93=87=E6=8A=8A=E5=8F=B3=E9=82=8A?= =?UTF-8?q?=E6=AC=84=E6=94=BE=E5=9C=A8=E5=B7=A6=E9=82=8A=203.=20Feature:?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=20Note=20(Bootstrap=20Callout)=20(?= =?UTF-8?q?=E7=A7=BB=E6=A4=8D=E6=96=BCnext=E4=B8=BB=E9=A1=8C)=204.=20Featu?= =?UTF-8?q?re:=20=E6=89=8B=E6=A9=9F=E4=B8=8A=E8=83=BD=E5=A4=A0=E6=9F=A5?= =?UTF-8?q?=E7=9C=8BTOC=205.=20Feature:=20=E5=A2=9E=E5=8A=A0=E7=9B=B4?= =?UTF-8?q?=E9=81=94=E8=A9=95=E8=AB=96=E6=8C=89=E9=88=95=206.=20Fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=BE=A9post=E9=A0=81=E5=9C=A8=E5=AF=AC=E5=BA=A61024p?= =?UTF-8?q?x=E4=B8=8B=E7=9A=84=E9=A1=AF=E7=A4=BAbug=207.=20Fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=BE=A9=E4=BB=A3=E7=A2=BC=E6=A1=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E8=AA=9E=E8=A8=80=E6=B2=92=E6=9C=89=E9=A1=AF=E7=A4=BA=E6=AD=A3?= =?UTF-8?q?=E7=A2=BA=E7=9A=84=E4=BB=A3=E7=A2=BC=E8=AA=9E=E8=A8=80=208.=20F?= =?UTF-8?q?ix:=20=E4=BF=AE=E5=BE=A9=E8=A8=AD=E7=BD=AE=E8=A3=8F=E6=8A=8ADis?= =?UTF-8?q?qus=E8=A8=BB=E9=87=8B=E6=8E=89=E7=84=A1=E6=B3=95=E9=81=8B?= =?UTF-8?q?=E8=A1=8C=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 26 +- layout/flink.pug | 5 +- layout/includes/additional-js.pug | 6 + layout/includes/comments/disqus.pug | 2 +- layout/includes/comments/index.pug | 12 +- layout/includes/header.pug | 2 +- layout/includes/layout.pug | 6 +- layout/includes/pagination.pug | 23 +- layout/includes/post-bottom.pug | 8 + layout/includes/recent-posts.pug | 21 +- layout/includes/reward.pug | 56 +---- layout/includes/widget/card_author.pug | 2 +- layout/includes/widget/card_recent_post.pug | 10 +- scripts/note.js | 15 ++ scripts/post-lazyload.js | 20 ++ scripts/related_post.js | 6 +- source/css/_global/index.styl | 4 +- source/css/_highlight/highlight.styl | 22 +- source/css/_layout/aside.styl | 11 +- source/css/_layout/head.styl | 3 - source/css/_layout/nightshift.styl | 16 +- source/css/_layout/note.styl | 256 ++++++++++++++++++++ source/css/_layout/pagination.styl | 1 - source/css/_layout/post.styl | 2 +- source/css/_layout/post_bottom.styl | 57 +++++ source/css/_layout/z-other.styl | 40 +-- source/css/var.styl | 70 ++++++ source/js/main.js | 102 +++++--- 28 files changed, 631 insertions(+), 173 deletions(-) create mode 100644 layout/includes/post-bottom.pug create mode 100644 scripts/note.js create mode 100644 scripts/post-lazyload.js create mode 100644 source/css/_layout/note.styl create mode 100644 source/css/_layout/post_bottom.styl diff --git a/_config.yml b/_config.yml index 7d13217..f3253fa 100644 --- a/_config.yml +++ b/_config.yml @@ -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 # --------------- @@ -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 @@ -417,4 +416,23 @@ baidu_push: #https://instant.page/ #prefetch預加載 instantpage: - enable: true \ No newline at end of file + 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 \ No newline at end of file diff --git a/layout/flink.pug b/layout/flink.pug index 4b39f62..de257c7 100644 --- a/layout/flink.pug +++ b/layout/flink.pug @@ -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
div(class="md-links-des")=item.descr diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index a9020e2..00153b0 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -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/instant.page@1.2.2/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(); diff --git a/layout/includes/comments/disqus.pug b/layout/includes/comments/disqus.pug index a1bd151..1e0c01c 100644 --- a/layout/includes/comments/disqus.pug +++ b/layout/includes/comments/disqus.pug @@ -1,4 +1,4 @@ -if theme.disqus.enable +if theme.disqus && theme.disqus.enable #disqus_thread script. var unused = null; diff --git a/layout/includes/comments/index.pug b/layout/includes/comments/index.pug index 6a8bedd..bdb057d 100644 --- a/layout/includes/comments/index.pug +++ b/layout/includes/comments/index.pug @@ -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 \ No newline at end of file diff --git a/layout/includes/header.pug b/layout/includes/header.pug index de2d802..bc88f99 100644 --- a/layout/includes/header.pug +++ b/layout/includes/header.pug @@ -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 diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index 765e99d..3d3ded0 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -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)) diff --git a/layout/includes/pagination.pug b/layout/includes/pagination.pug index bfd5628..a0ba097 100644 --- a/layout/includes/pagination.pug +++ b/layout/includes/pagination.pug @@ -16,7 +16,11 @@ 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 @@ -24,19 +28,23 @@ 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 @@ -44,7 +52,10 @@ 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 diff --git a/layout/includes/post-bottom.pug b/layout/includes/post-bottom.pug new file mode 100644 index 0000000..6d8427b --- /dev/null +++ b/layout/includes/post-bottom.pug @@ -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"}) diff --git a/layout/includes/recent-posts.pug b/layout/includes/recent-posts.pug index e13e3cd..77d66fb 100644 --- a/layout/includes/recent-posts.pug +++ b/layout/includes/recent-posts.pug @@ -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) diff --git a/layout/includes/reward.pug b/layout/includes/reward.pug index 57d26ba..f8c7b7e 100644 --- a/layout/includes/reward.pug +++ b/layout/includes/reward.pug @@ -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 - - - diff --git a/layout/includes/widget/card_author.pug b/layout/includes/widget/card_author.pug index 9f93e71..b31fff2 100644 --- a/layout/includes/widget/card_author.pug +++ b/layout/includes/widget/card_author.pug @@ -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 diff --git a/layout/includes/widget/card_recent_post.pug b/layout/includes/widget/card_recent_post.pug index f07e9f0..671187c 100644 --- a/layout/includes/widget/card_recent_post.pug +++ b/layout/includes/widget/card_recent_post.pug @@ -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) diff --git a/scripts/note.js b/scripts/note.js new file mode 100644 index 0000000..61acd3b --- /dev/null +++ b/scripts/note.js @@ -0,0 +1,15 @@ +/** + * note.js + * transplant from hexo-theme-next + */ + +'use strict'; + +function postNote(args, content) { + return `
+ ${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')} +
`; +} + +hexo.extend.tag.register('note', postNote, {ends: true}); +hexo.extend.tag.register('subnote', postNote, {ends: true}); \ No newline at end of file diff --git a/scripts/post-lazyload.js b/scripts/post-lazyload.js new file mode 100644 index 0000000..d738fe7 --- /dev/null +++ b/scripts/post-lazyload.js @@ -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); \ No newline at end of file diff --git a/scripts/related_post.js b/scripts/related_post.js index 2861861..1d7f514 100644 --- a/scripts/related_post.js +++ b/scripts/related_post.js @@ -34,10 +34,12 @@ 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 += '