File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,5 @@ $ docker cp cover.webp kungfux.github.io:/workspaces/kungfux.github.io/assets/me
58
58
` assets/js/progress.js ` , ` assets/css/jekyll-theme-chirpy.scss ` , ` _includes/metadata-hook.html `
59
59
- Trigger PWA update automatically
60
60
` assets/js/auto-update.js ` , ` _includes/metadata-hook.html `
61
+ - Fix pageviews
62
+ ` _includes/pageviews/goatcounter.html `
Original file line number Diff line number Diff line change
1
+ <!-- Display GoatCounter pageviews -->
2
+ < script >
3
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
4
+ const pv = document . getElementById ( 'pageviews' ) ;
5
+
6
+ if ( pv !== null ) {
7
+ const uri = location . pathname . replace ( / \/ $ / , '' ) ;
8
+ const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${ encodeURIComponent ( uri ) } .json` ;
9
+
10
+ fetch ( url )
11
+ . then ( ( response ) => response . json ( ) )
12
+ . then ( ( data ) => {
13
+ const count = data . count . replace ( / \s / g, '' ) ;
14
+ pv . innerText = new Intl . NumberFormat ( ) . format ( count ) ;
15
+ } )
16
+ . catch ( ( error ) => {
17
+ pv . innerText = '1' ;
18
+ } ) ;
19
+ }
20
+ } ) ;
21
+ </ script >
You can’t perform that action at this time.
0 commit comments