popular posts extracted from goatcounter db

This commit is contained in:
Wouter Groeneveld 2022-11-12 10:10:31 +01:00
parent 87622a9014
commit 1b9f683dbe
6 changed files with 199 additions and 29 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

7
data/popularposts.json Normal file
View File

@ -0,0 +1,7 @@
[
{ "url": "/post/2022/10/a-visual-studio-6-nostalgia-trip", "title": "A Visual Studio 6.0 Nostalgia Trip", "rank": "57%" },
{ "url": "/post/2022/10/guilt-and-flexible-working-hours", "title": "Guilt And Flexible Working Hours", "rank": "15%" },
{ "url": "/post/2022/04/cool-things-people-do-with-their-blogs", "title": "Cool Things People Do With Their Blogs", "rank": "10%" },
{ "url": "/post/2021/02/writing-academic-papers-in-markdown", "title": "How to write academic papers in Markdown", "rank": "10%" },
{ "url": "/post/2022/02/how-to-setup-pi-hole-on-synology-nas", "title": "How to setup Pi-Hole on a Synology NAS", "rank": "8%" }
]

View File

@ -1,4 +1,144 @@
[
{
"author": {
"name": "Simone Silvestroni",
"picture": "/pictures/minutestomidnight.co.uk"
},
"name": "Note",
"content": "@wouter thanks for the debug! Since I released this version of the website Ive must have changed the layout a billion times and didnt test the JS behavior properly…\n\nIm not fussed about DuckDuckGo, all the results lead to my website anyway...",
"published": "2022-11-11T18:30:44+01:00",
"url": "https://minutestomidnight.co.uk/note/2022-11-11-18-30-44/",
"type": "mention",
"source": "https://minutestomidnight.co.uk/note/2022-11-11-18-30-44/",
"target": "https://brainbaking.com/notes/2022/11/11h13m23s03/",
"relativeTarget": "/notes/2022/11/11h13m23s03/"
},
{
"author": {
"name": "Henrique Dias",
"picture": "/pictures/hacdias.com"
},
"name": "",
"content": "Today Wouter posted about Finding Stuff on Big Blogs, which was quite an interesting read. I noticed that quite some people had a “on this day” page. It turns out, I already had it implemented 99% of the functionality to get it done. I just add t...",
"published": "2022-11-11T16:01:21+01:00",
"url": "https://hacdias.com/2022/11/11/16h01m21s69",
"type": "mention",
"source": "https://hacdias.com/2022/11/11/16h01m21s69",
"target": "https://brainbaking.com/post/2022/11/finding-stuff-on-big-blogs/",
"relativeTarget": "/post/2022/11/finding-stuff-on-big-blogs/"
},
{
"author": {
"name": "Simone Silvestroni",
"picture": "/pictures/minutestomidnight.co.uk"
},
"name": "Note",
"content": "@wouter I do have a graceful degradation in my search page as well, though my decision was to show both the JS-based instant search and the DDG-driven static functionality, regardless of whether the person has JS enabled or not. To be honest, Im w...",
"published": "2022-11-11T12:30:58+01:00",
"url": "https://minutestomidnight.co.uk/note/2022-11-11-12-30-58/",
"type": "mention",
"source": "https://minutestomidnight.co.uk/note/2022-11-11-12-30-58/",
"target": "https://brainbaking.com/post/2022/11/finding-stuff-on-big-blogs/",
"relativeTarget": "/post/2022/11/finding-stuff-on-big-blogs/"
},
{
"author": {
"name": "Henrique Dias",
"picture": "/pictures/hacdias.com"
},
"name": "Issues With DigiD as a Foreigner",
"content": "When Wouter published an article on government website design mistakes, I immediately thought: I have a very similar topic in the back of my mind that has bothered me since I moved to The Netherlands. It is not related to a website per se, but to a s...",
"published": "2022-11-08T23:50:15+01:00",
"url": "https://hacdias.com/2022/11/08/issues-with-digid-as-foreigner",
"type": "mention",
"source": "https://hacdias.com/2022/11/08/issues-with-digid-as-foreigner",
"target": "https://brainbaking.com/post/2022/11/governmental-infrastructure-website-design-mistakes/",
"relativeTarget": "/post/2022/11/governmental-infrastructure-website-design-mistakes/"
},
{
"author": {
"name": "Aaron Davis",
"picture": "/pictures/readwriterespond.com"
},
"name": "📑 50 Most Common WordPress Errors and How to Fix Them",
"content": "I had a few errors on my sites recently. ALT LAB Timeline Maker and Subscribe To Comments plugins were causing issues on Collect, while I was unable to login to my Read Write Respond site. After logging a ticket with Reclaim Hosting, I was pointed to...",
"published": "2022-11-08T21:29:34+11:00",
"url": "https://collect.readwriterespond.com/50-most-common-wordpress-errors-and-how-to-fix-them/",
"type": "mention",
"source": "https://collect.readwriterespond.com/50-most-common-wordpress-errors-and-how-to-fix-them/",
"target": "https://brainbaking.com/post/2022/10/should-we-build-our-own-wayback-machines/",
"relativeTarget": "/post/2022/10/should-we-build-our-own-wayback-machines/"
},
{
"author": {
"name": "Henrique Dias",
"picture": "/pictures/hacdias.com"
},
"name": "",
"content": "",
"published": "2022-11-07T14:56:25+01:00",
"url": "https://hacdias.com/2022/11/07/14h56m25s79",
"type": "mention",
"source": "https://hacdias.com/2022/11/07/14h56m25s79",
"target": "https://brainbaking.com/post/2022/11/governmental-infrastructure-website-design-mistakes/",
"relativeTarget": "/post/2022/11/governmental-infrastructure-website-design-mistakes/"
},
{
"author": {
"name": "Peter Rukavina",
"picture": "/pictures/ruk.ca"
},
"name": "Governmental Infrastructue Website Design Mistakes",
"content": "",
"published": "2022-11-07T12:15:03+00:00",
"url": "https://ruk.ca/favourite/governmental-infrastructue-website-design-mistakes",
"type": "like",
"source": "https://ruk.ca/favourite/governmental-infrastructue-website-design-mistakes",
"target": "https://brainbaking.com/post/2022/11/governmental-infrastructure-website-design-mistakes/",
"relativeTarget": "/post/2022/11/governmental-infrastructure-website-design-mistakes/"
},
{
"author": {
"name": "Jan Boddez",
"picture": "/pictures/boddez.net"
},
"name": "",
"content": "A thousand times this. (I expect things to cool down soon enough. If not, Ill be hanging out on the ol blog. Feel free to webmention me.)\n\nTwitters exodus [is] leading a lot of folks to the Fediverse, which is great, except that [to] me, the...",
"published": "2022-11-03T12:43:00+01:00",
"url": "https://jan.boddez.net/notes/cb4a006e8c",
"type": "bookmark",
"source": "https://jan.boddez.net/notes/cb4a006e8c",
"target": "https://brainbaking.com/post/2022/11/october-2022/",
"relativeTarget": "/post/2022/11/october-2022/"
},
{
"author": {
"name": "Anonymous",
"picture": "/pictures/anonymous"
},
"name": "@jamesravey Is simssource.net also stored in your archivebox? 😇 I would love to see that revived somewhere! Managed to put up a few of my old junk like https://brainbaking.com/museum/1998/ but the dynamic ones are partially broken forever I'm afraid...",
"content": "@jamesravey Is simssource.net also stored in your archivebox? 😇 I would love to see that revived somewhere! Managed to put up a few of my old junk like https://brainbaking.com/museum/1998/ but the dynamic ones are partially broken forever I'm afra...",
"published": "2022-11-03T10:23:56+00:00",
"url": "https://chat.brainbaking.com/objects/d7a07ae0-4a34-40f8-9152-933b8744fcf6",
"type": "mention",
"source": "https://brid.gy/comment/mastodon/@jamesravey@fosstodon.org/109279275255962446/109279381898899954",
"target": "https://brainbaking.com/post/2022/10/should-we-build-our-own-wayback-machines/",
"relativeTarget": "/post/2022/10/should-we-build-our-own-wayback-machines/"
},
{
"author": {
"name": "James Ravenscroft",
"picture": "/pictures/brainsteam.co.uk"
},
"name": "",
"content": "Really enjoyed this blog post. Ive been using archivebox for a couple of years now and I tend to link to the original and then my archived mirror when writing up my notes in my digital garden. I also use wallabag for preserving long form art...",
"published": "2022-11-03T09:54:43+00:00",
"url": "https://brainsteam.co.uk/replies/2022/11/03/1667467926/",
"type": "mention",
"source": "https://brainsteam.co.uk/replies/2022/11/03/1667467926/",
"target": "https://brainbaking.com/post/2022/10/should-we-build-our-own-wayback-machines/",
"relativeTarget": "/post/2022/10/should-we-build-our-own-wayback-machines/"
},
{
"author": {
"name": "Peter Rukavina",

45
extras/popularposts.py Normal file
View File

@ -0,0 +1,45 @@
import sqlite3
import sys
import os
from datetime import datetime
# see https://github.com/arp242/goatcounter/blob/master/db/query/hit_list.List-stats.sql
# date format: "2022-11-01 23:00:00"
q = """
select
path, title, hour,
sum(total) as total
from hit_counts
where
hit_counts.site = 1
and hour >= "2022-11-01"
and hour < "2022-12-01"
and path like '/post/%'
group by path
order by total desc
limit 5
"""
dbpath = "/var/www/goatcounter/db/goatcounter.db"
if len(sys.argv) > 1:
dbpath = sys.argv[1]
if not os.path.exists(dbpath):
exit("DB file " + dbpath + " does not exist, quitting!")
connection = sqlite3.connect(dbpath)
cursor = connection.cursor()
cursor.execute(q)
rows = cursor.fetchall()
total = sum(map(lambda r: int(r[3]), rows))
title = lambda r: r[1].split('|')[0].strip()
url = lambda r: r[0]
date = lambda r: datetime.strptime(r[2], "%Y-%m-%d %H:%M:%S").strftime("%d %b %Y")
rank = lambda r: str(round((int(r[3]) / total) * 100)) + "%"
print('[')
print(',\n'.join(map(lambda r: "{ \"url\": \"" + url(r) + "\", \"title\": \"" + title(r) + "\", \"rank\": \"" + rank(r) + "\" }", rows)))
print(']')

View File

@ -15,8 +15,6 @@
<small><a href="/archives">Archives</a> &raquo;</small>
</div>
{{ $tags := slice }}
{{ $cats := slice }}
<ul class="smallist">
{{ range first $itms (where .Site.Pages "Section" "post").ByDate.Reverse }}
<li class="flexlist">
@ -27,12 +25,6 @@
{{ .Date.Format ("02 Jan 2006") }}
</small>
</li>
{{ if isset .Params "tags" }}
{{ $tags = $tags | append .Params.tags }}
{{ end }}
{{ if isset .Params "categories" }}
{{ $cats = $cats | append .Params.categories }}
{{ end }}
{{ end }}
</ul>
</article>
@ -42,24 +34,16 @@
<small><a href="https://stats.brainbaking.com">Statistics</a> &raquo;</small>
</div>
{{ $tags := slice }}
{{ $cats := slice }}
<ul class="smallist">
{{ range first $itms (where .Site.Pages "Section" "post").ByDate.Reverse }}
{{ range first $itms (.Site.Data.popularposts) }}
<li class="flexlist">
<h3>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
<a href="{{ .url }}">{{ .title }}</a>
</h3>
<small>
{{ .Date.Format ("02 Jan 2006") }}
{{ .rank }} hits
</small>
</li>
{{ if isset .Params "tags" }}
{{ $tags = $tags | append .Params.tags }}
{{ end }}
{{ if isset .Params "categories" }}
{{ $cats = $cats | append .Params.categories }}
{{ end }}
{{ end }}
</ul>
</article>
@ -68,8 +52,6 @@
<h2>Random Tasty Treats</h2>
<small><a href="/post">All posts</a> &raquo;</small>
</div>
{{ $tags := slice }}
{{ $cats := slice }}
<ul class="smallist">
{{ range first $itms (shuffle (where .Site.Pages "Section" "post")) }}
<li class="flexlist">
@ -80,12 +62,6 @@
{{ .Date.Format ("02 Jan 2006") }}
</small>
</li>
{{ if isset .Params "tags" }}
{{ $tags = $tags | append .Params.tags }}
{{ end }}
{{ if isset .Params "categories" }}
{{ $cats = $cats | append .Params.categories }}
{{ end }}
{{ end }}
</ul>
</article>

View File

@ -14,9 +14,11 @@
},
"scripts": {
"prenote": "node hooks/prenote.js",
"precommit": "node hooks/precommit.js",
"search": "echo 'executing Hugo+Pagefind (locally)...' && hugo && /usr/local/bin/pagefind --source docs --bundle-dir ../static/_pagefind && hugo serve",
"postdeploy": "node hooks/postdeploy.js"
"precompile": "python extras/popularposts.py > data/popularposts.json",
"predeploy": "/usr/local/bin/pagefind --source docs",
"postdeploy": "node hooks/postdeploy.js",
},
"repository": {
"type": "git",