Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure all page JS is in functions rather than running at the top level
Improve init code
- Loading branch information
Showing
3 changed files
with
46 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import Plausible from 'plausible-tracker'; | ||
|
||
const {trackPageview, enableAutoOutboundTracking} = Plausible({ | ||
apiHost: 'https://d.sb', | ||
trackLocalhost: false, | ||
}); | ||
export function trackPageview(): void { | ||
const {trackPageview, enableAutoOutboundTracking} = Plausible({ | ||
apiHost: 'https://d.sb', | ||
trackLocalhost: false, | ||
}); | ||
|
||
trackPageview(); | ||
// TODO: This doesn't provide a way to ignore links, which breaks the | ||
// JS-powered links on the projects page. | ||
// https://github.com/plausible/plausible-tracker/blob/c0b87d997d839938c23023d35bac0d6683635bbc/src/lib/tracker.ts#L292 | ||
//enableAutoOutboundTracking(); | ||
trackPageview(); | ||
// TODO: This doesn't provide a way to ignore links, which breaks the | ||
// JS-powered links on the projects page. | ||
// https://github.com/plausible/plausible-tracker/blob/c0b87d997d839938c23023d35bac0d6683635bbc/src/lib/tracker.ts#L292 | ||
//enableAutoOutboundTracking(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
import '../css/main.less'; | ||
|
||
import {initBlog} from './pages/blog'; | ||
import {initIndex} from './pages/home'; | ||
import {initProjects} from './pages/projects'; | ||
import {initSocialFeed} from './pages/socialfeed'; | ||
|
||
import './analytics'; | ||
import '../not_an_easter_egg/secret'; | ||
import {trackPageview} from './analytics'; | ||
import {attachKonamiCodeListener} from '../not_an_easter_egg/secret'; | ||
|
||
switch (document.body.id) { | ||
case 'site-index': | ||
initIndex(); | ||
break; | ||
function initPage(): void { | ||
const controller = document.body.dataset.controller; | ||
const action = document.body.dataset.action; | ||
switch (controller) { | ||
case 'blog': | ||
initBlog(); | ||
break; | ||
|
||
case 'site-socialfeed': | ||
initSocialFeed(); | ||
break; | ||
case 'projects': | ||
initProjects(); | ||
break; | ||
|
||
case 'project-index': | ||
initProjects(); | ||
break; | ||
case 'site': | ||
switch (action) { | ||
case 'index': | ||
initIndex(); | ||
break; | ||
|
||
case 'socialfeed': | ||
initSocialFeed(); | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
trackPageview(); | ||
initPage(); | ||
attachKonamiCodeListener(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters