Skip to content

Commit

Permalink
[Fix] Refactor _includes and _layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
zhonger committed Mar 29, 2024
1 parent ac57fc3 commit 98f71b9
Show file tree
Hide file tree
Showing 47 changed files with 599 additions and 740 deletions.
53 changes: 0 additions & 53 deletions _includes/comments.html

This file was deleted.

51 changes: 0 additions & 51 deletions _includes/head.html

This file was deleted.

File renamed without changes.
47 changes: 23 additions & 24 deletions _includes/post-head.html → _includes/layouts/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% if page.title %}{{ page.title }} - {{ site.title }}{% else %}{{ site.title }}{% endif %}</title>
<meta name="author" content="{{ site.author }}">
{% if layout.type == "post" %}
<meta name="description" content="{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}">
<meta name="keywords" content="{% if page.tags.size > 0 %}{% for tag in page.tags %}{{ tag }}{% if forloop.last == false %}, {% endif %}{% endfor %}{% endif %}">
<!-- Open Graph -->
<meta property="og:title" content="{% if page.title %}{{ page.title }} - {{ site.title }}{% else %}{{ site.title }}{% endif %}">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ page.url | prepend: site.url }}">
<meta property="og:baseurl" content="{{ site.baseurl }}">
<meta property="og:description" content="{{ site.description }}">
<meta property="og:site_name" content="{{ site.title }}">
<meta property="og:gray" content="{{ site.gray }}">
{% if page.next.url %}
<meta property="og:previous_url" content="{{ page.next.url | relative_url }}">
{% endif %}
{% if page.previous.url %}
<meta property="og:next_url" content="{{ page.previous.url | relative_url }}">
{% endif %}
{% else %}
<meta name="description" content="{{ site.description }}">
<meta name="keywords" content="{{ site.keyword }}">
{% endif %}
<meta property="post-date-format" content="{{ site.formats.time }}">
{% case site.formats.time %}
{% when 0 %}
Expand All @@ -28,6 +25,15 @@
{% else %}
<meta property="post-date" content="{{ page.date | date: '%Y年%-m月%-d日 %H:%M:%S %z' }}" />
{% endcase %}
<!-- Open Graph -->
<meta property="og:title" content="{% if page.title %}{{ page.title }} - {{ site.title }}{% else %}{{ site.title }}{% endif %}">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ page.url | prepend: site.url }}">
<meta property="og:baseurl" content="{{ site.baseurl }}">
<meta property="og:description" content="{{ site.description }}">
<meta property="og:site_name" content="{{ site.title }}">
<meta property="og:gray" content="{{ site.gray }}">
<meta property="og:lang" content="{{ lang }}">
{% if site.alivetime %}
<meta name="alivestart" content="{{ site.alivestart }}">
{% endif %}
Expand All @@ -36,28 +42,21 @@
{% endif %}
<meta name="theme-color" content="{{ site.pwa.color }}" />
<link rel="manifest" href="{{ "/manifest.json" | prepend: site.baseurl }}" />
<link rel="apple-touch-icon" href="{{ site.baseurl }}/assets/img/touch/apple-touch-icon.png"/>
<link rel="apple-touch-icon" href="{{ "/assets/img/touch/apple-touch-icon.png" | prepend: site.baseurl }}" />
<link rel="Shortcut Icon" href="{{ site.favicon | prepend: site.baseurl }}">
<link rel="icon" href="{{ site.favicon | prepend: site.baseurl }}" type="image/x-icon" />
<link rel="bookmark" href="{{ site.favicon | prepend: site.baseurl }}" type="image/x-icon" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.min.css" async>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-screen-webfont@1.1.0/style.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5.2.0/github-markdown-light.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css">
{% assign prisms1 = "coy,dark,funky,okaidia,solarizedlight,tomorrow,twilight" | split: "," %}
{% assign prisms2 = "a11y-dark,atom-dark,base16-ateliersulphurpool.light,cb,coldark-cold,coy-without-shadows,darcula,duotone-dark,duotone-earth,duotone-light,dutone-sea,dutone-space,ghcolors,gruvbox-dark,gruvbox-light,holi-theme,hopscotch,lucario,material-dark,material-light,material-oceanic,night-owl,nord,one-dark,one-light,pojoaque,shades-of-purple,solarized-dark-atom,synthwave84,vs,vsc-dark-plus,xonokai,z-touch" | split: "," %}
{% if prisms1 contains site.prism.theme %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.28.0/themes/prism-{{site.prism.theme}}.min.css" />
{% else if prisms2 contains site.prism.theme %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prism-themes@1.9.0/themes/prism-{{site.prism.theme}}.min.css" />
{% if layout.type == "post" %}
{% include plugins/others/social_css.html%}
{% include plugins/markdown/fancybox_css.html %}
{% else %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.28.0/themes/prism.min.css" />
{% endif %}
{% if site.prism.line_numbers %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.28.0/plugins/line-numbers/prism-line-numbers.min.css">
{% include plugins/others/calendar_css.html %}
{% endif %}
{% include plugins/markdown/prism_css.html %}
{% include plugins/comments/waline_css.html %}
<link rel="stylesheet" href="{{ "/assets/css/app.min.css" | prepend: site.baseurl }}">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.css" />
<script src="//cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
</head>
File renamed without changes.
40 changes: 40 additions & 0 deletions _includes/layouts/metainfo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.2/dayjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.2/plugin/customParseFormat.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.2/plugin/relativeTime.js"></script>
<script>
$(document).ready(function () {
var time_formats = ['YYYY-MM-DD HH:mm:ss ZZ', 'YYYY DD MMM HH:mm:ss ZZ', 'YYYY年MM月DD日 HH:mm:ss ZZ'];
function dateFormat(date, format) {
var date_org = dayjs(date, time_formats[format]);
var date = date_org.format(time_formats[format]);
return { "date_org": date_org, "date": date }
}

dayjs.extend(window.dayjs_plugin_customParseFormat);
dayjs.extend(window.dayjs_plugin_relativeTime);
var post_date = $("meta[property='post-date']").attr('content');
var post_date_format = $("meta[property='post-date-format']").attr('content');
var local_post_date = dateFormat(post_date, post_date_format);

$(".post time span.create-at").html(local_post_date["date"]);

fetch("https://api.github.com/repos/{{ site.github.owner }}/{{ site.github.repository }}/commits?path={{ page.path }}").then((response) => {
return response.json();
}).then((commits) => {
if (commits.length != 0) {
var update_at = dayjs(commits[0]['commit']['committer']['date']);
} else {
var update_at = post_date
}

var local_update_at = dateFormat(update_at, post_date_format);
$('.post time span.update-at').html(local_update_at["date"]);

var relative_time = dayjs().diff(local_update_at["date_org"], 'day');
$(".post-copyright .tips span").append(relative_time);
if (relative_time > 365) {
$(".post-copyright .tips").addClass("active");
}
});
});
</script>
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions _includes/paginate.html → _includes/layouts/paginate.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
{% endif %}
{% for i in (unpin_start..unpin_end) %}
{% assign post = unpin_posts[i] %}
{% include paginate-article.html %}
{% include layouts/paginate-article.html %}
{% endfor %}
{% elsif pin_posts_num < max_num %}
{% assign pin_end = pin_posts_num | minus: 1 %}
{% for i in (min_num..pin_end) %}
{% assign post = pin_posts[i] %}
{% include paginate-article.html %}
{% include layouts/paginate-article.html %}
{% endfor %}
{% assign unpin_end = max_num | minus: pin_posts_num | minus: 1 %}
{% if unpin_end >= unpin_posts_num %}
{% assign unpin_end = unpin_posts_num | minus: 1 %}
{% endif %}
{% for i in (0..unpin_end) %}
{% assign post = unpin_posts[i] %}
{% include paginate-article.html %}
{% include layouts/paginate-article.html %}
{% endfor %}
{% else %}
{% assign pin_start = min_num %}
{% assign pin_end = max_num | minus: 1 %}
{% for i in (pin_start..pin_end) %}
{% assign post = pin_posts[i] %}
{% include paginate-article.html %}
{% include layouts/paginate-article.html %}
{% endfor %}
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion _includes/sidebar.html → _includes/layouts/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{% endif %}
</section>
{% if site.calendar %}
{% include calendar.html %}
{% include plugins/others/calendar_block.html %}
{% endif %}
{% if site.recommend-tags and site.tags.size>0 %}
{% assign max_tag_count = 0 %}
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions _includes/mermaid.html

This file was deleted.

3 changes: 3 additions & 0 deletions _includes/plugins/analytics/analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% include plugins/analytics/google.html %}
{% include plugins/analytics/umami.html %}
{% include plugins/analytics/busuanzi.html %}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<script async src="https://www.googletagmanager.com/gtag/js?id={{site.google_analytics}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', '{{site.google_analytics}}');
</script>
{% endif %}
File renamed without changes.
67 changes: 67 additions & 0 deletions _includes/plugins/comments/comments_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% capture block %}
<section class="post-footer-item comment">
<div class="comments-headline">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-comment"></use>
</svg>
<span>{{ locales.post.comment }}</span>
</div>
{% if layout.type == "post" %}
{% if site.comments.disqus and site.comments.waline %}
<div id="comments-switch">
<span class="first-comment">Disqus</span>
<span class="switch-button">
<input id="cmn-toggle-4" class="cmn-toggle cmn-toggle-round-flat" type="checkbox">
<label for="cmn-toggle-4"></label>
</span>
<span class="second-comment">Waline</span>
</div>
{% endif %}
{% else %}
{% if page.comments.disqus and page.comments.waline %}
<div id="comments-switch">
<span class="first-comment">Disqus</span>
<span class="switch-button">
<input id="cmn-toggle-4" class="cmn-toggle cmn-toggle-round-flat" type="checkbox">
<label for="cmn-toggle-4"></label>
</span>
<span class="second-comment">Waline</span>
</div>
{% endif %}
{% endif %}
</section>
{% endcapture %}

{% if layout.type == "post" %}
{% if site.comments.disqus or site.comments.waline or page.comments.waline or page.comments.disqus %}
{{ block }}
{% endif %}
{% else %}
{% if page.comments.disqus or page.comments.waline %}
{{ block }}
{% endif %}
{% endif %}

{% if layout.type == "post" %}
{% if site.comments.disqus %}
<section class="post-footer-item comment">
<div id="disqus_thread"></div>
</section>
{% endif %}
{% if site.comments.waline %}
<section class="post-footer-item comment">
<div id="waline"></div>
</section>
{% endif %}
{% else %}
{% if page.comments.disqus %}
<section class="post-footer-item comment">
<div id="disqus_thread"></div>
</section>
{% endif %}
{% if page.comments.waline %}
<section class="post-footer-item comment">
<div id="waline"></div>
</section>
{% endif %}
{% endif %}
24 changes: 24 additions & 0 deletions _includes/plugins/comments/comments_js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% include plugins/comments/disqus.html %}
{% include plugins/comments/waline_js.html %}
<script>
$(document).ready(function () {
if ($("#comments-switch").length > 0) {
var comment_status = $("#cmn-toggle-4")[0].checked;
if (comment_status) {
$("#waline").addClass("active");
} else {
$("#disqus_thread").addClass("active");
}
$("#cmn-toggle-4").click(function () {
$("#disqus_thread").toggleClass("active");
$("#waline").toggleClass("active");
})
} else {
if ($("#disqus_thread").length > 0) {
$("#disqus_thread").addClass("active");
} else if ($("#waline").length > 0) {
$("#waline").addClass("active");
}
}
})
</script>
Loading

0 comments on commit 98f71b9

Please sign in to comment.