缘由
由于之前控制指定单页的侧边栏显示,部分page页面可以显示侧边栏,这就让带有欢迎功能的公告栏在多个page页显示,不清楚会不会持续加载txmap.js相关代码。同时由于自己的pjax还不会适配,会出现page页的公告栏经常只有一个框而没有欢迎样式,需要刷新才能显示的bug,为了美观就只在首页显示公告栏。
代码
在主题配置文件_config.butterfly.yml中侧边栏announcement保持为true:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
aside: enable: true hide: false button: true mobile: false position: right display: archive: true tag: true category: true card_author: enable: true description: 采菊东篱下🍂 button: enable: true icon: fab fa-github text: 关注我 link: https://github.com/aligu99 card_announcement: enable: true content: ...
|
使用 is_home() 函数来判断当前页面是否是首页,只有当 is_home() 返回 true 时才渲染 card_announcement。
修改[BlogRoot]
\themes\butterfly\layout\includes\widget\index.pug文件,增加if is_home()
判断逻辑:
1 2 3 4 5 6 7
| else //- page !=partial('includes/widget/card_author', {}, {cache: true}) - !=partial('includes/widget/card_announcement', {}, {cache: true}) + // 仅在首页显示公告栏 + if is_home() + !=partial('includes/widget/card_announcement', {}, {cache: true})
|
ps:由于魔改方式不同,以下是index.pug的完整代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #aside-content.aside-content if is_post() - const tocStyle = page.toc_style_simple - const tocStyleVal = tocStyle === true || tocStyle === false ? tocStyle : theme.toc.style_simple if showToc && tocStyleVal .sticky_layout include ./card_post_toc.pug else !=partial('includes/widget/card_author', {}, {cache: true}) !=partial('includes/widget/card_top_self', {}, {cache: true}) .sticky_layout if showToc include ./card_post_toc.pug if page.series include ./card_post_series.pug !=partial('includes/widget/card_recent_post', {}, {cache: true}) !=partial('includes/widget/card_ad', {}, {cache: true}) else !=partial('includes/widget/card_author', {}, {cache: true}) !=partial('includes/widget/card_announcement', {}, {cache: true}) !=partial('includes/widget/card_top_self', {}, {cache: true})
.sticky_layout if showToc include ./card_post_toc.pug !=partial('includes/widget/card_recent_post', {}, {cache: true}) !=partial('includes/widget/card_ad', {}, {cache: true}) !=partial('includes/widget/card_newest_comment', {}, {cache: true}) !=partial('includes/widget/card_categories', {}, {cache: true}) !=partial('includes/widget/card_tags', {}, {cache: true}) !=partial('includes/widget/card_archives', {}, {cache: true}) !=partial('includes/widget/card_webinfo', {}, {cache: true}) !=partial('includes/widget/card_bottom_self', {}, {cache: true})
|