Skip to content

Commit 5677981

Browse files
committed
add stats on list page
1 parent 51fa32b commit 5677981

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

static/js/custom.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ function set_home_page_site_run_days() {
4646
}
4747

4848
let allPageViewsAPI = "https://api.bmpi.dev/page-views/bmpi-dev-all-page-views/";
49+
let devPageViewsAPI = "https://api.bmpi.dev/page-views/bmpi-dev-dev-page-views/";
50+
let selfPageViewsAPI = "https://api.bmpi.dev/page-views/bmpi-dev-self-page-views/";
51+
let moneyPageViewsAPI = "https://api.bmpi.dev/page-views/bmpi-dev-money-page-views/";
4952
let singlePageViewsAPI = "https://api.bmpi.dev/page-views/bmpi.dev" + window.location.pathname;
5053

5154
function get_post_views(url, callback) {
@@ -61,6 +64,24 @@ function set_stats_on_home() {
6164
get_post_views(singlePageViewsAPI, res => {});
6265
} else {
6366
postViews = document.getElementById("post-views");
67+
devPostViews = document.getElementById("dev-page-views");
68+
selfPostViews = document.getElementById("self-page-views");
69+
moneyPostViews = document.getElementById("money-page-views");
70+
if (devPostViews != undefined) {
71+
get_post_views(devPageViewsAPI, res => {
72+
devPostViews.textContent = JSON.parse(res).count;
73+
});
74+
}
75+
if (selfPostViews != undefined) {
76+
get_post_views(selfPageViewsAPI, res => {
77+
selfPostViews.textContent = JSON.parse(res).count;
78+
});
79+
}
80+
if (moneyPostViews != undefined) {
81+
get_post_views(moneyPageViewsAPI, res => {
82+
moneyPostViews.textContent = JSON.parse(res).count;
83+
});
84+
}
6485
if (postViews != undefined) {
6586
get_post_views(allPageViewsAPI, res => {});
6687
get_post_views(singlePageViewsAPI, res => {

themes/hugo-coder/layouts/dev/list.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
{{ end }}
44
{{ define "content" }}
55
<section class="container list">
6-
<h1 class="title" style="font-size: 1.6rem !important;border-bottom:1px dotted #bf7326;padding-bottom:20px;">{{ .Description }}</h1>
7-
6+
{{$scratch := newScratch}}
7+
{{ range (where .Site.RegularPages "Section" "==" "dev") }}
8+
{{$scratch.Add "total" (countwords .Content)}}
9+
{{ end }}
10+
<h1 class="title" style="font-size: 1.6rem !important;border-bottom:1px dotted #bf7326;padding-bottom:20px;">
11+
{{ .Description }}
12+
<br>
13+
<div style="text-align:left;font-size: 1.2rem !important;">共 {{ len (where .Site.RegularPages "Section" "==" "dev") }} 篇文章 / 总计 {{$scratch.Get "total" }} 字 / 浏览量 <span id="dev-page-views"></span></div>
14+
</h1>
815
<ul>
916
{{- range .Paginator.Pages -}}
1017
{{- .Render "li" -}}

themes/hugo-coder/layouts/money/list.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
{{ end }}
44
{{ define "content" }}
55
<section class="container list">
6-
<h1 class="title" style="font-size: 1.6rem !important;border-bottom:1px dotted #bf7326;padding-bottom:20px;">{{ .Description }}</h1>
6+
{{$scratch := newScratch}}
7+
{{ range (where .Site.RegularPages "Section" "==" "dev") }}
8+
{{$scratch.Add "total" (countwords .Content)}}
9+
{{ end }}
10+
<h1 class="title" style="font-size: 1.6rem !important;border-bottom:1px dotted #bf7326;padding-bottom:20px;">
11+
{{ .Description }}
12+
<br>
13+
<div style="text-align:left;font-size: 1.2rem !important;">共 {{ len (where .Site.RegularPages "Section" "==" "dev") }} 篇文章 / 总计 {{$scratch.Get "total" }} 字 / 浏览量 <span id="money-page-views"></span></div>
14+
</h1>
715

816
<ul>
917
{{- range .Paginator.Pages -}}

themes/hugo-coder/layouts/self/list.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
{{ end }}
44
{{ define "content" }}
55
<section class="container list">
6-
<h1 class="title" style="font-size: 1.6rem !important;border-bottom:1px dotted #bf7326;padding-bottom:20px;">{{ .Description }}</h1>
6+
{{$scratch := newScratch}}
7+
{{ range (where .Site.RegularPages "Section" "==" "dev") }}
8+
{{$scratch.Add "total" (countwords .Content)}}
9+
{{ end }}
10+
<h1 class="title" style="font-size: 1.6rem !important;border-bottom:1px dotted #bf7326;padding-bottom:20px;">
11+
{{ .Description }}
12+
<br>
13+
<div style="text-align:left;font-size: 1.2rem !important;">共 {{ len (where .Site.RegularPages "Section" "==" "dev") }} 篇文章 / 总计 {{$scratch.Get "total" }} 字 / 浏览量 <span id="self-page-views"></span></div>
14+
</h1>
715

816
<ul>
917
{{- range .Paginator.Pages -}}

0 commit comments

Comments
 (0)