diff --git a/package-lock.json b/package-lock.json index a727cee..fb5da4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "5.0.1", + "version": "5.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "5.0.1", + "version": "5.1.2", "license": "MIT", "dependencies": { "html-minifier-terser": "7.2.0", @@ -31,7 +31,7 @@ "postcss-import": "^16.1.0", "postcss-import-ext-glob": "^2.1.1", "rimraf": "^6.0.1", - "terser": "^5.39.1", + "terser": "^5.39.2", "truncate-html": "^1.2.1" }, "engines": { @@ -4486,13 +4486,13 @@ "license": "MIT" }, "node_modules/terser": { - "version": "5.39.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.39.1.tgz", - "integrity": "sha512-Mm6+uad0ZuDtcV8/4uOZQDQ8RuiC5Pu+iZRedJtF7yA/27sPL7d++In/AJKpWZlU3SYMPPkVfwetn6sgZ66pUA==", + "version": "5.39.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.39.2.tgz", + "integrity": "sha512-yEPUmWve+VA78bI71BW70Dh0TuV4HHd+I5SHOAfS1+QBOmvmCiiffgjR8ryyEd3KIfvPGFqoADt8LdQ6XpXIvg==", "license": "BSD-2-Clause", "dependencies": { "@jridgewell/source-map": "^0.3.3", - "acorn": "^8.8.2", + "acorn": "^8.14.0", "commander": "^2.20.0", "source-map-support": "~0.5.20" }, diff --git a/package.json b/package.json index 06c93f9..eafef56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "5.0.2", + "version": "5.1.2", "description": "The source for my personal site. Built using 11ty (and other tools).", "type": "module", "engines": { @@ -54,7 +54,7 @@ "postcss-import": "^16.1.0", "postcss-import-ext-glob": "^2.1.1", "rimraf": "^6.0.1", - "terser": "^5.39.1", + "terser": "^5.39.2", "truncate-html": "^1.2.1" } } diff --git a/queries/functions/get_top_tags.sql b/queries/functions/get_top_tags.sql new file mode 100644 index 0000000..2e91066 --- /dev/null +++ b/queries/functions/get_top_tags.sql @@ -0,0 +1,37 @@ +CREATE OR REPLACE FUNCTION get_top_tag_groups() +RETURNS JSON AS $$ +BEGIN + RETURN json_build_object( + 'tags', ( + SELECT json_agg(t) FROM ( + SELECT tag, COUNT(*) AS usage_count + FROM optimized_tagged_content + WHERE type IN ('article', 'link') + GROUP BY tag + ORDER BY usage_count DESC + LIMIT 10 + ) t + ), + 'watching_genres', ( + SELECT json_agg(t) FROM ( + SELECT tag, COUNT(*) AS usage_count + FROM optimized_tagged_content + WHERE type IN ('tv', 'movies') + GROUP BY tag + ORDER BY usage_count DESC + LIMIT 10 + ) t + ), + 'books_genres', ( + SELECT json_agg(t) FROM ( + SELECT tag, COUNT(*) AS usage_count + FROM optimized_tagged_content + WHERE type = 'books' + GROUP BY tag + ORDER BY usage_count DESC + LIMIT 10 + ) t + ) + ); +END; +$$ LANGUAGE plpgsql STABLE; diff --git a/src/data/topTags.js b/src/data/topTags.js new file mode 100644 index 0000000..d457f77 --- /dev/null +++ b/src/data/topTags.js @@ -0,0 +1,27 @@ +import EleventyFetch from "@11ty/eleventy-fetch"; + +const { POSTGREST_URL, POSTGREST_API_KEY } = process.env; + +const fetchTopTags = async () => { + try { + return await EleventyFetch(`${POSTGREST_URL}/rpc/get_top_tag_groups`, { + duration: "1h", + type: "json", + fetchOptions: { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${POSTGREST_API_KEY}`, + }, + }, + }); + } catch (error) { + console.error("Error fetching top tag entries:", error); + return []; + } +}; + +export default async function () { + console.log(await fetchTopTags()) + return await fetchTopTags(); +} diff --git a/src/includes/blocks/top-tags.liquid b/src/includes/blocks/top-tags.liquid new file mode 100644 index 0000000..a0ef8ab --- /dev/null +++ b/src/includes/blocks/top-tags.liquid @@ -0,0 +1 @@ +
{{ label }}{%- for tag in tags %} #{{ tag.tag }}{%- endfor -%}
diff --git a/src/pages/media/books/index.html b/src/pages/media/books/index.html index 4411179..842bf79 100644 --- a/src/pages/media/books/index.html +++ b/src/pages/media/books/index.html @@ -10,6 +10,10 @@ updated: "now" {%- assign currentBookCount = books.currentYear | size -%}Here's what I'm reading at the moment. I've finished {{ currentBookCount }} books this year. I've read {{ books.daysRead }} days in a row and counting.
+{% render "blocks/top-tags.liquid" + label:"Top genres" + tags:topTags.books_genres +%}{{ books.years | bookYearLinks }}
{% render "blocks/banners/rss.liquid", url: "/feeds/books.xml", diff --git a/src/pages/media/watching/index.html b/src/pages/media/watching/index.html index d52ca7a..69b45d5 100644 --- a/src/pages/media/watching/index.html +++ b/src/pages/media/watching/index.html @@ -15,6 +15,10 @@ updated: "now" %}Here's all of the TV and movies I've been watching presented in what is (hopefully) an organized fashion.
You can see all of the shows I've got queued up here.
+{% render "blocks/top-tags.liquid" + label:"Top genres" + tags:topTags.watching_genres +%} {% render "blocks/banners/rss.liquid", url: "/feeds/movies.xml", text: "Subscribe to my movies feed or follow along on this page" diff --git a/src/pages/sections/links.html b/src/pages/sections/links.html index 27034f2..e5a0861 100644 --- a/src/pages/sections/links.html +++ b/src/pages/sections/links.html @@ -9,6 +9,10 @@ permalink: "/links/{% if pagination.pageNumber > 0 %}{{ pagination.pageNumber }} {% if pagination.pageNumber == 0 %}These are links I've liked or otherwise found interesting. They're all added manually, after having been read and, I suppose, properly considered.
+{% render "blocks/top-tags.liquid" + label:"Top tags" + tags:topTags.tags +%} {% render "blocks/banners/rss.liquid", url: "/feeds/links.xml", text: "Subscribe to my links feed or follow along on this page" diff --git a/src/pages/sections/posts/index.html b/src/pages/sections/posts/index.html index 30d75d7..11e0532 100644 --- a/src/pages/sections/posts/index.html +++ b/src/pages/sections/posts/index.html @@ -9,6 +9,10 @@ permalink: "/posts/{% if pagination.pageNumber > 0 %}{{ pagination.pageNumber }}These are all of my blog posts on this site (I like some more than others).
I tend to write about whatever strikes me, with a focus on development, technology, automation or issues I run into with these things. This is all typically light on editing with and heavy on spur of the moment thoughts.
+{% render "blocks/top-tags.liquid" + label:"Top tags" + tags:topTags.tags +%} {% render "blocks/banners/rss.liquid", url: "/feeds/posts.xml", text: "Subscribe to my posts feed or follow along on this page" diff --git a/src/pages/static/search.html b/src/pages/static/search.html index 72f1f67..d930be0 100644 --- a/src/pages/static/search.html +++ b/src/pages/static/search.html @@ -6,6 +6,10 @@ description: Search through posts and other content on my site.You can find posts, links, artists, genres, movies, shows and books via the field below (though it only surfaces movies and shows I've watched and books I've written something about). You can also browse my tags list.
+{% render "blocks/top-tags.liquid" + label:"Top tags" + tags:topTags.tags +%}