Skip to content

Commit 1950d09

Browse files
committed
Add download counts to content metadata table
1 parent 72b0b20 commit 1950d09

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

‎_layouts/content.html‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h2 class="author">Read by {% if reader %}<a href="{{ reader.url }}">{{ reader.t
9797
</i></p>
9898

9999
{% if site.show_bibtex %}
100-
<details class="details-reset bibtex" ontoggle="deetstoggler();">
100+
<details class="details-reset bibtex">
101101
<summary class="btn">Bibtex Data <span class="dropdown-caret"></span></summary>
102102
<div>
103103
{% capture bibtex %}{% include content.bibtex.liquid content=page %}{% endcapture %}
@@ -113,11 +113,32 @@ <h2 class="author">Read by {% if reader %}<a href="{{ reader.url }}">{{ reader.t
113113
function clearTooltip(){this.setAttribute('class','btn copybutton');this.removeAttribute('aria-label');}
114114
function showTooltip(elem,msg){elem.setAttribute('class','btn copybutton tooltipped tooltipped-n');elem.setAttribute('aria-label',msg); setTimeout(clearTooltip.bind(elem), 4000);}
115115
</script>
116-
<table class="metadata"><tbody>{% if site.show_timestamps %}
117-
<tr><td>Added</td><td><span style="font-family: system-ui, sans;">{{ page.date | date_to_rfc822 }}</span></td></tr>
118-
{% if page.last_modified_at > page.date %}<tr><td>Updated</td><td><span style="font-family: system-ui, sans;">{{ page.last_modified_at | date_to_rfc822 }}</span></td></tr>{% endif %}{% endif %}
119-
<tr><td>Sorting Value</td><td><span style="font-family: system-ui, sans;">{{ page.expected_value }}</span></td></tr>
116+
<table id="metadata"><tbody>{% if site.show_timestamps %}
117+
<tr><td>Added</td><td><span>{{ page.date | date_to_rfc822 }}</span></td></tr>
118+
{% if page.last_modified_at > page.date %}<tr><td>Updated</td><td><span>{{ page.last_modified_at | date_to_rfc822 }}</span></td></tr>{% endif %}{% endif %}
119+
<tr><td>Sorting Value</td><td><span>{{ page.expected_value }}</span></td></tr>
120120
</tbody></table>
121+
<script type="module">
122+
function addDownloadCountRow(download_count) {
123+
const table = document.getElementById("metadata");
124+
const dcRow = table.insertRow();
125+
const labelCell = dcRow.insertCell(0);
126+
labelCell.appendChild(document.createTextNode("Download Count"));
127+
const valueCell = dcRow.insertCell(1);
128+
const value = document.createTextNode(download_count.toString());
129+
const valueSpan = document.createElement('span');
130+
valueSpan.appendChild(value);
131+
valueCell.appendChild(valueSpan);
132+
}
133+
const download_count_resp = await fetch("https://buddhistuniversity.net/analytics/content/{{ page.content_path }}.download_count");
134+
var download_count = 0;
135+
if (download_count_resp.ok) {
136+
download_count = await download_count_resp.text();
137+
download_count = Number.parseInt(download_count);
138+
}
139+
download_count++;
140+
addDownloadCountRow(download_count);
141+
</script>
121142
<span><a href="https://github.com/{{ site.github_repo }}/blob/{{ site.github_branch }}/{{ page.path }}">View this entry's source code on GitHub</a></span>
122143
</div>
123144
</details>{% endif %}

‎_layouts/default.html‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@
8484
</head>
8585
<body>
8686
<a class="skip-to-main" href="#main">Skip to content</a>
87-
<noscript>
88-
<img src="https://{{ site.goatcounter }}.goatcounter.com/count?p=/{{ page.url }}&t={{ page.title | url_encode }}">
89-
</noscript>
90-
9187
<header class="site-header{% if page.banner_info %} banner-img{% if page.next_courses %} fullsize{% elsif site.header_pages contains page.path %} smallsize{% endif %}{% if page.image_center_y %}" style="background-position-y: {{ page.image_center_y }};{% if page.image_center_x %} background-position-x: {{ page.image_center_x }};{% endif %}{% endif %}{% endif %}" role="banner">
9288
<div class="wrapper"{% if page.banner_info %} style="backdrop-filter: blur(0.3px);"{% endif %}>
9389
<a class="site-title" rel="author" href="{{ "/" | relative_url }}"><img height="48" src="/assets/imgs/logo.png" alt="logo"></img><span>{{ site.title | escape }}</span></a>
@@ -100,6 +96,9 @@
10096
</div>
10197
{% if page.banner_info %}{{ infobutton }}{% endif %}
10298
</header>
99+
<noscript>
100+
<img src="https://{{ site.goatcounter }}.goatcounter.com/count?p=/{{ page.url }}&t={{ page.title | url_encode }}">
101+
</noscript>
103102

104103
<main class="page-content" aria-label="Content">
105104
<div id="main" tabindex="-1" class="wrapper">
@@ -141,17 +140,15 @@ <h2 class="footer-heading">{{ site.title | escape }}</h2>
141140
</div>
142141

143142
</div>
144-
143+
</footer>
145144
{%- if site.goatcounter -%}
146145
<script
147146
data-goatcounter="https://{{ site.goatcounter }}.goatcounter.com/count"
148-
data-goatcounter-settings='{"allow_frame": true, "title": "{{ page.title | replace: '"', '\\"' }}"}'
147+
data-goatcounter-settings='{"allow_frame": true, "title": "{{ page.title | escape }}"}'
149148
async src="//gc.zgo.at/count.js">
150149
</script>
151150
<script async src="/assets/js/goatclicker.js">
152151
</script>
153152
{%- endif -%}
154-
155-
</footer>
156153
</body>
157154
</html>

‎assets/css/content-perma.scss‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ article.content-perma .pub_desc {
3737
font-size: 105%;
3838
}
3939

40-
article.content-perma table.metadata {
40+
#metadata {
4141
font-size: 89%;
4242
margin-top: 18px;
43+
td:nth-child(2)>span {
44+
font-family: system-ui, sans;
45+
}
4346
}
4447

4548
details.bibtex .highlight {

0 commit comments

Comments
 (0)