优化 document 布局内容 (#423)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
neveler 2026-04-17 07:52:37 +08:00 committed by GitHub
parent 493d605495
commit 0907ca4b6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 64 additions and 12 deletions

View File

@ -106,10 +106,7 @@ defaults:
path: "" path: ""
values: values:
layout: document layout: document
read_time: false show_date: true
author_profile: false
share: false
comments: false
sidebar: sidebar:
nav: docs nav: docs
hits: true hits: true

View File

@ -31,3 +31,9 @@ appearance_skin:
- sunrise - sunrise
- catppuccin_latte - catppuccin_latte
- catppuccin_mocha - catppuccin_mocha
miscellaneous_hits:
type: radio
default: enable
options:
- enable
- disable

View File

@ -2,12 +2,13 @@
layout: single 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 }} {{ 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 %}

40
assets/js/meta.js Normal file
View File

@ -0,0 +1,40 @@
(() => {
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) => {
if (settings.get("miscellaneous_hits") === "disable") return;
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");
}
});
};
})();

View File

@ -37,4 +37,12 @@ data:
sunrise: 日出 (Sunrise) sunrise: 日出 (Sunrise)
catppuccin_latte: Catppuccin Latte catppuccin_latte: Catppuccin Latte
catppuccin_mocha: Catppuccin Mocha catppuccin_mocha: Catppuccin Mocha
- title: 杂项
settings:
miscellaneous_hits:
title: 访问统计服务
description: 用于统计页面访问量的服务。
options:
enable: 启用
disable: 禁用
--- ---