Skip to content

Commit

Permalink
[Features] Add submenu support for posts and optimize related codes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhonger committed Mar 27, 2024
1 parent 6c6163a commit ea12ea0
Show file tree
Hide file tree
Showing 17 changed files with 536 additions and 262 deletions.
11 changes: 11 additions & 0 deletions _data/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- id: 'begin'
name: 'H2O-ac 主题入门系列'
articles:
- name: '快速入门'
url: '/tech/new-theme-h2o-ac.html'
- name: '快速入门'
url: '/tech/new-theme-h2o-ac.html'
- name: '快速入门'
url: '/tech/new-theme-h2o-ac.html'


51 changes: 29 additions & 22 deletions _includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,33 @@

<button id="accept-tos">{{ footer.tos.btn }}</button>
</div>
<button id="list" aria-label="Scroll back to top" class="mobile-list" type="button">
<svg class="icon list day" aria-hidden="true">
<use xlink:href="#icon-list-day"></use>
</svg>
<svg class="icon list night" aria-hidden="true">
<use xlink:href="#icon-list-night"></use>
</svg>
<svg class="icon exit day" aria-hidden="true">
<use xlink:href="#icon-exit-day"></use>
</svg>
<svg class="icon exit night" aria-hidden="true">
<use xlink:href="#icon-exit-night"></use>
</svg>
</button>
<button id="bttb" aria-label="Scroll back to top" class="bttb" type="button">
<svg class="icon up day" aria-hidden="true">
<use xlink:href="#icon-up-day"></use>
</svg>
<svg class="icon up night" aria-hidden="true">
<use xlink:href="#icon-up-night"></use>
</svg>
</button>

<section id="tools">
{% if page.submenu %}
<div class="tool collection">
<svg class="icon b1 active" aria-hidden="true">
<use xlink:href="#icon-submenu"></use>
</svg>
<svg class="icon b2" aria-hidden="true">
<use xlink:href="#icon-exit"></use>
</svg>
</div>
{% endif %}
{% if page.content contains 'h1' or page.content contains 'h2' or page.content contains 'h3' or page.content contains 'h4' or page.content contains 'h5' or page.content contains 'h6' and site.toc %}
<div class="tool toc">
<svg class="icon b1 active" aria-hidden="true">
<use xlink:href="#icon-toc"></use>
</svg>
<svg class="icon b2" aria-hidden="true">
<use xlink:href="#icon-exit"></use>
</svg>
</div>
{% endif %}
</section>
<section id="bttb" aria-label="Scroll back to top" class="bttb">
<div class="tool">
<svg class="icon top" aria-hidden="true">
<use xlink:href="#icon-top"></use>
</svg>
</div>
</section>
20 changes: 20 additions & 0 deletions _includes/submenu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% if page.submenu %}
<div class="submenu">
{% for collection in site.data.collections %}
{% if collection.id == page.submenu %}
<h4>
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-submenu"></use>
</svg>{{ collection.name }}
</h4>
<ul>
{% for article in collection.articles %}
<li><a href="{{ article.url | prepend: site.baseurl }}">{{ article.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
{% else %}
<div class="submenu hidden">
{% endif %}
</div>
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/line-numbers/prism-line-numbers.min.js"></script>
<script src="{{ "/assets/js/app.min.js" | prepend: site.baseurl }}"></script>
<script src="https://cdn.jsdelivr.net/npm/lazysizes@5.3.2/lazysizes.min.js" async></script>
<script src="https://at.alicdn.com/t/c/font_3046306_rifslacm9z.js"></script>
<script src="https://at.alicdn.com/t/c/font_3046306_9tox63bysiw.js"></script>
{% include waline.html %}
{% include analytics.html %}
{% include umami.html %}
Expand Down
62 changes: 7 additions & 55 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ <h2 class="post-subtitle">{{ page.subtitle }}</h2>
{% endif %}

{% assign copyright = post.copyright %}
{% if site.toc %}

<div class="container">
{% include submenu.html %}
<div class="contents">
<article class="markdown-body post">
{% if page.langs %}
Expand Down Expand Up @@ -162,64 +163,15 @@ <h2 class="post-subtitle">{{ page.subtitle }}</h2>
</div>
</article>
</div>
{% if page.content contains 'h1' or page.content contains 'h2' or page.content contains 'h3' or page.content contains 'h4' or page.content contains 'h5' or page.content contains 'h6' and site.toc %}
<div class="table-of-contents">
<h2>{{ post.outline }}</h2>
{% include toc.html html=content %}
{% else %}
<div class="table-of-contents hidden">
{% endif %}
</div>
</div>
{% else %}
<article class="markdown-body">
{% if page.langs %}
<p><b>{{ locales.langs }}</b>
{% assign langs = "zh-Hans, zh-Hant, en, ja" | split: ", " %}
{% assign langnames = "简中, 繁中, EN, 日本語" | split: ", " %}
{% if lang == site.default_lang %}
{% assign url = page.url %}
{% else %}
{% assign urls = page.url | split: '/' %}
{% assign url = "" %}
{% for u in urls offset:2 %}
{% assign url = url | append: "/" | append: u %}
{% endfor %}
{% endif %}
{% for l in page.langs %}
{% for i in (0..4) %}
{% if langs[i] == l %}
{% if l == page.lang %}
{{ langnames[i] }}
{% elsif l == site.default_lang %}
<a href="{{ url }}">{{ langnames[i] }}</a>
{% else %}
{% assign prefix = "/" | append: l %}
<a href="{{ url | prepend: prefix }}">{{ langnames[i] }}</a>
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
</p>
{% endif %}
{{ page.content }}
<div class="post-copyright">
{% assign copyright = post.copyright %}
<p>
<span>{{ copyright.statement.name }}:</span>
{{ copyright.statement.left }}
<a href="{{ site.url }}" class="cplink">{{ site.title }}</a>
{{ copyright.statement.middle }}
</p>
{% if site.cclicense %}
<p>
{{ copyright.statement.right1 }}
<a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" class="extlinks">CC BY-NC-SA 4.0</a>
{{ copyright.statement.right2 }}
</p>
{% endif %}
<p><span>{{ copyright.title }}:</span>《 {{ page.title }} 》</p>
<p><span>{{ copyright.link }}:</span><a href="{{ page.url | prepend: site.url }}" class="cplink">{{ page.url | prepend: site.url }}</a></p>
<p class="tips">{{ copyright.statement.outdate1 }} <span></span> {{ copyright.statement.outdate2 }}</p>
</div>
</article>
{% endif %}

{% if site.social-share %}
<div class="social-share-wrapper">
Expand Down Expand Up @@ -512,7 +464,7 @@ <h2>{{ post.outline }}</h2>
});
});
</script>
<script src="https://at.alicdn.com/t/c/font_3046306_rifslacm9z.js"></script>
<script src="https://at.alicdn.com/t/c/font_3046306_9tox63bysiw.js"></script>
{% include analytics.html %}
{% include umami.html %}
{% include busuanzi.html %}
Expand Down
1 change: 1 addition & 0 deletions _posts/2021-12-22-new-theme-h2o-ac.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tags:
- 学术
- 运维
pin: true
submenu: 'begin'
---

## 前言
Expand Down
Loading

0 comments on commit ea12ea0

Please sign in to comment.