From a40ad6b7fecbfaee673cdd1e09ca4a89fa6b92b9 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 8 Nov 2026 21:36:01 +0000 Subject: [PATCH 1/2] Adds social share images, a default card plus a dynamic one for every page --- package-lock.json | 432 +++++++++++++++++- package.json | 3 + src/lib/components/common/PageMeta.svelte | 29 +- src/lib/components/home/HomeMeta.svelte | 19 - src/lib/config/index.ts | 7 +- src/lib/server/cache.ts | 2 +- src/lib/server/github/repo.ts | 8 +- src/lib/server/github/user.ts | 6 + src/lib/server/og/card.test.ts | 61 +++ src/lib/server/og/card.ts | 258 +++++++++++ src/lib/server/og/render.ts | 45 ++ src/lib/server/og/target.test.ts | 70 +++ src/lib/server/og/target.ts | 24 + src/lib/server/og/view.ts | 81 ++++ src/routes/+page.svelte | 5 +- .../[user=login]/[repo=repo]/+page.svelte | 14 +- .../[repo=repo]/ops/pages/+page.svelte | 9 +- src/routes/_og/[...path]/+server.ts | 18 + src/routes/og.png/+server.ts | 8 + static/robots.txt | 15 +- 20 files changed, 1069 insertions(+), 45 deletions(-) delete mode 100644 src/lib/components/home/HomeMeta.svelte create mode 100644 src/lib/server/og/card.test.ts create mode 100644 src/lib/server/og/card.ts create mode 100644 src/lib/server/og/render.ts create mode 100644 src/lib/server/og/target.test.ts create mode 100644 src/lib/server/og/target.ts create mode 100644 src/lib/server/og/view.ts create mode 100644 src/routes/_og/[...path]/+server.ts create mode 100644 src/routes/og.png/+server.ts diff --git a/package-lock.json b/package-lock.json index c118b12..398c3c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,14 +8,17 @@ "name": "github-dashboards", "version": "0.0.4", "dependencies": { + "@resvg/resvg-js": "^2.6.2", "drizzle-orm": "^0.45.4", "postgres": "^4.1.0", + "satori": "^0.63.2", "zod": "^4.6.7" }, "devDependencies": { "@eslint/js": "^10.0.1", "@fontsource-variable/geist": "^5.3.0", "@fontsource-variable/geist-mono": "^5.3.0", + "@fontsource/geist-mono": "^5.3.0", "@internationalized/date": "^3.12.4", "@lucide/svelte": "^1.66.0", "@sveltejs/adapter-node": "^5.5.4", @@ -1132,6 +1135,16 @@ "url": "https://github.com/sponsors/ayuhito" } }, + "node_modules/@fontsource/geist-mono": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource/geist-mono/-/geist-mono-5.3.0.tgz", + "integrity": "sha512-UtJ1BBBCVpMYdIcW7nEB45UAoAw5M53ZXs2t0ciPW+IokuAAIc56M8+kW5tXbRJCTpDw4XTtU7proT6NdQAHTg==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@humanfs/core": { "version": "0.19.2", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz", @@ -1373,6 +1386,233 @@ "dev": true, "license": "MIT" }, + "node_modules/@resvg/resvg-js": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js/-/resvg-js-2.6.2.tgz", + "integrity": "sha512-xBaJish5OeGmniDj9cW5PRa/PtmuVU3ziqrbr5xJj901ZDN4TosrVaNZpEiLZAxdfnhAe7uQ7QFWfjPe9d9K2Q==", + "license": "MPL-2.0", + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@resvg/resvg-js-android-arm-eabi": "2.6.2", + "@resvg/resvg-js-android-arm64": "2.6.2", + "@resvg/resvg-js-darwin-arm64": "2.6.2", + "@resvg/resvg-js-darwin-x64": "2.6.2", + "@resvg/resvg-js-linux-arm-gnueabihf": "2.6.2", + "@resvg/resvg-js-linux-arm64-gnu": "2.6.2", + "@resvg/resvg-js-linux-arm64-musl": "2.6.2", + "@resvg/resvg-js-linux-x64-gnu": "2.6.2", + "@resvg/resvg-js-linux-x64-musl": "2.6.2", + "@resvg/resvg-js-win32-arm64-msvc": "2.6.2", + "@resvg/resvg-js-win32-ia32-msvc": "2.6.2", + "@resvg/resvg-js-win32-x64-msvc": "2.6.2" + } + }, + "node_modules/@resvg/resvg-js-android-arm-eabi": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-android-arm-eabi/-/resvg-js-android-arm-eabi-2.6.2.tgz", + "integrity": "sha512-FrJibrAk6v29eabIPgcTUMPXiEz8ssrAk7TXxsiZzww9UTQ1Z5KAbFJs+Z0Ez+VZTYgnE5IQJqBcoSiMebtPHA==", + "cpu": [ + "arm" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-android-arm64": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-android-arm64/-/resvg-js-android-arm64-2.6.2.tgz", + "integrity": "sha512-VcOKezEhm2VqzXpcIJoITuvUS/fcjIw5NA/w3tjzWyzmvoCdd+QXIqy3FBGulWdClvp4g+IfUemigrkLThSjAQ==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-darwin-arm64": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-darwin-arm64/-/resvg-js-darwin-arm64-2.6.2.tgz", + "integrity": "sha512-nmok2LnAd6nLUKI16aEB9ydMC6Lidiiq2m1nEBDR1LaaP7FGs4AJ90qDraxX+CWlVuRlvNjyYJTNv8qFjtL9+A==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-darwin-x64": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-darwin-x64/-/resvg-js-darwin-x64-2.6.2.tgz", + "integrity": "sha512-GInyZLjgWDfsVT6+SHxQVRwNzV0AuA1uqGsOAW+0th56J7Nh6bHHKXHBWzUrihxMetcFDmQMAX1tZ1fZDYSRsw==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-linux-arm-gnueabihf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-linux-arm-gnueabihf/-/resvg-js-linux-arm-gnueabihf-2.6.2.tgz", + "integrity": "sha512-YIV3u/R9zJbpqTTNwTZM5/ocWetDKGsro0SWp70eGEM9eV2MerWyBRZnQIgzU3YBnSBQ1RcxRZvY/UxwESfZIw==", + "cpu": [ + "arm" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-linux-arm64-gnu": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-linux-arm64-gnu/-/resvg-js-linux-arm64-gnu-2.6.2.tgz", + "integrity": "sha512-zc2BlJSim7YR4FZDQ8OUoJg5holYzdiYMeobb9pJuGDidGL9KZUv7SbiD4E8oZogtYY42UZEap7dqkkYuA91pg==", + "cpu": [ + "arm64" + ], + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-linux-arm64-musl": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-linux-arm64-musl/-/resvg-js-linux-arm64-musl-2.6.2.tgz", + "integrity": "sha512-3h3dLPWNgSsD4lQBJPb4f+kvdOSJHa5PjTYVsWHxLUzH4IFTJUAnmuWpw4KqyQ3NA5QCyhw4TWgxk3jRkQxEKg==", + "cpu": [ + "arm64" + ], + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-linux-x64-gnu": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-linux-x64-gnu/-/resvg-js-linux-x64-gnu-2.6.2.tgz", + "integrity": "sha512-IVUe+ckIerA7xMZ50duAZzwf1U7khQe2E0QpUxu5MBJNao5RqC0zwV/Zm965vw6D3gGFUl7j4m+oJjubBVoftw==", + "cpu": [ + "x64" + ], + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-linux-x64-musl": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-linux-x64-musl/-/resvg-js-linux-x64-musl-2.6.2.tgz", + "integrity": "sha512-UOf83vqTzoYQO9SZ0fPl2ZIFtNIz/Rr/y+7X8XRX1ZnBYsQ/tTb+cj9TE+KHOdmlTFBxhYzVkP2lRByCzqi4jQ==", + "cpu": [ + "x64" + ], + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-win32-arm64-msvc": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-win32-arm64-msvc/-/resvg-js-win32-arm64-msvc-2.6.2.tgz", + "integrity": "sha512-7C/RSgCa+7vqZ7qAbItfiaAWhyRSoD4l4BQAbVDqRRsRgY+S+hgS3in0Rxr7IorKUpGE69X48q6/nOAuTJQxeQ==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-win32-ia32-msvc": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-win32-ia32-msvc/-/resvg-js-win32-ia32-msvc-2.6.2.tgz", + "integrity": "sha512-har4aPAlvjnLcil40AC77YDIk6loMawuJwFINEM7n0pZviwMkMvjb2W5ZirsNOZY4aDbo5tLx0wNMREp5Brk+w==", + "cpu": [ + "ia32" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@resvg/resvg-js-win32-x64-msvc": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/@resvg/resvg-js-win32-x64-msvc/-/resvg-js-win32-x64-msvc-2.6.2.tgz", + "integrity": "sha512-ZXtYhtUr5SSaBrUDq7DiyjOFJqBVL/dOBN7N/qmi/pO0IgiWW/f/ue3nbvu9joWE5aAKDoIzy/CxsY0suwGosQ==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@rolldown/binding-android-arm-eabi": { "version": "1.2.16", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.16.tgz", @@ -2099,6 +2339,22 @@ "win32" ] }, + "node_modules/@shuding/opentype.js": { + "version": "1.4.0-beta.0", + "resolved": "https://registry.npmjs.org/@shuding/opentype.js/-/opentype.js-1.4.0-beta.0.tgz", + "integrity": "sha512-3NgmNyH3l/Hv6EvsWJbsvpcpUba6R8IREQ83nH83cyakCw7uM1arZKNfHwv1Wz6jgqrF/j4x5ELvR6PnK9nTcA==", + "license": "MIT", + "dependencies": { + "fflate": "^0.7.3", + "string.prototype.codepointat": "^0.2.1" + }, + "bin": { + "ot": "bin/ot" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/@standard-schema/spec": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", @@ -3593,6 +3849,15 @@ "node": "18 || 20 || >=22" } }, + "node_modules/base64-js": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.8.tgz", + "integrity": "sha512-3XSA2cR/h/73EzlXXdU6YNycmYI7+kicTxks4eJg2g39biHR84slg2+des+p7iHYhbRg/udIS4TD53WabcOUkw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/bindings": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", @@ -3662,6 +3927,15 @@ "qified": "^0.10.1" } }, + "node_modules/camelize": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.1.tgz", + "integrity": "sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/chai": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", @@ -3738,7 +4012,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true, "license": "MIT" }, "node_modules/commander": { @@ -3793,6 +4066,47 @@ "node": ">= 8" } }, + "node_modules/css-background-parser": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/css-background-parser/-/css-background-parser-0.1.0.tgz", + "integrity": "sha512-2EZLisiZQ+7m4wwur/qiYJRniHX4K5Tc9w93MT3AS0WS1u5kaZ4FKXlOTBhOjc+CgEgPiGY+fX1yWD8UwpEqUA==", + "license": "MIT" + }, + "node_modules/css-box-shadow": { + "version": "1.0.0-3", + "resolved": "https://registry.npmjs.org/css-box-shadow/-/css-box-shadow-1.0.0-3.tgz", + "integrity": "sha512-9jaqR6e7Ohds+aWwmhe6wILJ99xYQbfmK9QQB9CcMjDbTxPZjwEmUQpU91OG05Xgm8BahT5fW+svbsQGjS/zPg==", + "license": "MIT" + }, + "node_modules/css-color-keywords": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz", + "integrity": "sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==", + "license": "ISC", + "engines": { + "node": ">=4" + } + }, + "node_modules/css-gradient-parser": { + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/css-gradient-parser/-/css-gradient-parser-0.0.17.tgz", + "integrity": "sha512-w2Xy9UMMwlKtou0vlRnXvWglPAceXCTtcmVSo8ZBUvqCV5aXEFP/PC6d+I464810I9FT++UACwTD5511bmGPUg==", + "license": "MIT", + "engines": { + "node": ">=16" + } + }, + "node_modules/css-to-react-native": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.2.0.tgz", + "integrity": "sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==", + "license": "MIT", + "dependencies": { + "camelize": "^1.0.0", + "css-color-keywords": "^1.0.0", + "postcss-value-parser": "^4.0.2" + } + }, "node_modules/cssesc": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", @@ -4511,6 +4825,15 @@ "dev": true, "license": "MIT" }, + "node_modules/emoji-regex-xs": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/emoji-regex-xs/-/emoji-regex-xs-2.0.1.tgz", + "integrity": "sha512-1QFuh8l7LqUcKe24LsPUNzjrzJQ7pgRwp1QMcZ5MX6mFplk2zQ08NVCM84++1cveaUUYtcCYHmeFEuNg16sU4g==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/enhanced-resolve": { "version": "5.26.0", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.26.0.tgz", @@ -4584,6 +4907,12 @@ "@esbuild/win32-x64": "0.28.1" } }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -4896,6 +5225,12 @@ } } }, + "node_modules/fflate": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.3.tgz", + "integrity": "sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw==", + "license": "MIT" + }, "node_modules/file-entry-cache": { "version": "11.1.5", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-11.1.5.tgz", @@ -5092,6 +5427,12 @@ "dev": true, "license": "ISC" }, + "node_modules/harfbuzzjs": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/harfbuzzjs/-/harfbuzzjs-0.10.0.tgz", + "integrity": "sha512-SN8LVwCOzvTq3OPNd0+EAghgXugItz56wst567D1vs7LnnKGWprhi3EG58aVOBwhN8HEbQxL4I9NDWkcXUutRw==", + "license": "MIT" + }, "node_modules/hashery": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/hashery/-/hashery-1.5.1.tgz", @@ -5118,6 +5459,18 @@ "node": ">= 0.4" } }, + "node_modules/hex-rgb": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/hex-rgb/-/hex-rgb-4.3.0.tgz", + "integrity": "sha512-Ox1pJVrDCyGHMG9CFg1tmrRUMRPRsAWYc/PinY0XzJU4K7y7vjNoLKIQ7BR5UJMCxNN8EM1MNDmHWA/B3aZUuw==", + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/hookified": { "version": "1.15.1", "resolved": "https://registry.npmjs.org/hookified/-/hookified-1.15.1.tgz", @@ -5591,6 +5944,16 @@ "node": ">=10" } }, + "node_modules/linebreak": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/linebreak/-/linebreak-1.1.0.tgz", + "integrity": "sha512-MHp03UImeVhB7XZtjd0E4n6+3xr5Dq/9xI/5FptGk5FrbDR3zagPa2DS6U8ks/3HjbKWG9Q1M2ufOzxV2qLYSQ==", + "license": "MIT", + "dependencies": { + "base64-js": "0.0.8", + "unicode-trie": "^2.0.0" + } + }, "node_modules/locate-character": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/locate-character/-/locate-character-3.0.0.tgz", @@ -5860,6 +6223,22 @@ "dev": true, "license": "BlueOak-1.0.0" }, + "node_modules/pako": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz", + "integrity": "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==", + "license": "MIT" + }, + "node_modules/parse-css-color": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/parse-css-color/-/parse-css-color-0.2.1.tgz", + "integrity": "sha512-bwS/GGIFV3b6KS4uwpzCFj4w297Yl3uqnSgIPsoQkx7GMLROXfMnWvxfNkL0oh8HVhZA4hvJoEoEIqonfJ3BWg==", + "license": "MIT", + "dependencies": { + "color-name": "^1.1.4", + "hex-rgb": "^4.1.0" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -6061,6 +6440,12 @@ "node": ">=4" } }, + "node_modules/postcss-value-parser": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", + "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", + "license": "MIT" + }, "node_modules/postgres": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/postgres/-/postgres-4.1.0.tgz", @@ -6396,6 +6781,29 @@ "node": ">=6" } }, + "node_modules/satori": { + "version": "0.63.2", + "resolved": "https://registry.npmjs.org/satori/-/satori-0.63.2.tgz", + "integrity": "sha512-h7dm4BRMo8F53l9vOXOIfJoqeVXuZvyz13VsvVuwJb72sLfq+8uddJIJcjLKLv2BqWzDvYIpzi3rvBBS+ETuvw==", + "license": "MPL-2.0", + "dependencies": { + "@shuding/opentype.js": "1.4.0-beta.0", + "css-background-parser": "^0.1.0", + "css-box-shadow": "1.0.0-3", + "css-gradient-parser": "^0.0.17", + "css-to-react-native": "^3.0.0", + "emoji-regex-xs": "^2.0.1", + "escape-html": "^1.0.3", + "fflate": "0.7.3", + "harfbuzzjs": "0.10.0", + "linebreak": "^1.1.0", + "parse-css-color": "^0.2.1", + "postcss-value-parser": "^4.2.0" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/semver": { "version": "7.8.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.4.tgz", @@ -6588,6 +6996,12 @@ "node": ">=8" } }, + "node_modules/string.prototype.codepointat": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.1.tgz", + "integrity": "sha512-2cBVCj6I4IOvEnjgO/hWqXjqBGsY+zwPmHl12Srk9IXSZ56Jwwmy+66XO5Iut/oQVR7t5ihYdLB0GMa4alEUcg==", + "license": "MIT" + }, "node_modules/strip-ansi": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz", @@ -6880,6 +7294,12 @@ "node": ">=18" } }, + "node_modules/tiny-inflate": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz", + "integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==", + "license": "MIT" + }, "node_modules/tinybench": { "version": "6.2.3", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.3.tgz", @@ -7041,6 +7461,16 @@ "dev": true, "license": "MIT" }, + "node_modules/unicode-trie": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unicode-trie/-/unicode-trie-2.0.0.tgz", + "integrity": "sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==", + "license": "MIT", + "dependencies": { + "pako": "^0.2.5", + "tiny-inflate": "^1.0.0" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index fc394e4..257da1d 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@eslint/js": "^10.0.1", "@fontsource-variable/geist": "^5.3.0", "@fontsource-variable/geist-mono": "^5.3.0", + "@fontsource/geist-mono": "^5.3.0", "@internationalized/date": "^3.12.4", "@lucide/svelte": "^1.66.0", "@sveltejs/adapter-node": "^5.5.4", @@ -55,8 +56,10 @@ "vitest": "^5.1.0" }, "dependencies": { + "@resvg/resvg-js": "^2.6.2", "drizzle-orm": "^0.45.4", "postgres": "^4.1.0", + "satori": "^0.63.2", "zod": "^4.6.7" } } diff --git a/src/lib/components/common/PageMeta.svelte b/src/lib/components/common/PageMeta.svelte index 2a40b97..a908ff9 100644 --- a/src/lib/components/common/PageMeta.svelte +++ b/src/lib/components/common/PageMeta.svelte @@ -1,13 +1,28 @@ - {title} · {APP_NAME} - {#if description} - - {/if} + {fullTitle} + + + + + + + + + + + + + diff --git a/src/lib/components/home/HomeMeta.svelte b/src/lib/components/home/HomeMeta.svelte deleted file mode 100644 index 8e489aa..0000000 --- a/src/lib/components/home/HomeMeta.svelte +++ /dev/null @@ -1,19 +0,0 @@ - - - - {APP_NAME} - - - - - - - - - diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index ee38027..4c584db 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -2,6 +2,9 @@ export const APP_NAME = 'github-dashboards'; export const APP_DESCRIPTION = 'A fast GitHub status board for users and repos'; export const GITHUB_WEB = 'https://github.com'; +// Social share card size, the 1.91:1 every platform crops to +export const OG_SIZE = { width: 1200, height: 630 } as const; + // A login's avatar straight from GitHub, no id needed, redirects to the sized image. // Larger sizes stay crisp when the avatar is drawn big, e.g. inside a bubble export const githubAvatar = (login: string, size = 48) => `${GITHUB_WEB}/${login}.png?size=${size}`; @@ -32,5 +35,7 @@ export const paths = { `/${user}/${repo}/ops/${section}`, repoInfo: (user: string, repo: string) => `/${user}/${repo}/info`, repoInfoSection: (user: string, repo: string, section: string) => - `/${user}/${repo}/info/${section}` + `/${user}/${repo}/info/${section}`, + // Share card for a page path, home gets the baked default + ogImage: (path: string) => (path === '/' ? '/og.png' : `/_og${path}.png`) }; diff --git a/src/lib/server/cache.ts b/src/lib/server/cache.ts index 90347b2..00058b2 100644 --- a/src/lib/server/cache.ts +++ b/src/lib/server/cache.ts @@ -83,7 +83,7 @@ function purgeExpired(): void { let storageReachable = true; export const isStorageHealthy = () => storageReachable; -function isFresh(fetchedAt: Date, ttl: number): boolean { +export function isFresh(fetchedAt: Date, ttl: number): boolean { return Date.now() - fetchedAt.getTime() < ttl * 1000; } diff --git a/src/lib/server/github/repo.ts b/src/lib/server/github/repo.ts index da12e37..7c20cc7 100644 --- a/src/lib/server/github/repo.ts +++ b/src/lib/server/github/repo.ts @@ -1,6 +1,6 @@ import { graphql } from '$lib/server/github/client'; import { REPO_FIELDS, mapRepo, type RawRepo } from '$lib/server/github/user'; -import { cached } from '$lib/server/cache'; +import { cached, isFresh, readCached } from '$lib/server/cache'; import { AppError } from '$lib/utils/errors'; import type { Repo } from '$lib/types'; @@ -46,6 +46,12 @@ export async function getRepo(owner: string, name: string): Promise return repo; } +// Fresh cached header data only, never fetching, so a repo gone private drops out with its TTL +export async function peekRepo(owner: string, name: string): Promise { + const stored = await readCached<{ repo: Repo | null }>(repoKey(owner, name)); + return stored && isFresh(stored.fetchedAt, stored.ttl) ? stored.value.repo : null; +} + // Resolve a repo without exposing private repos to other or anonymous viewers export async function requireRepo( owner: string, diff --git a/src/lib/server/github/user.ts b/src/lib/server/github/user.ts index e8228d9..fe0af98 100644 --- a/src/lib/server/github/user.ts +++ b/src/lib/server/github/user.ts @@ -476,6 +476,12 @@ export async function getUserOverview(login: string): Promise { return toOverview(stored.value); } +// The cached profile only, never syncing, null until someone has loaded the overview +export async function peekUserProfile(login: string): Promise { + const stored = await readCached(overviewKey(login)); + return stored ? mapProfile(stored.value.owner, stored.value.owned.nodes.map(mapRepo)) : null; +} + // blocking sync of every owned repo, for callers that need live counts export async function refreshUserOverview(login: string): Promise { // joining a shallow sync already in flight would skip the rewalk diff --git a/src/lib/server/og/card.test.ts b/src/lib/server/og/card.test.ts new file mode 100644 index 0000000..687a1d6 --- /dev/null +++ b/src/lib/server/og/card.test.ts @@ -0,0 +1,61 @@ +import { describe, it, expect } from 'vitest'; +import { cleanText, defaultCard, pageCard, type OgNode } from './card'; + +// Every node in a card tree, depth first, so tests check what actually renders +function nodes(node: OgNode | string): (OgNode | string)[] { + if (typeof node === 'string') return [node]; + return [node, ...((node.props.children ?? []) as (OgNode | string)[]).flatMap(nodes)]; +} + +const texts = (card: OgNode) => nodes(card).filter((node) => typeof node === 'string'); +const dots = (card: OgNode) => + nodes(card).filter((node) => typeof node !== 'string' && node.type === 'circle').length; + +describe('cleanText', () => { + it('drops emoji, flags, keycaps and joined sequences', () => { + expect(cleanText('🚀 Fast ✨ flag 🇬🇧 key 1️⃣ family 👨‍👩‍👧 done')).toBe('Fast flag key family done'); + }); + + it('keeps accented latin and punctuation, drops scripts the font lacks', () => { + expect(cleanText('Café Ünïcödé, a/b (c) 你好 日本')).toBe('Café Ünïcödé, a/b (c)'); + }); + + it('returns empty for missing or undrawable text so callers can fall back', () => { + expect(cleanText(null)).toBe(''); + expect(cleanText('日本語のみ 🎉')).toBe(''); + }); +}); + +describe('cards', () => { + it('draws the full robot from the site logo', () => { + expect(dots(defaultCard())).toBe(441); + }); + + it('shows the repo identity, page trail and stats', () => { + const text = texts( + pageCard({ + trail: ['Info', 'Stats'], + owner: 'octocat', + name: 'hello-world', + description: 'My first repo', + avatar: null, + stats: [{ label: 'Stars', value: '1.2K' }] + }) + ); + expect(text).toEqual( + expect.arrayContaining(['octocat /', 'hello-world', 'My first repo', 'Info / Stats', '1.2K']) + ); + }); + + it('leaves out the stat row and avatar when nothing is cached', () => { + const card = pageCard({ + trail: ['Overview'], + name: 'octocat', + description: 'Profile summary', + avatar: null, + stats: [] + }); + expect(JSON.stringify(card)).not.toContain('"img"'); + expect(texts(card)).not.toContain('Stars'); + }); +}); diff --git a/src/lib/server/og/card.ts b/src/lib/server/og/card.ts new file mode 100644 index 0000000..7655e8c --- /dev/null +++ b/src/lib/server/og/card.ts @@ -0,0 +1,258 @@ +import logoSource from '$lib/components/common/Logo.svelte?raw'; +import { APP_NAME, APP_DESCRIPTION, OG_SIZE } from '$lib/config'; + +type Style = Record; +type Child = OgNode | string | null | undefined | false; +export type OgNode = { type: string; props: Record }; + +export type OgStat = { label: string; value: string; color?: string | null }; + +// Everything a page card shows, owner set means a repo card +export type OgView = { + trail: string[]; + owner?: string; + name: string; + subtitle?: string | null; + description: string; + avatar: string | null; + stats: OgStat[]; +}; + +// Dark theme tokens from layout.css, satori converts the oklch for the rasteriser +const COLOR = { + background: 'oklch(0.17 0.005 264)', + foreground: 'oklch(0.96 0.003 264)', + muted: 'oklch(0.255 0.006 264)', + mutedForeground: 'oklch(0.68 0.012 264)', + primary: 'oklch(0.68 0.13 248)', + border: 'oklch(1 0 0 / 9%)', + grid: 'oklch(1 0 0 / 7%)' +}; + +const PAD = 64; +const CONTENT_WIDTH = OG_SIZE.width - PAD * 2; +const CHAR_WIDTH = 0.6; +const USER_AVATAR = 200; +const USER_GAP = 48; +const FEATURES = ['Stats', 'Activity', 'CI/CD', 'Security']; + +// The robot dots straight from the site logo, recoloured with the same tokens +const ROBOT_FILL: Record = { + shell: COLOR.foreground, + screen: COLOR.muted, + dark: COLOR.mutedForeground, + accent: COLOR.primary +}; +const ROBOT_DOTS = [...logoSource.matchAll(/x="(\d+)" y="(\d+)" fill="var\(--robot-(\w+)\)"/g)].map( + ([, cx, cy, part]) => ({ type: 'circle', props: { cx, cy, r: 3.2, fill: ROBOT_FILL[part] } }) +); + +// Tiny element builder in the shape satori reads +const el = (type: string, style: Style, ...children: Child[]): OgNode => ({ + type, + props: { style, children: children.filter(Boolean) } +}); + +const robot = (height: number): OgNode => ({ + type: 'svg', + props: { + viewBox: '0 0 248 232', + width: Math.round((height * 248) / 232), + height, + children: ROBOT_DOTS + } +}); + +const avatarImage = (src: string, size: number, radius: number): OgNode => ({ + type: 'img', + props: { src, width: size, height: size, style: { borderRadius: radius } } +}); + +// Biggest font that fits a mono string on one line, wrapping below the floor +function fitSize(text: string, width: number, max: number, min = 48): number { + return Math.max(min, Math.min(max, Math.floor(width / (text.length * CHAR_WIDTH)))); +} + +// Emoji and scripts Geist Mono can't draw, which would otherwise render as tofu +const UNDRAWABLE = + /\p{RGI_Emoji}|\p{Extended_Pictographic}|[^\p{Script=Latin}\p{Script=Common}\p{Script=Inherited}]/gv; + +export function cleanText(text: string | null | undefined): string { + return (text ?? '').replace(UNDRAWABLE, '').replace(/\s+/g, ' ').trim(); +} + +const pill = (text: string) => + el( + 'div', + { + display: 'flex', + padding: '8px 18px', + border: `2px solid ${COLOR.border}`, + borderRadius: 999, + color: COLOR.primary, + fontSize: 22, + textTransform: 'uppercase', + letterSpacing: 2 + }, + text + ); + +// Muted copy that ellipses after a few lines +const clamp = (text: string, fontSize: number, lines: number) => + el( + 'div', + { + display: 'block', + width: '100%', + fontSize, + lineHeight: 1.4, + color: COLOR.mutedForeground, + lineClamp: lines + }, + text + ); + +const headline = (text: string, fontSize: number) => + el( + 'div', + { fontSize, fontWeight: 800, letterSpacing: '-0.03em', lineHeight: 1, wordBreak: 'break-all' }, + text + ); + +// One big number over its label, with an optional colour dot +const stat = ({ label, value, color }: OgStat) => + el( + 'div', + { display: 'flex', flexDirection: 'column', gap: 4 }, + el( + 'div', + { display: 'flex', alignItems: 'center', gap: 14, fontSize: 44, fontWeight: 800 }, + color && el('div', { width: 22, height: 22, borderRadius: 999, backgroundColor: color }), + value + ), + el( + 'div', + { fontSize: 20, color: COLOR.mutedForeground, textTransform: 'uppercase', letterSpacing: 2 }, + label + ) + ); + +// Dot grid canvas with the primary bar along the bottom, shared by every card +const frame = (...children: Child[]) => + el( + 'div', + { + width: '100%', + height: '100%', + boxSizing: 'border-box', + display: 'flex', + flexDirection: 'column', + padding: `56px ${PAD}px ${PAD}px`, + backgroundColor: COLOR.background, + backgroundImage: `radial-gradient(circle at 50% 50%, ${COLOR.grid} 10%, transparent 12%)`, + backgroundSize: '28px 28px', + color: COLOR.foreground, + fontFamily: 'Geist Mono', + fontSize: 28 + }, + ...children, + el('div', { + position: 'absolute', + left: 0, + right: 0, + bottom: 0, + height: 10, + backgroundColor: COLOR.primary + }) + ); + +// Site-wide card for the homepage and anything without its own +export function defaultCard(): OgNode { + const [first, second] = APP_NAME.split('-'); + return frame( + el( + 'div', + { display: 'flex', flexGrow: 1, alignItems: 'center', justifyContent: 'space-between' }, + el( + 'div', + { display: 'flex', flexDirection: 'column', gap: 28, width: 640 }, + el( + 'div', + { + display: 'flex', + flexDirection: 'column', + fontSize: 104, + fontWeight: 800, + letterSpacing: '-0.04em', + lineHeight: 0.95 + }, + el('div', { color: COLOR.mutedForeground }, `${first}-`), + el('div', {}, second) + ), + el('div', { width: 120, height: 10, backgroundColor: COLOR.primary }), + clamp(APP_DESCRIPTION, 34, 3), + el('div', { display: 'flex', gap: 12 }, ...FEATURES.map(pill)) + ), + robot(380) + ) + ); +} + +// A user or repo card, brand and page up top, identity in the middle, stats along the bottom +export function pageCard(view: OgView): OgNode { + const identity = view.owner + ? el( + 'div', + { display: 'flex', flexDirection: 'column', gap: 20 }, + el( + 'div', + { + display: 'flex', + alignItems: 'center', + gap: 20, + fontSize: 36, + color: COLOR.mutedForeground + }, + view.avatar && avatarImage(view.avatar, 56, 12), + `${view.owner} /` + ), + headline(view.name, fitSize(view.name, CONTENT_WIDTH, 96)), + clamp(view.description, 30, 2) + ) + : el( + 'div', + { display: 'flex', alignItems: 'center', gap: USER_GAP }, + view.avatar && avatarImage(view.avatar, USER_AVATAR, 28), + el( + 'div', + { display: 'flex', flexDirection: 'column', gap: 12, flex: 1 }, + headline( + view.name, + fitSize(view.name, CONTENT_WIDTH - (view.avatar ? USER_AVATAR + USER_GAP : 0), 96) + ), + view.subtitle && + el('div', { fontSize: 36, lineClamp: 1, display: 'block' }, view.subtitle), + clamp(view.description, 28, 2) + ) + ); + + return frame( + el( + 'div', + { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, + el( + 'div', + { display: 'flex', alignItems: 'center', gap: 16, fontWeight: 600 }, + robot(44), + APP_NAME + ), + pill(view.trail.join(' / ')) + ), + el( + 'div', + { display: 'flex', flexDirection: 'column', flexGrow: 1, justifyContent: 'center' }, + identity + ), + view.stats.length > 0 && el('div', { display: 'flex', gap: 64 }, ...view.stats.map(stat)) + ); +} diff --git a/src/lib/server/og/render.ts b/src/lib/server/og/render.ts new file mode 100644 index 0000000..548aecc --- /dev/null +++ b/src/lib/server/og/render.ts @@ -0,0 +1,45 @@ +import satori, { type Font } from 'satori'; +import { Resvg } from '@resvg/resvg-js'; +import { read } from '$app/server'; +import { OG_SIZE } from '$lib/config'; +import regular from '@fontsource/geist-mono/files/geist-mono-latin-400-normal.woff'; +import regularExt from '@fontsource/geist-mono/files/geist-mono-latin-ext-400-normal.woff'; +import semibold from '@fontsource/geist-mono/files/geist-mono-latin-600-normal.woff'; +import semiboldExt from '@fontsource/geist-mono/files/geist-mono-latin-ext-600-normal.woff'; +import extrabold from '@fontsource/geist-mono/files/geist-mono-latin-800-normal.woff'; +import extraboldExt from '@fontsource/geist-mono/files/geist-mono-latin-ext-800-normal.woff'; +import type { OgNode } from './card'; + +// Static Geist Mono cuts, satori can't read the variable woff2 the site uses +const FONT_FILES = [ + [400, regular], + [400, regularExt], + [600, semibold], + [600, semiboldExt], + [800, extrabold], + [800, extraboldExt] +] as const; + +let fonts: Promise | undefined; + +// Read the font files once per server instance +function loadFonts(): Promise { + fonts ??= Promise.all( + FONT_FILES.map(async ([weight, file]) => ({ + name: 'Geist Mono', + weight, + style: 'normal' as const, + data: await read(file).arrayBuffer() + })) + ); + return fonts; +} + +// Lay a card out with satori, then rasterise it to a png response +export async function renderOg(card: OgNode, cacheControl: string): Promise { + const svg = await satori(card, { ...OG_SIZE, fonts: await loadFonts() }); + const png = new Resvg(svg, { font: { loadSystemFonts: false } }).render().asPng(); + return new Response(new Uint8Array(png), { + headers: { 'content-type': 'image/png', 'cache-control': cacheControl } + }); +} diff --git a/src/lib/server/og/target.test.ts b/src/lib/server/og/target.test.ts new file mode 100644 index 0000000..c68115c --- /dev/null +++ b/src/lib/server/og/target.test.ts @@ -0,0 +1,70 @@ +import { describe, it, expect } from 'vitest'; +import { readdirSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { resolveOgTarget } from './target'; +import { BUCKET_BY_SECTION } from '$lib/config/tasks'; + +const labels = (path: string) => resolveOgTarget(path)?.trail.map((page) => page.label); + +// Every real page route under a user, as a sample path with params filled in +function routePaths(): string[] { + const root = 'src/routes/[user=login]'; + const files = readdirSync(root, { recursive: true, encoding: 'utf8' }); + return files + .filter((file) => file.endsWith('+page.svelte')) + .flatMap((file) => { + const route = join('octocat', dirname(file)) + .replace('/(user)', '') + .replace('[repo=repo]', 'hello-world'); + if (!route.includes('[list=taskList]')) return [route]; + return Object.keys(BUCKET_BY_SECTION).map((list) => route.replace('[list=taskList]', list)); + }); +} + +describe('resolveOgTarget', () => { + it('resolves user pages, including task lists', () => { + expect(resolveOgTarget('octocat')).toMatchObject({ user: 'octocat' }); + expect(resolveOgTarget('octocat')?.repo).toBeUndefined(); + expect(labels('octocat')).toEqual(['Overview']); + expect(labels('octocat/stats')).toEqual(['Stats']); + expect(labels('octocat/tasks/my-prs')).toEqual(['Issues & PRs', 'PRs submitted']); + }); + + it('resolves repo pages and their section children', () => { + expect(resolveOgTarget('octocat/hello-world')).toMatchObject({ + user: 'octocat', + repo: 'hello-world' + }); + expect(labels('octocat/hello-world')).toEqual(['Overview']); + expect(labels('octocat/hello-world/code')).toEqual(['Code']); + expect(labels('octocat/hello-world/info/security')).toEqual(['Info', 'Security']); + }); + + it('prefers user pages, falling back to a repo named like one, like the router does', () => { + expect(resolveOgTarget('octocat/stats')?.repo).toBeUndefined(); + expect(resolveOgTarget('octocat/stats/info/stats')).toMatchObject({ repo: 'stats' }); + expect(labels('octocat/tasks/tasks/issues')).toEqual(['Issues & PRs', 'Issues']); + expect(resolveOgTarget('octocat/web-check.xyz')?.repo).toBe('web-check.xyz'); + }); + + it('rejects bad logins, repos and unknown pages', () => { + for (const path of [ + '', + '-octocat', + 'octo_cat', + 'octocat/..', + 'octocat/hello-world/nope', + 'octocat/hello-world/info/nope', + 'octocat/hello-world/info/stats/extra', + 'octocat/stats/extra' + ]) { + expect(resolveOgTarget(path), path).toBeNull(); + } + }); + + it('covers every page route so no page shares a broken card', () => { + const paths = routePaths(); + expect(paths.length).toBeGreaterThan(20); + for (const path of paths) expect(resolveOgTarget(path), path).not.toBeNull(); + }); +}); diff --git a/src/lib/server/og/target.ts b/src/lib/server/og/target.ts new file mode 100644 index 0000000..ce932d8 --- /dev/null +++ b/src/lib/server/og/target.ts @@ -0,0 +1,24 @@ +import { USER_PAGES, REPO_PAGES, type PageDef } from '$lib/config/pages'; +import { LOGIN_RE, REPO_RE } from '$lib/utils/github-input'; + +// Who a card is for and the registry pages it shows, outermost first +export type OgTarget = { user: string; repo?: string; trail: PageDef[] }; + +// Registry pages named by the segments under a scope, null when they aren't a page +function findTrail(pages: PageDef[], [slug = '', childSlug, ...extra]: string[]): PageDef[] | null { + const section = pages.find((page) => page.slug === slug); + const child = section?.children?.find((page) => page.slug === childSlug); + if (!section || extra.length || (childSlug !== undefined && !child)) return null; + return child ? [section, child] : [section]; +} + +// Map a page path onto its scope and pages, user pages first then repo pages, like the router +export function resolveOgTarget(path: string): OgTarget | null { + const [user, ...segments] = path.split('/'); + if (!LOGIN_RE.test(user)) return null; + const userTrail = findTrail(USER_PAGES, segments); + if (userTrail) return { user, trail: userTrail }; + const [repo = '', ...rest] = segments; + const repoTrail = REPO_RE.test(repo) ? findTrail(REPO_PAGES, rest) : null; + return repoTrail && { user, repo, trail: repoTrail }; +} diff --git a/src/lib/server/og/view.ts b/src/lib/server/og/view.ts new file mode 100644 index 0000000..1174fec --- /dev/null +++ b/src/lib/server/og/view.ts @@ -0,0 +1,81 @@ +import { canViewRepo, peekRepo } from '$lib/server/github/repo'; +import { peekUserProfile } from '$lib/server/github/user'; +import { githubAvatar } from '$lib/config'; +import { compactNumber } from '$lib/utils/format'; +import { rootReason } from '$lib/utils/errors'; +import { createLogger } from '$lib/utils/logger'; +import { cleanText, type OgStat, type OgView } from './card'; +import type { OgTarget } from './target'; + +const log = createLogger('og'); +const AVATAR_PX = 400; +const AVATAR_TIMEOUT_MS = 3000; +const AVATAR_TYPES = new Set(['image/png', 'image/jpeg']); + +// Avatar inlined as a data uri, null when GitHub is slow or sends something satori can't draw +async function avatarData(login: string): Promise { + try { + const response = await fetch(githubAvatar(login, AVATAR_PX), { + signal: AbortSignal.timeout(AVATAR_TIMEOUT_MS) + }); + const type = response.headers.get('content-type') ?? ''; + if (!response.ok || !AVATAR_TYPES.has(type)) return null; + return `data:${type};base64,${Buffer.from(await response.arrayBuffer()).toString('base64')}`; + } catch (error) { + log.warn(`avatar fetch failed for ${login}`, { reason: rootReason(error) }); + return null; + } +} + +// A cache miss or storage blip just means a card without stats +function peek(what: string, read: Promise): Promise { + return read.catch((error) => { + log.warn(`${what} cache read failed`, { reason: rootReason(error) }); + return null; + }); +} + +// Card data from the cache only, seen as an anonymous viewer so private repos never leak +export async function loadOgView(target: OgTarget): Promise<{ view: OgView; cached: boolean }> { + const { user, repo: repoName, trail } = target; + const page = trail.at(-1)!; + const isRoot = page.slug === ''; + const base = { trail: trail.map((entry) => entry.label), description: page.description }; + + if (repoName) { + const [peeked, avatar] = await Promise.all([ + peek(`repo ${user}/${repoName}`, peekRepo(user, repoName)), + avatarData(user) + ]); + const repo = peeked && canViewRepo(peeked, null) ? peeked : null; + const stats: OgStat[] = repo + ? [ + { label: 'Stars', value: compactNumber(repo.stars) }, + { label: 'Forks', value: compactNumber(repo.forks) }, + { label: 'Issues', value: compactNumber(repo.openIssues) }, + ...(repo.language + ? [{ label: 'Language', value: repo.language.name, color: repo.language.color }] + : []) + ] + : []; + const description = (isRoot && cleanText(repo?.description)) || base.description; + const view = { ...base, owner: user, name: repo?.name ?? repoName, description, avatar, stats }; + return { view, cached: !!repo }; + } + + const [profile, avatar] = await Promise.all([ + peek(`profile ${user}`, peekUserProfile(user)), + avatarData(user) + ]); + const stats: OgStat[] = profile + ? [ + ...(profile.isOrg ? [] : [{ label: 'Followers', value: compactNumber(profile.followers) }]), + { label: 'Repos', value: compactNumber(profile.repoCount) }, + { label: 'Stars', value: compactNumber(profile.totalStars) } + ] + : []; + const description = (isRoot && cleanText(profile?.bio)) || base.description; + const subtitle = cleanText(profile?.name) || null; + const view = { ...base, name: profile?.login ?? user, subtitle, description, avatar, stats }; + return { view, cached: !!profile }; +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 27e0559..bb000ed 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,8 +1,9 @@ - +
diff --git a/src/routes/[user=login]/[repo=repo]/+page.svelte b/src/routes/[user=login]/[repo=repo]/+page.svelte index ca7fa67..5140148 100644 --- a/src/routes/[user=login]/[repo=repo]/+page.svelte +++ b/src/routes/[user=login]/[repo=repo]/+page.svelte @@ -16,6 +16,7 @@ Package } from '@lucide/svelte'; import SectionHeading from '$lib/components/common/SectionHeading.svelte'; + import PageMeta from '$lib/components/common/PageMeta.svelte'; import AsyncPanel from '$lib/components/common/AsyncPanel.svelte'; import Panel from '$lib/components/common/Panel.svelte'; import EmptyState from '$lib/components/common/EmptyState.svelte'; @@ -51,7 +52,7 @@ import { treeSizeSlices } from '$lib/views/repo-tree'; import { deploymentMiniChart } from '$lib/views/repo-deployments'; import { releaseDownloadBars, hasReleaseDownloads } from '$lib/views/repo-stats'; - import { paths, APP_NAME } from '$lib/config'; + import { paths } from '$lib/config'; import { findPage, REPO_PAGES } from '$lib/config/pages'; import { iconFor } from '$lib/components/layout/nav'; import { restrictedGate } from '$lib/config/status'; @@ -93,13 +94,10 @@ }); - - {data.repo.nameWithOwner} · {APP_NAME} - - + {#snippet totalMini(kind: 'issue' | 'pr', unit: string, title: string, icon: typeof CircleDot)} diff --git a/src/routes/[user=login]/[repo=repo]/ops/pages/+page.svelte b/src/routes/[user=login]/[repo=repo]/ops/pages/+page.svelte index 38b3a5e..2b8bdd1 100644 --- a/src/routes/[user=login]/[repo=repo]/ops/pages/+page.svelte +++ b/src/routes/[user=login]/[repo=repo]/ops/pages/+page.svelte @@ -19,7 +19,7 @@ import { STATUS_GLYPH } from '$lib/components/repo/status-glyph'; import type { RepoPages } from '$lib/types'; import { formatDateTime, formatDuration } from '$lib/utils/format'; - import { APP_NAME } from '$lib/config'; + import PageMeta from '$lib/components/common/PageMeta.svelte'; import type { PageData } from './$types'; import { revalidatingResult } from '$lib/state/revalidate.svelte'; @@ -71,9 +71,10 @@ } - - Pages · {data.repo.nameWithOwner} · {APP_NAME} - +
{#await pages.result} diff --git a/src/routes/_og/[...path]/+server.ts b/src/routes/_og/[...path]/+server.ts new file mode 100644 index 0000000..bc3eb04 --- /dev/null +++ b/src/routes/_og/[...path]/+server.ts @@ -0,0 +1,18 @@ +import { error } from '@sveltejs/kit'; +import { resolveOgTarget } from '$lib/server/og/target'; +import { loadOgView } from '$lib/server/og/view'; +import { pageCard } from '$lib/server/og/card'; +import { renderOg } from '$lib/server/og/render'; +import type { RequestHandler } from './$types'; + +// Cards with stats keep for an hour, bare ones retry soon in case the cache has warmed +const CACHE_FULL = 'public, max-age=3600, s-maxage=3600'; +const CACHE_BARE = 'public, max-age=300, s-maxage=300'; + +// Share card for any dashboard page, at /_og/.png +export const GET: RequestHandler = async ({ params }) => { + const target = params.path.endsWith('.png') ? resolveOgTarget(params.path.slice(0, -4)) : null; + if (!target) error(404, 'No share card for that page'); + const { view, cached } = await loadOgView(target); + return renderOg(pageCard(view), cached ? CACHE_FULL : CACHE_BARE); +}; diff --git a/src/routes/og.png/+server.ts b/src/routes/og.png/+server.ts new file mode 100644 index 0000000..709ac62 --- /dev/null +++ b/src/routes/og.png/+server.ts @@ -0,0 +1,8 @@ +import { defaultCard } from '$lib/server/og/card'; +import { renderOg } from '$lib/server/og/render'; +import type { RequestHandler } from './$types'; + +export const prerender = true; + +// Site-wide share card, baked to a static file at build time +export const GET: RequestHandler = () => renderOg(defaultCard(), 'public, max-age=86400'); diff --git a/static/robots.txt b/static/robots.txt index 513c024..ae5abcc 100644 --- a/static/robots.txt +++ b/static/robots.txt @@ -1,6 +1,19 @@ -# only the homepage is crawlable, the rest sits behind a bot check +# only the homepage and share cards are crawlable, the rest sits behind a bot check User-agent: * Allow: /$ Allow: /_app/ Allow: /logo.svg +Allow: /og.png +Allow: /_og/ Disallow: / + +# link preview bots read share tags off whatever page someone shared +User-agent: Twitterbot +User-agent: facebookexternalhit +User-agent: LinkedInBot +User-agent: Slackbot +User-agent: Discordbot +User-agent: TelegramBot +User-agent: WhatsApp +Disallow: /api/ +Allow: / From baee2012c65fc519e5a17d0432755be0fe5702e7 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 8 Nov 2026 21:53:17 +0000 Subject: [PATCH 2/2] Pins fflate to 0.7.5 to clear the audit flag from satori --- package-lock.json | 6 +++--- package.json | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 398c3c5..7900f5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5226,9 +5226,9 @@ } }, "node_modules/fflate": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.3.tgz", - "integrity": "sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw==", + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.5.tgz", + "integrity": "sha512-QieYf//cis6ywHNi5qW1+PXPQ4bC+XVJAtS4AXIML8P76GroEiOxm/oQtn1f02UkJY1+KsXMJcC+R2v/Eg4G3g==", "license": "MIT" }, "node_modules/file-entry-cache": { diff --git a/package.json b/package.json index 257da1d..509fdbb 100644 --- a/package.json +++ b/package.json @@ -61,5 +61,8 @@ "postgres": "^4.1.0", "satori": "^0.63.2", "zod": "^4.6.7" + }, + "overrides": { + "fflate": "^0.7.5" } }