Skip to content

Commit 066889d

Browse files
authored
在 document 布局中新增 page meta 信息
1 parent bf53fa9 commit 066889d

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

_config.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ defaults:
105105
path: ""
106106
values:
107107
layout: document
108-
read_time: false
109-
author_profile: false
110-
share: false
111-
comments: false
108+
show_date: true
112109
sidebar:
113110
nav: docs
114111
hits: true

_data/settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ appearance_skin:
3131
- sunrise
3232
- catppuccin_latte
3333
- catppuccin_mocha
34+
miscellaneous_hits:
35+
type: radio
36+
default: enable
37+
options:
38+
- enable
39+
- disable

_layouts/document.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
layout: single
33
---
44

5-
{% if jekyll.environment == 'production' and page.hits %}
6-
<img src="https://hits.zkitefly.eu.org/?tag={{ page.url | absolute_url | url_encode }}" alt="Hits" decoding="async">
7-
{% endif %}
8-
9-
<div class="notice--info">
10-
<p>本文由 {{ page.author | default: '未署名用户' }} 创建{% if page.contributors %},并由 {{ page.contributors | join: ' ' }} 编辑{% endif %}。</p>
11-
</div>
12-
135
{{ content }}
6+
7+
{% if page.author or page.contributors or jekyll.environment == 'production' and page.hits %}
8+
<script src="{{ '/assets/js/meta.js' | relative_url }}"></script>
9+
<script>
10+
{%- if page.author %}appendMeta("{{ page.author }}", "fas fa-user-pen");{% endif -%}
11+
{%- for contributor in page.contributors %}appendMeta("{{ contributor }}", "fas fa-user-pen");{% endfor -%}
12+
{%- if jekyll.environment == 'production' and page.hits %}hits("{{ page.url | absolute_url | url_encode }}");{% endif -%}
13+
</script>
14+
{% endif %}

assets/js/meta.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(() => {
2+
const pageTitle = document.getElementById("page-title");
3+
if (pageTitle === null) return;
4+
const header = pageTitle.parentElement;
5+
let metas = header.getElementsByClassName("page__meta")[0];
6+
if (metas === null) {
7+
metas = document.createElement("div");
8+
element.className = "page__meta";
9+
header.append(element);
10+
}
11+
window.appendMeta = (text, icon) => {
12+
if (metas.children.length > 0) {
13+
const sep = document.createElement("span");
14+
sep.className = "page__meta-sep";
15+
metas.append(sep);
16+
}
17+
const meta = document.createElement("span");
18+
if (icon !== undefined) {
19+
const metaIcon = document.createElement("i");
20+
metaIcon.className = icon;
21+
meta.append(metaIcon, " ");
22+
}
23+
meta.append(text.trim());
24+
metas.append(meta);
25+
};
26+
window.hits = (tag) => {
27+
if (settings.get("miscellaneous_hits") === "disable") return;
28+
const hitsUrl = new URL("https://hits.zkitefly.eu.org");
29+
hitsUrl.searchParams.set("tag", tag);
30+
fetch(hitsUrl, { method: "HEAD" }).then((response) => {
31+
if (response.status !== 200) return;
32+
const { headers } = response;
33+
const total = headers.get("X-Total-Hits");
34+
const today = headers.get("X-Today-Hits");
35+
if (total !== null && today !== null) {
36+
appendMeta(today + " / " + total, "far fa-eye");
37+
}
38+
});
39+
};
40+
})();

settings.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ data:
3737
sunrise: 日出 (Sunrise)
3838
catppuccin_latte: Catppuccin Latte
3939
catppuccin_mocha: Catppuccin Mocha
40+
- title: 杂项
41+
settings:
42+
miscellaneous_hits:
43+
title: 访问统计服务
44+
description: 用于统计页面访问量的服务。
45+
options:
46+
enable: 启用
47+
disable: 禁用
4048
---

0 commit comments

Comments
 (0)