317 字1 分钟
Next 主题添加公告栏
字面意思,给 Next 主题添加个公告栏,不过由于 Next 侧边栏只在宽屏上显示,在手机上是看不到的。
适用范围:Next·Pisces 主题
打开 hexo/themes/next/layout/_macro/sidebar.njk,在 </aside> 与最后一个 {%- endif %} 之间添加以下代码
{%- if theme.related_posts.enable %}
{%- if theme.pjax %}
<div class="pjax">
{%- endif %}
{%- if page.related_posts and page.related_posts.length > 0 %}
<div class="sidebar-inner sidebar-post-related">
<div class="animated">
{{ partial('_partials/post/post-related.njk') }}
</div>
</div>
{%- endif %}
{%- if theme.pjax %}
</div>
{%- endif %}
{%- endif %}
+ {%- if theme.notice.enable %}
+ {%- if theme.pjax %}
+ <div class="pjax">
+ {%- endif %}
+ {%- if theme.notice.content.length > 0 %}
+ <div class="sidebar-inner notice" style="padding: 18px;">
+ <div class="notice-title" style="font-size: 1.2em;text-align: left;">
+ <i class="fa-solid fa-bullhorn"></i>
+ <span style="margin-left: 6px;">公告</span>
+ </div>
+ <div class="notice-content" style="text-align: justify;">
+ {{ theme.notice.content }}
+ </div>
+ </div>
+ {%- endif %}
+ {%- if theme.pjax %}
+ </div>
+ {%- endif %}
+ {%- endif %}
</aside>
{% endmacro %}
以下为方便复制的版本
{%- if theme.notice.enable %}
{%- if theme.pjax %}
<div class="pjax">
{%- endif %}
{%- if theme.notice.content.length > 0 %}
<div class="sidebar-inner notice" style="padding: 18px;">
<div class="notice-title" style="font-size: 1.2em;text-align: left;">
<i class="fa-solid fa-bullhorn"></i>
<span style="margin-left: 6px;">公告</span>
</div>
<div class="notice-content" style="text-align: justify;">
{{ theme.notice.content }}
</div>
</div>
{%- endif %}
{%- if theme.pjax %}
</div>
{%- endif %}
{%- endif %}
然后在主题配置 _config.next.yml 中添加以下内容
notice:
enable: true
content: #公告内容
样式写的很简单,如有需要请自行更改。
- 作者
- 浮生若梦
- 发布于
- 2024-04-20
- 许可协议
- CC BY-NC-SA 4.0

