mirror of
https://github.com/cotes2020/chirpy-starter.git
synced 2025-07-01 20:08:55 +10:00
fix: update layout and import Chirpy template files
This commit is contained in:
19
_includes/pageviews/goatcounter.html
Normal file
19
_includes/pageviews/goatcounter.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!-- Display GoatCounter pageviews -->
|
||||
<script>
|
||||
let pv = document.getElementById('pageviews');
|
||||
|
||||
if (pv !== null) {
|
||||
const uri = location.pathname.replace(/\/$/, '');
|
||||
const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${encodeURIComponent(uri)}.json`;
|
||||
|
||||
fetch(url)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const count = data.count.replace(/\s/g, '');
|
||||
pv.innerText = new Intl.NumberFormat().format(count);
|
||||
})
|
||||
.catch((error) => {
|
||||
pv.innerText = '1';
|
||||
});
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user