📈 Add umami code

This commit is contained in:
Dan Jones 2023-01-03 14:47:27 -06:00
commit d73ec6ba7b
5 changed files with 57 additions and 2 deletions

View file

@ -1,5 +1,7 @@
ifndef dev ifndef dev
sass_opts = --no-source-map --style=compressed sass_opts = --no-source-map --style=compressed
else
compile_opts = dev
endif endif
.PHONY: all .PHONY: all
@ -10,7 +12,7 @@ clean:
rm -v build/index.html build/style.css* rm -v build/index.html build/style.css*
build/index.html: index.html config.toml compile.js build/index.html: index.html config.toml compile.js
node compile.js node compile.js $(compile_opts)
build/style.css: scss/style.scss node_modules/bootstrap/scss/_root.scss build/style.css: scss/style.scss node_modules/bootstrap/scss/_root.scss
npx sass $(sass_opts) $< $@ npx sass $(sass_opts) $< $@

35
build/app.js Normal file
View file

@ -0,0 +1,35 @@
/* global umami */
document.addEventListener('click', getFollows);
function getFollows(evt) {
const el = evt.target;
if (el.tagName.toLowerCase() !== 'a') {
return;
}
const name = el.dataset.name;
if (!name) {
return;
}
const url = el.href;
if (!url) {
return;
}
if (!window.umami) {
return;
}
const umProm = umami.trackEvent('visit', { type: 'click', site: name });
if (!el.target || el.target.match(/^_(self|parent|top)$/i)) {
// If we're not opening in a new tab, then try to send event before navigating away
// Don't wait too long though (half a second, at most)
evt.preventDefault();
umProm.then(() => location.href = url).catch(() => location.href = url);
setTimeout(() => location.href = url, 500);
}
}

View file

@ -1,3 +1,5 @@
/* global process */
const { parse } = require('@ltd/j-toml'); const { parse } = require('@ltd/j-toml');
const { render } = require('mustache'); const { render } = require('mustache');
const { readFile, writeFile } = require('node:fs/promises'); const { readFile, writeFile } = require('node:fs/promises');
@ -13,11 +15,18 @@ async function compile() {
const config = parse(confToml); const config = parse(confToml);
config.version = stdout.trim(); config.version = stdout.trim();
config.slug = function () {
return this.text ? this.text.toLowerCase() : this.icon;
};
config.text = function () { config.text = function () {
const string = this.icon; const string = this.icon;
return string.charAt(0).toUpperCase() + string.slice(1); return string.charAt(0).toUpperCase() + string.slice(1);
}; };
if (process.argv[2] === 'dev') {
config.umami.website_id = config.umami.dev_website_id;
}
const tempPath = resolve('./index.html'); const tempPath = resolve('./index.html');
const template = await readFile(tempPath, { encoding: 'utf8' }); const template = await readFile(tempPath, { encoding: 'utf8' });

View file

@ -1,6 +1,10 @@
title = "Dan Jones's Links" title = "Dan Jones's Links"
name = "Dan Jones" name = "Dan Jones"
[umami]
website_id = "698f40c8-f098-4287-8d01-f98e55902d6c"
dev_website_id = "23b68fab-0a02-4e81-8240-63bec79b5f2e"
[[links]] [[links]]
icon = "mastodon" icon = "mastodon"
url = "https://fosstodon.org/@danjones000" url = "https://fosstodon.org/@danjones000"
@ -9,12 +13,14 @@ url = "https://fosstodon.org/@danjones000"
icon = "blog" icon = "blog"
la = "las" la = "las"
text = "Dan's Musings" text = "Dan's Musings"
slug = "musings"
url = "https://goodevilgenius.org" url = "https://goodevilgenius.org"
[[links]] [[links]]
icon = "swatchbook" icon = "swatchbook"
la = "las" la = "las"
text = "Résumé" text = "Résumé"
slug = "danielrayjones"
url = "https://danielrayjones.com/" url = "https://danielrayjones.com/"
[[links]] [[links]]
@ -49,6 +55,7 @@ url = "https://trakt.tv/users/goodevilgenius/"
[[links]] [[links]]
icon = "lastfm" icon = "lastfm"
text = "Last.FM" text = "Last.FM"
slug = "lastfm"
url = "https://www.last.fm/user/dan000" url = "https://www.last.fm/user/dan000"
[[links]] [[links]]

View file

@ -6,6 +6,8 @@
<title>{{title}}</title> <title>{{title}}</title>
<link rel="stylesheet" href="https://maxst.icons8.com/vue-static/landings/line-awesome/line-awesome/1.3.0/css/line-awesome.min.css"/> <link rel="stylesheet" href="https://maxst.icons8.com/vue-static/landings/line-awesome/line-awesome/1.3.0/css/line-awesome.min.css"/>
<link rel="stylesheet" href="style.css?ver={{version}}"/> <link rel="stylesheet" href="style.css?ver={{version}}"/>
<script async data-website-id="{{umami.website_id}}" data-do-not-track="true" src="https://whoami.goodevilgenius.org/whoami.js?ver={{version}}"></script>
<script async src="app.js"></script>
</head> </head>
<body> <body>
<header class="py-3 mb-4 border-bottom"> <header class="py-3 mb-4 border-bottom">
@ -23,7 +25,7 @@
<ul class="list-group"> <ul class="list-group">
{{#links}} {{#links}}
<li class="list-group-item text-center"> <li class="list-group-item text-center">
<a href="{{{url}}}" rel="me" class="fs-4 text-decoration-none text-dark"> <a href="{{{url}}}" data-name="{{slug}}" rel="me" class="fs-4 text-decoration-none text-dark">
<i class="{{la}}{{^la}}lab{{/la}} la-{{icon}}"></i> <i class="{{la}}{{^la}}lab{{/la}} la-{{icon}}"></i>
{{text}} {{text}}
</a> </a>