Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ defaults:
path: ""
values:
layout: document
read_time: false
author_profile: false
share: false
comments: false
show_date: true
sidebar:
nav: docs
hits: true
Expand Down
17 changes: 9 additions & 8 deletions _layouts/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
layout: single
---

{% if jekyll.environment == 'production' and page.hits %}
<img src="https://hits.zkitefly.eu.org/?tag={{ page.url | absolute_url | url_encode }}" alt="Hits" decoding="async">
{% endif %}

<div class="notice--info">
<p>本文由 {{ page.author | default: '未署名用户' }} 创建{% if page.contributors %},并由 {{ page.contributors | join: ' ' }} 编辑{% endif %}。</p>
</div>

{{ content }}

{% if page.author or page.contributors or jekyll.environment == 'production' and page.hits %}
<script src="{{ '/assets/js/meta.js' | relative_url }}"></script>
<script>
{%- if page.author %}appendMeta("{{ page.author }}", "fas fa-user-pen");{% endif -%}
{%- for contributor in page.contributors %}appendMeta("{{ contributor }}", "fas fa-user-pen");{% endfor -%}
{%- if jekyll.environment == 'production' and page.hits %}hits("{{ page.url | absolute_url | url_encode }}");{% endif -%}
</script>
{% endif %}
39 changes: 39 additions & 0 deletions assets/js/meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(() => {
const pageTitle = document.getElementById("page-title");
if (pageTitle === null) return;
const header = pageTitle.parentElement;
let metas = header.getElementsByClassName("page__meta")[0];
if (metas === null) {
metas = document.createElement("div");
element.className = "page__meta";
header.append(element);
}
window.appendMeta = (text, icon) => {
if (metas.children.length > 0) {
const sep = document.createElement("span");
sep.className = "page__meta-sep";
metas.append(sep);
}
const meta = document.createElement("span");
if (icon !== undefined) {
const metaIcon = document.createElement("i");
metaIcon.className = icon;
meta.append(metaIcon, " ");
}
meta.append(text.trim());
metas.append(meta);
};
window.hits = (tag) => {
const hitsUrl = new URL("https://hits.zkitefly.eu.org");
hitsUrl.searchParams.set("tag", tag);
fetch(hitsUrl, { method: "HEAD" }).then((response) => {
if (response.status !== 200) return;
const { headers } = response;
const total = headers.get("X-Total-Hits");
const today = headers.get("X-Today-Hits");
if (total !== null && today !== null) {
appendMeta(today + " / " + total, "far fa-eye");
}
});
};
})();