mirror of
https://github.com/peter-tanner/peter-tanner.github.io.git
synced 2024-12-02 21:10:17 +08:00
19 lines
529 B
HTML
19 lines
529 B
HTML
|
<!-- 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) => {
|
||
|
pv.innerText = new Intl.NumberFormat().format(data.count);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
pv.innerText = '1';
|
||
|
});
|
||
|
}
|
||
|
</script>
|