From 475d181aac9e3f1e48c7057683cb411b8f71a9bd Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 30 Sep 2023 04:46:40 +0800 Subject: [PATCH] refactor: optimize the basic layouts --- _layouts/default.html | 31 +++--- _layouts/home.html | 15 +-- _layouts/page.html | 12 +-- _layouts/post.html | 212 +++++++++++++++++++-------------------- _sass/addon/commons.scss | 13 +-- 5 files changed, 134 insertions(+), 149 deletions(-) diff --git a/_layouts/default.html b/_layouts/default.html index 9f83e81..f938a94 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -8,14 +8,8 @@ layout: compress {% include lang.html %} -{% capture prefer_mode %} - {% if site.theme_mode %} - data-mode="{{ site.theme_mode }}" - {% endif %} -{% endcapture %} - -{% if layout.tail_includes %} - {% assign has_tail = true %} +{% if site.theme_mode %} + {% capture prefer_mode %}data-mode="{{ site.theme_mode }}"{% endcapture %} {% endif %} @@ -30,11 +24,12 @@ layout: compress {% include topbar.html lang=lang %}
-
- {{ content }} +
+ {% if layout.refactor or layout.layout == 'default' %} + {% include refactor-content.html content=content lang=lang %} + {% else %} + {{ content }} + {% endif %}
@@ -54,12 +49,10 @@ layout: compress
- {% if has_tail %} - {% for _include in layout.tail_includes %} - {% assign _include_path = _include | append: '.html' %} - {% include {{ _include_path }} lang=lang %} - {% endfor %} - {% endif %} + {% for _include in layout.tail_includes %} + {% assign _include_path = _include | append: '.html' %} + {% include {{ _include_path }} lang=lang %} + {% endfor %} {% include_cached footer.html lang=lang %}
diff --git a/_layouts/home.html b/_layouts/home.html index b5b6f7f..4cf4c1d 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -1,5 +1,6 @@ --- layout: default +refactor: true --- {% include lang.html %} @@ -39,8 +40,7 @@ layout: default {% endfor %} {% endif %} -{% capture _content %} -
+
{% for post in posts %}
-{% endcapture %} - -{% include refactor-content.html content=_content lang=lang %} {% if paginator.total_pages > 1 %} {% include post-paginator.html %} diff --git a/_layouts/page.html b/_layouts/page.html index cd04bdc..32d6582 100644 --- a/_layouts/page.html +++ b/_layouts/page.html @@ -4,14 +4,6 @@ layout: default {% include lang.html %} -{% capture _content %} - {% if layout.refactor or page.layout == 'page' %} - {% include refactor-content.html content=content lang=lang %} - {% else %} - {{ content }} - {% endif %} -{% endcapture %} -
{% if page.layout == 'page' or page.collection == 'tabs' %} {% assign tab_key = page.title | downcase %} @@ -20,9 +12,9 @@ layout: default {{ title }}
- {{ _content }} + {{ content }}
{% else %} - {{ _content }} + {{ content }} {% endif %}
diff --git a/_layouts/post.html b/_layouts/post.html index 0b99d49..4dd9efc 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -1,5 +1,5 @@ --- -layout: page +layout: default refactor: true panel_includes: - toc @@ -11,125 +11,125 @@ tail_includes: {% include lang.html %} -
-

{{ page.title }}

+
+
+

{{ page.title }}

-
+ +
+ {{ content }} +
+ +
+ + {% if page.categories.size > 0 %} + {% endif %} -
- - - {% if page.author %} - {% assign authors = page.author %} - {% elsif page.authors %} - {% assign authors = page.authors %} - {% endif %} + + {% if page.tags.size > 0 %} + + {% endif %} - {{ site.data.locales[lang].post.written_by }} - - - {% if authors %} - {% for author in authors %} - {{ site.data.authors[author].name }} - {% unless forloop.last %}{{ ', ' }}{% endunless %} - {% endfor %} - {% else %} - {{ site.social.name }} - {% endif %} - - - - - {% include read-time.html content=content prompt=true lang=lang %} -
- -
- -
- -
- {{ content }} -
- -
- - {% if page.categories.size > 0 %} - - {% endif %} - - - {% if page.tags.size > 0 %} - - {% endif %} - -
-
- {% if site.data.locales[lang].copyright.license.template %} - {% capture _replacement %} +
+
+ {% if site.data.locales[lang].copyright.license.template %} + {% capture _replacement %} {{ site.data.locales[lang].copyright.license.name }} {% endcapture %} - {{ site.data.locales[lang].copyright.license.template | replace: ':LICENSE_NAME', _replacement }} - {% endif %} -
+ {{ site.data.locales[lang].copyright.license.template | replace: ':LICENSE_NAME', _replacement }} + {% endif %} +
- {% include post-sharing.html lang=lang %} + {% include post-sharing.html lang=lang %} +
+
- -
- + + diff --git a/_sass/addon/commons.scss b/_sass/addon/commons.scss index c80d412..d54e76a 100644 --- a/_sass/addon/commons.scss +++ b/_sass/addon/commons.scss @@ -148,7 +148,6 @@ footer { } p { - line-height: 1.75; text-align: center; margin-bottom: 0; } @@ -820,9 +819,11 @@ $btn-mb: 0.5rem; padding-right: 1rem; margin-bottom: 1.5rem; + $btn-size: 1.75rem; + %button { - width: 1.75rem; - height: 1.75rem; + width: $btn-size; + height: $btn-size; margin-bottom: $btn-mb; // multi line gap border-radius: 50%; color: var(--sidebar-btn-color); @@ -849,7 +850,7 @@ $btn-mb: 0.5rem; } i { - line-height: 1.75rem; + line-height: $btn-size; } .mode-toggle { @@ -1129,10 +1130,6 @@ search { > :not(script) { margin-top: 3rem; } - - > :only-child { - margin-top: 0; - } } /* --- button back-to-top --- */