From 65a80fef1278dacf26940a674b249112e3fc8e26 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 18 Nov 2026 18:40:55 +0100 Subject: [PATCH 1/6] fix: update canonical and Open Graph URLs to use Astro.site for consistency --- astro.config.mjs | 1 + src/layouts/base.astro | 9 +++++---- src/layouts/word.astro | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 34da0940..45868a17 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,6 +8,7 @@ import autoprefixer from "autoprefixer"; // https://astro.build/config export default defineConfig({ + site: "https://www.jargons.dev", integrations: [ mdx(), react(), diff --git a/src/layouts/base.astro b/src/layouts/base.astro index 8d9e8444..dcb0312f 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -7,10 +7,11 @@ import { SITE_META_KEYWORDS, SITE_META_DESCRIPTION } from "../../constants.js"; const MEASUREMENT_ID = import.meta.env.PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID; const { props, url } = Astro; +const canonicalUrl = new URL(url.pathname, Astro.site); const { pageTitle, class: list, - ogImageUrl = `${url.origin}/og.png`, + ogImageUrl = new URL("/og.png", Astro.site).href, description = SITE_META_DESCRIPTION, subtitle = "Developer Jargons", } = props; @@ -25,15 +26,15 @@ const { - + - - + + diff --git a/src/layouts/word.astro b/src/layouts/word.astro index aaa0e958..2a8c59a7 100644 --- a/src/layouts/word.astro +++ b/src/layouts/word.astro @@ -13,7 +13,10 @@ import JAIFollowUpChatWidget, { const { frontmatter } = Astro.props; const dictionary = await getCollection("dictionary"); const wordSlug = Astro.url.pathname.split("/").filter(Boolean).at(-1) ?? ""; -const ogImageUrl = `${Astro.url.origin}/api/open-graph/${encodeURIComponent(String(wordSlug))}.png`; +const ogImageUrl = new URL( + `/api/open-graph/${encodeURIComponent(String(wordSlug))}.png`, + Astro.site, +).href; /** * @todo implement a better way to resolve the `slug` used in the `editUrl` From 30c5cffcbf8f42742a494d57686dad5b87fac653 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 18 Nov 2026 18:52:15 +0100 Subject: [PATCH 2/6] feat: use dynamic site URL for Vercel preview environment supoort --- astro.config.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/astro.config.mjs b/astro.config.mjs index 45868a17..e970b1d0 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -6,9 +6,16 @@ import partytown from "@astrojs/partytown"; import tailwindcss from "tailwindcss"; import autoprefixer from "autoprefixer"; +const VERCEL_PREVIEW_SITE = + process.env.VERCEL_ENV === "preview" && process.env.VERCEL_BRANCH_URL + ? `https://${process.env.VERCEL_BRANCH_URL}` + : undefined; + +const site = VERCEL_PREVIEW_SITE || "https://www.jargons.dev"; + // https://astro.build/config export default defineConfig({ - site: "https://www.jargons.dev", + site, integrations: [ mdx(), react(), From 33f337305790f99d16be07dac0d1a4e6215a68e8 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 18 Nov 2026 18:53:33 +0100 Subject: [PATCH 3/6] fix: update canonical and Open Graph URLs to use dynamic site origin --- src/layouts/base.astro | 5 +++-- src/layouts/word.astro | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/layouts/base.astro b/src/layouts/base.astro index dcb0312f..1c34527b 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -7,11 +7,12 @@ import { SITE_META_KEYWORDS, SITE_META_DESCRIPTION } from "../../constants.js"; const MEASUREMENT_ID = import.meta.env.PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID; const { props, url } = Astro; -const canonicalUrl = new URL(url.pathname, Astro.site); +const siteOrigin = import.meta.env.DEV ? url.origin : Astro.site; +const canonicalUrl = new URL(url.pathname, siteOrigin); const { pageTitle, class: list, - ogImageUrl = new URL("/og.png", Astro.site).href, + ogImageUrl = new URL("/og.png", siteOrigin).href, description = SITE_META_DESCRIPTION, subtitle = "Developer Jargons", } = props; diff --git a/src/layouts/word.astro b/src/layouts/word.astro index 2a8c59a7..a1bb8bef 100644 --- a/src/layouts/word.astro +++ b/src/layouts/word.astro @@ -13,9 +13,10 @@ import JAIFollowUpChatWidget, { const { frontmatter } = Astro.props; const dictionary = await getCollection("dictionary"); const wordSlug = Astro.url.pathname.split("/").filter(Boolean).at(-1) ?? ""; +const siteOrigin = import.meta.env.DEV ? Astro.url.origin : Astro.site; const ogImageUrl = new URL( `/api/open-graph/${encodeURIComponent(String(wordSlug))}.png`, - Astro.site, + siteOrigin, ).href; /** From 983e409287ced9d82e8c0eda8fed9e8f33168914 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 18 Nov 2026 18:55:02 +0100 Subject: [PATCH 4/6] feat: add SITE_META_SUBTITLE to improve SEO and page metadata --- constants.js | 2 ++ src/layouts/base.astro | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/constants.js b/constants.js index 0d2dfd7d..6be02717 100644 --- a/constants.js +++ b/constants.js @@ -12,6 +12,8 @@ export const LABELS = { export const SITE_META_DESCRIPTION = "A community-driven dictionary that simplifies software, engineering and tech terms for all levels. Curated by contributors, jargons.dev offers clear, easy-to-understand definitions."; +export const SITE_META_SUBTITLE = "Jargons.dev"; + export const SITE_META_KEYWORDS = [ "dev jargon", "dev jargons", diff --git a/src/layouts/base.astro b/src/layouts/base.astro index 1c34527b..1c1264fa 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -2,7 +2,7 @@ import "@fontsource/inter"; import "@fontsource/ibm-plex-mono"; import "../base.css"; -import { SITE_META_KEYWORDS, SITE_META_DESCRIPTION } from "../../constants.js"; +import { SITE_META_KEYWORDS, SITE_META_DESCRIPTION, SITE_META_SUBTITLE } from "../../constants.js"; const MEASUREMENT_ID = import.meta.env.PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID; @@ -14,7 +14,7 @@ const { class: list, ogImageUrl = new URL("/og.png", siteOrigin).href, description = SITE_META_DESCRIPTION, - subtitle = "Developer Jargons", + subtitle = SITE_META_SUBTITLE, } = props; --- From b69b05e20fcbc7a3e8d55a555bffca521e226b67 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 18 Nov 2026 19:04:24 +0100 Subject: [PATCH 5/6] feat: implement getExcerpt function for extracting text excerpts from Markdown --- src/layouts/word.astro | 9 ++++++++- src/lib/utils/index.js | 23 +++++++++++++++++++++++ src/pages/api/open-graph/[...slug].png.js | 17 +---------------- tests/unit/utils/index.test.js | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/layouts/word.astro b/src/layouts/word.astro index a1bb8bef..ffc68c06 100644 --- a/src/layouts/word.astro +++ b/src/layouts/word.astro @@ -6,6 +6,7 @@ import BaseLayout from "./base.astro"; import { getCollection } from "astro:content"; import Navbar from "../components/navbar.astro"; import Search from "../components/islands/search.jsx"; +import { buildWordSlug, getExcerpt } from "../lib/utils/index.js"; import JAIFollowUpChatWidget, { JAIFollowUpChatWidgetTrigger, } from "../../apps/jai/components/follow-up-chat.jsx"; @@ -13,6 +14,8 @@ import JAIFollowUpChatWidget, { const { frontmatter } = Astro.props; const dictionary = await getCollection("dictionary"); const wordSlug = Astro.url.pathname.split("/").filter(Boolean).at(-1) ?? ""; +const word = dictionary.find((entry) => buildWordSlug(entry.id) === wordSlug); +const excerpt = getExcerpt(word?.body); const siteOrigin = import.meta.env.DEV ? Astro.url.origin : Astro.site; const ogImageUrl = new URL( `/api/open-graph/${encodeURIComponent(String(wordSlug))}.png`, @@ -26,7 +29,11 @@ const ogImageUrl = new URL( const editUrl = `/editor/edit/${frontmatter.url.split("/")[3].split(".")[0]}`; --- - +
diff --git a/src/lib/utils/index.js b/src/lib/utils/index.js index 7d514726..c53b3f42 100644 --- a/src/lib/utils/index.js +++ b/src/lib/utils/index.js @@ -100,6 +100,29 @@ export function buildWordSlug(id) { return id.split(".")[0]; } +/** + * Get a plain-text excerpt from the first non-code paragraph of Markdown + * @param {string} body + * @returns {string} + */ +export function getExcerpt(body = "") { + const firstParagraph = body + .split(/\r?\n\s*\r?\n/) + .find( + (paragraph) => paragraph.trim() && !paragraph.trim().startsWith("```"), + ); + const normalized = (firstParagraph ?? "") + .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") + .replace(/`([^`]+)`/g, "$1") + .replace(/[*_>#]/g, "") + .replace(/\s+/g, " ") + .trim(); + + if (normalized.length <= 320) return normalized; + + return `${normalized.slice(0, 317).trimEnd()}...`; +} + /** * Get branch name from branch ref * @param {string} branchRef diff --git a/src/pages/api/open-graph/[...slug].png.js b/src/pages/api/open-graph/[...slug].png.js index 4cdc2cfd..8913d639 100644 --- a/src/pages/api/open-graph/[...slug].png.js +++ b/src/pages/api/open-graph/[...slug].png.js @@ -4,6 +4,7 @@ import { Resvg } from "@resvg/resvg-js"; import fs from "node:fs"; import path from "node:path"; import { getCollection } from "astro:content"; +import { getExcerpt } from "../../../lib/utils/index.js"; export const prerender = true; @@ -76,22 +77,6 @@ function truncate(text, limit) { return `${normalized.slice(0, limit - 3).trimEnd()}...`; } -function getExcerpt(body = "") { - const firstParagraph = body - .split(/\r?\n\s*\r?\n/) - .find( - (paragraph) => paragraph.trim() && !paragraph.trim().startsWith("```"), - ); - - return truncate( - (firstParagraph ?? "") - .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") - .replace(/`([^`]+)`/g, "$1") - .replace(/[*_>#]/g, ""), - 320, - ); -} - /** * Generate a share image for a dictionary entry. * @param {import("astro").APIContext} context diff --git a/tests/unit/utils/index.test.js b/tests/unit/utils/index.test.js index c89c2fbd..3e9d39d9 100644 --- a/tests/unit/utils/index.test.js +++ b/tests/unit/utils/index.test.js @@ -10,6 +10,7 @@ import { buildStatsUrl, buildWordPathname, buildWordSlug, + getExcerpt, toggleMarkdownListPrefix, continueMarkdownListOnEnter, toggleMarkdownWrap, @@ -438,3 +439,21 @@ describe("buildWordSlug", () => { expect(buildWordSlug("")).toBe(""); }); }); + +describe("getExcerpt", () => { + it("extracts and simplifies the first non-code paragraph", () => { + expect( + getExcerpt( + "```js\nignored()\n```\n\n**QUIC** uses [`UDP`](https://example.com) and `TLS`.\n\nA second paragraph.", + ), + ).toBe("QUIC uses UDP and TLS."); + }); + + it("truncates excerpts to 320 characters", () => { + expect(getExcerpt("a".repeat(321))).toBe(`${"a".repeat(317)}...`); + }); + + it("returns an empty string when no paragraph is available", () => { + expect(getExcerpt()).toBe(""); + }); +}); From 547c32747ba1f0c25cd666c57d3d5d2aab5798ad Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 18 Nov 2026 19:59:34 +0100 Subject: [PATCH 6/6] feat: add getKeywords function for extracting unique keywords from title and definition --- src/layouts/base.astro | 3 +- src/layouts/word.astro | 4 ++- src/lib/utils/index.js | 61 ++++++++++++++++++++++++++++++++++ tests/unit/utils/index.test.js | 21 ++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/layouts/base.astro b/src/layouts/base.astro index 1c1264fa..073cabb2 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -12,6 +12,7 @@ const canonicalUrl = new URL(url.pathname, siteOrigin); const { pageTitle, class: list, + keywords = SITE_META_KEYWORDS, ogImageUrl = new URL("/og.png", siteOrigin).href, description = SITE_META_DESCRIPTION, subtitle = SITE_META_SUBTITLE, @@ -25,7 +26,7 @@ const { - + diff --git a/src/layouts/word.astro b/src/layouts/word.astro index ffc68c06..1f4c6132 100644 --- a/src/layouts/word.astro +++ b/src/layouts/word.astro @@ -6,7 +6,7 @@ import BaseLayout from "./base.astro"; import { getCollection } from "astro:content"; import Navbar from "../components/navbar.astro"; import Search from "../components/islands/search.jsx"; -import { buildWordSlug, getExcerpt } from "../lib/utils/index.js"; +import { buildWordSlug, getExcerpt, getKeywords } from "../lib/utils/index.js"; import JAIFollowUpChatWidget, { JAIFollowUpChatWidgetTrigger, } from "../../apps/jai/components/follow-up-chat.jsx"; @@ -16,6 +16,7 @@ const dictionary = await getCollection("dictionary"); const wordSlug = Astro.url.pathname.split("/").filter(Boolean).at(-1) ?? ""; const word = dictionary.find((entry) => buildWordSlug(entry.id) === wordSlug); const excerpt = getExcerpt(word?.body); +const keywords = getKeywords(frontmatter.title, word?.body); const siteOrigin = import.meta.env.DEV ? Astro.url.origin : Astro.site; const ogImageUrl = new URL( `/api/open-graph/${encodeURIComponent(String(wordSlug))}.png`, @@ -32,6 +33,7 @@ const editUrl = `/editor/edit/${frontmatter.url.split("/")[3].split(".")[0]}`;
diff --git a/src/lib/utils/index.js b/src/lib/utils/index.js index c53b3f42..b5b4c331 100644 --- a/src/lib/utils/index.js +++ b/src/lib/utils/index.js @@ -123,6 +123,67 @@ export function getExcerpt(body = "") { return `${normalized.slice(0, 317).trimEnd()}...`; } +/** + * Extract a short, deduplicated keyword list from a word title and definition + * @todo Consider adding more sophisticated keyword extraction logic - this can help improve the relevance of extracted keywords + * @param {string} title + * @param {string} body + * @returns {string[]} + */ +export function getKeywords(title = "", body = "") { + const stopWords = new Set([ + "about", + "after", + "also", + "and", + "are", + "as", + "at", + "be", + "by", + "for", + "from", + "has", + "have", + "into", + "is", + "it", + "its", + "of", + "on", + "or", + "that", + "the", + "their", + "this", + "to", + "using", + "was", + "were", + "which", + "with", + ]); + const normalizedTitle = title.trim().toLowerCase(); + const keywords = normalizedTitle ? [normalizedTitle] : []; + const seen = new Set(keywords); + const words = + `${title} ${getExcerpt(body)}`.match(/[\p{L}\p{N}+#.-]+/gu) ?? []; + + for (const word of words) { + const keyword = word.replace(/^[.-]+|[.-]+$/g, "").toLowerCase(); + if (keyword.length < 3 || stopWords.has(keyword) || seen.has(keyword)) { + continue; + } + + keywords.push(keyword); + seen.add(keyword); + + if (keywords.length === 12) break; + } + + return keywords; +} + /** * Get branch name from branch ref * @param {string} branchRef diff --git a/tests/unit/utils/index.test.js b/tests/unit/utils/index.test.js index 3e9d39d9..eeb54728 100644 --- a/tests/unit/utils/index.test.js +++ b/tests/unit/utils/index.test.js @@ -11,6 +11,7 @@ import { buildWordPathname, buildWordSlug, getExcerpt, + getKeywords, toggleMarkdownListPrefix, continueMarkdownListOnEnter, toggleMarkdownWrap, @@ -457,3 +458,23 @@ describe("getExcerpt", () => { expect(getExcerpt()).toBe(""); }); }); + +describe("getKeywords", () => { + it("extracts unique terms from the title and first definition paragraph", () => { + expect( + getKeywords("QUIC", "QUIC is a fast protocol using UDP and TCP."), + ).toEqual(["quic", "fast", "protocol", "udp", "tcp"]); + }); + + it("keeps a title keyword when the definition is empty", () => { + expect(getKeywords("C", "")).toEqual(["c"]); + }); + + it("limits the list to twelve keywords", () => { + const body = Array.from({ length: 20 }, (_, index) => `term${index}`).join( + " ", + ); + + expect(getKeywords("Example", body)).toHaveLength(12); + }); +});