From a5bc052aa1043fbdf6a23bb457d870cea2f05f8e Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 15 Nov 2026 22:47:38 +0300 Subject: [PATCH 1/2] feat(app): the card can leave out the picture and the name (#93) --- app/src/app/pages/[username].page.ts | 4 ++- app/src/app/profile/card-design.ts | 2 +- app/src/app/profile/card-identity.spec.ts | 15 ++++++++++ app/src/app/profile/card-identity.ts | 11 +++++++ app/src/app/profile/share.html | 16 ++++++++-- app/src/app/profile/share.ts | 29 +++++++++++++++---- app/src/server/card/card.ts | 16 +++++----- .../server/routes/[username]/card.png.get.ts | 8 +++-- app/vite.config.ts | 2 +- docs/ARCHITECTURE.md | 2 +- 10 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 app/src/app/profile/card-identity.spec.ts create mode 100644 app/src/app/profile/card-identity.ts diff --git a/app/src/app/pages/[username].page.ts b/app/src/app/pages/[username].page.ts index d513df0..cd06ea0 100644 --- a/app/src/app/pages/[username].page.ts +++ b/app/src/app/pages/[username].page.ts @@ -15,6 +15,7 @@ import { simpleBluesky, simpleFacebook, simpleGithub, simpleInstagram, simpleMastodon, simpleNpm, simpleReddit, simpleThreads, simpleTwitch, simpleX, simpleYoutube, } from '@ng-icons/simple-icons'; +import { identityQuery, parseCardIdentity } from '../profile/card-identity'; import { badgeQuery, parseBadgeOptions } from '../profile/card-badges'; import { BADGE_ICONS, earnedBadges } from '../profile/earned-badges'; import { BadgePill } from '../profile/badge-pill'; @@ -85,6 +86,7 @@ export default class Profile { /** The country the owner picked for the shared card, for this link's preview image. */ private readonly cardFlag = injectQueryParams(params => countryCode(params['flag'])); private readonly cardBadges = injectQueryParams(params => parseBadgeOptions(params['hide'], params['names'])); + private readonly cardIdentity = injectQueryParams(params => parseCardIdentity(params['avatar'], params['name'])); /** Every period is in the profile: switching period needs no request. */ protected readonly profile = injectSeededServerFn(getContributor, () => ({ username: this.username() })); @@ -237,7 +239,7 @@ export default class Profile { const { title, description } = profileHead(person, this.current(), this.period()); this.title.setTitle(`${title} · Angularians`); this.meta.removeTag('name="robots"'); - const cardQuery = shareQuery(this.period(), this.cardFlag(), badgeQuery(this.cardBadges())); + const cardQuery = shareQuery(this.period(), this.cardFlag(), { ...badgeQuery(this.cardBadges()), ...identityQuery(this.cardIdentity()) }); setShareMeta(this.meta, this.document, { title, description, diff --git a/app/src/app/profile/card-design.ts b/app/src/app/profile/card-design.ts index 016dd9a..05d80e1 100644 --- a/app/src/app/profile/card-design.ts +++ b/app/src/app/profile/card-design.ts @@ -1,2 +1,2 @@ /** Raise it when the card's design changes, so the preview does not show a copy the browser kept. */ -export const CARD_DESIGN = 18 +export const CARD_DESIGN = 19 diff --git a/app/src/app/profile/card-identity.spec.ts b/app/src/app/profile/card-identity.spec.ts new file mode 100644 index 0000000..ebf8160 --- /dev/null +++ b/app/src/app/profile/card-identity.spec.ts @@ -0,0 +1,15 @@ +import { identityQuery, parseCardIdentity } from './card-identity' + +describe('card identity options', () => { + it('shows the avatar and the name unless the query says off', () => { + expect(parseCardIdentity(undefined, undefined)).toEqual({ avatar: true, name: true }) + expect(parseCardIdentity(['off'], 'on')).toEqual({ avatar: true, name: true }) + expect(parseCardIdentity('off', 'off')).toEqual({ avatar: false, name: false }) + }) + + it('writes an option only when it is off', () => { + expect(identityQuery({ avatar: true, name: true })).toEqual({}) + expect(identityQuery({ avatar: false, name: true })).toEqual({ avatar: 'off' }) + expect(identityQuery({ avatar: true, name: false })).toEqual({ name: 'off' }) + }) +}) diff --git a/app/src/app/profile/card-identity.ts b/app/src/app/profile/card-identity.ts new file mode 100644 index 0000000..d270765 --- /dev/null +++ b/app/src/app/profile/card-identity.ts @@ -0,0 +1,11 @@ +export interface CardIdentity { + avatar: boolean + name: boolean +} + +export const parseCardIdentity = (avatar: unknown, name: unknown): CardIdentity => ({ avatar: avatar !== 'off', name: name !== 'off' }) + +export const identityQuery = ({ avatar, name }: CardIdentity): Record => ({ + ...(avatar ? {} : { avatar: 'off' }), + ...(name ? {} : { name: 'off' }), +}) diff --git a/app/src/app/profile/share.html b/app/src/app/profile/share.html index 1a86cad..8af1e9c 100644 --- a/app/src/app/profile/share.html +++ b/app/src/app/profile/share.html @@ -12,9 +12,19 @@ - @if (cardPeriods().length > 1) { - - } +
+ @if (cardPeriods().length > 1) { + + } +
+ + +
+

diff --git a/app/src/app/profile/share.ts b/app/src/app/profile/share.ts index c11170d..a077d7b 100644 --- a/app/src/app/profile/share.ts +++ b/app/src/app/profile/share.ts @@ -3,7 +3,7 @@ import { NgTemplateOutlet } from '@angular/common' import { Component, computed, input, linkedSignal, signal } from '@angular/core' import { periodPhrase, sortPeriods, type Period, COUNTRIES, countryName } from '@angularians/shared' import { NgIcon, provideIcons } from '@ng-icons/core' -import { remixCheckLine, remixDownloadLine, remixFileCopyLine, remixImageLine, remixLinkedinBoxFill, remixLinkM, remixMarkdownLine, remixShareLine } from '@ng-icons/remixicon' +import { remixCheckLine, remixDownloadLine, remixFileCopyLine, remixImageLine, remixLinkedinBoxFill, remixLinkM, remixMarkdownLine, remixShareLine, remixUserForbidLine, remixUserLine, remixEyeLine, remixEyeOffLine } from '@ng-icons/remixicon' import { simpleBluesky, simpleX } from '@ng-icons/simple-icons' import { HlmButton } from '@spartan-ng/helm/button' import { HlmDialogImports } from '@spartan-ng/helm/dialog' @@ -13,6 +13,7 @@ import { HlmSkeleton } from '@spartan-ng/helm/skeleton' import { SITE_URL } from '../site' import { shareQuery } from './share-query' import { CardBadgeOptions } from './card-badge-options' +import { identityQuery } from './card-identity' import { badgeQuery, type BadgeNameStyle } from './card-badges' import { CARD_DESIGN } from './card-design' import type { EarnedBadge } from './earned-badges' @@ -30,7 +31,7 @@ export const SHARE_BUTTONS = { link: 'Copy profile link', card: 'Share card', re @Component({ selector: 'app-share', imports: [CardBadgeOptions, CountrySelect, HlmButton, HlmDialogImports, HlmSkeleton, NgIcon, NgTemplateOutlet, PeriodTabs], - providers: [provideIcons({ remixCheckLine, remixDownloadLine, remixFileCopyLine, remixImageLine, remixLinkedinBoxFill, remixShareLine, simpleBluesky, simpleX, remixLinkM, remixMarkdownLine })], + providers: [provideIcons({ remixCheckLine, remixDownloadLine, remixFileCopyLine, remixImageLine, remixLinkedinBoxFill, remixShareLine, simpleBluesky, simpleX, remixLinkM, remixMarkdownLine, remixUserForbidLine, remixUserLine, remixEyeLine, remixEyeOffLine })], templateUrl: './share.html', styleUrl: './share.css', }) @@ -62,6 +63,10 @@ export class Share { protected readonly flag = signal(null) protected readonly hiddenBadges = signal([]) protected readonly names = signal('fun') + protected readonly showAvatar = signal(true) + protected readonly showName = signal(true) + protected readonly avatarLabel = computed(() => (this.showAvatar() ? 'Hide picture' : 'Show picture')) + protected readonly nameLabel = computed(() => (this.showName() ? 'Hide name' : 'Show name')) protected readonly allCountries = Object.keys(COUNTRIES).map(code => ({ code, count: 0, top: [] })) protected readonly name = countryName protected readonly flagLabel = computed(() => { @@ -70,13 +75,13 @@ export class Share { }) protected readonly cardPeriods = computed(() => sortPeriods(['all', ...this.periods()])) - private readonly badgeOptions = computed(() => badgeQuery({ hidden: this.hiddenBadges(), names: this.names() })) + private readonly cardOptions = computed(() => ({ ...badgeQuery({ hidden: this.hiddenBadges(), names: this.names() }), ...identityQuery({ avatar: this.showAvatar(), name: this.showName() }) })) private readonly profileUrl = computed(() => `${SITE_URL}/${this.username()}${shareQuery(this.period())}`) /** The profile with the card's period and flag: what a post links to, and the README card's link. */ - private readonly cardProfileUrl = computed(() => `${SITE_URL}/${this.username()}${shareQuery(this.cardPeriod(), this.flag(), this.badgeOptions())}`) - private readonly cardUrl = computed(() => `${SITE_URL}/${this.username()}/card.png${shareQuery(this.cardPeriod(), this.flag(), this.badgeOptions())}`) + private readonly cardProfileUrl = computed(() => `${SITE_URL}/${this.username()}${shareQuery(this.cardPeriod(), this.flag(), this.cardOptions())}`) + private readonly cardUrl = computed(() => `${SITE_URL}/${this.username()}/card.png${shareQuery(this.cardPeriod(), this.flag(), this.cardOptions())}`) /** The same card from this site: right on a preview deploy or locally too. The Markdown keeps the public address. */ - protected readonly previewUrl = computed(() => `/${this.username()}/card.png${shareQuery(this.cardPeriod(), this.flag(), { v: String(CARD_DESIGN), ...this.badgeOptions() })}`) + protected readonly previewUrl = computed(() => `/${this.username()}/card.png${shareQuery(this.cardPeriod(), this.flag(), { v: String(CARD_DESIGN), ...this.cardOptions() })}`) protected readonly fileName = computed(() => `${this.username()}-angularian${this.cardPeriod() === 'all' ? '' : `-${this.cardPeriod()}`}.png`) /** The profile's link preview is this card, so a post only needs the link. */ protected readonly shareLinks = computed(() => { @@ -104,6 +109,8 @@ export class Share { this.flag.set(null) this.hiddenBadges.set([]) this.names.set('fun') + this.showAvatar.set(true) + this.showName.set(true) this.shownUrl.set(null) this.startLoading() } @@ -120,6 +127,16 @@ export class Share { this.startLoading() } + protected toggleAvatar(): void { + this.showAvatar.update(shown => !shown) + this.startLoading() + } + + protected toggleName(): void { + this.showName.update(shown => !shown) + this.startLoading() + } + protected showLoadedCard(url: string): void { clearTimeout(this.loadedTimer) this.loadedTimer = setTimeout(() => { diff --git a/app/src/server/card/card.ts b/app/src/server/card/card.ts index faf26e8..1383e66 100644 --- a/app/src/server/card/card.ts +++ b/app/src/server/card/card.ts @@ -105,8 +105,8 @@ export function cardPeriod(profile: ContributorProfile, requested: unknown): Per return period !== 'all' && profile.periods.some(row => row.period === period) ? period : 'all' } -/** `avatar`: a data URL, or `null` when GitHub did not send it (a grey circle instead). */ -export function cardTree(profile: ContributorProfile, period: Period, avatar: string | null, flag: { src: string, name: string } | null = null, tags: readonly CardTag[] = []): Node { +/** `avatar`: a data URL, `null` when GitHub did not send it (a grey circle instead), or `false` when the owner left it off. */ +export function cardTree(profile: ContributorProfile, period: Period, avatar: string | null | false, flag: { src: string, name: string } | null = null, tags: readonly CardTag[] = [], showName = true): Node { const tiles = !tags.length ? TILES : tags.some(tag => tag.row === 3) ? TILES_WITH_THREE_ROWS : TILES_WITH_TAGS const stats = period === 'all' ? profile : profile.periods.find(row => row.period === period)! const since = profile.firstContributionAt ? formatMonth(profile.firstContributionAt) : null @@ -122,13 +122,13 @@ export function cardTree(profile: ContributorProfile, period: Period, avatar: st ] return h('div', { width: '100%', height: '100%', flexDirection: 'column', justifyContent: 'space-between', backgroundColor: '#0a0a0a', color: '#ffffff', paddingTop: 44, paddingRight: 64, paddingBottom: 36, paddingLeft: 64, fontFamily: 'Manrope' }, [ h('div', { flexDirection: 'row', gap: 64 }, [ - h('div', { flexDirection: 'column', width: 380 }, [ - avatar + h('div', { flexDirection: 'column', width: 380, justifyContent: avatar === false || !showName ? 'center' : 'flex-start' }, [ + ...(avatar === false ? [] : [avatar ? h('img', { width: 108, height: 108, borderRadius: 9999, border: '4px solid #262626' }, undefined, { src: avatar, width: 108, height: 108 }) - : h('div', { width: 108, height: 108, borderRadius: 9999, backgroundColor: '#262626' }), - h('div', { fontSize: 40, fontWeight: 600, marginTop: 12, maxWidth: 380, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, profile.username), - h('div', { fontFamily: 'Norse', fontWeight: 700, fontSize: 84, lineHeight: 1, letterSpacing: 2, color: BRAND, marginTop: 6 }, formatRank(period === 'all' ? profile.rank : stats.rank)), - h('div', { fontSize: 30, fontWeight: 600, color: BRAND, marginTop: 4 }, formatPoints(stats.score)), + : h('div', { width: 108, height: 108, borderRadius: 9999, backgroundColor: '#262626' })]), + ...(showName ? [h('div', { fontSize: 40, fontWeight: 600, marginTop: avatar === false ? 0 : 12, maxWidth: 380, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, profile.username)] : []), + h('div', { fontFamily: 'Norse', fontWeight: 700, fontSize: avatar === false && !showName ? 128 : 84, lineHeight: 1, letterSpacing: 2, color: BRAND, marginTop: showName ? 6 : avatar === false ? 0 : 12 }, formatRank(period === 'all' ? profile.rank : stats.rank)), + h('div', { fontSize: avatar === false && !showName ? 36 : 30, fontWeight: 600, color: BRAND, marginTop: 4 }, formatPoints(stats.score)), ...(period !== 'all' ? [h('div', { fontSize: 24, color: '#a3a3a3', marginTop: 4 }, periodPhrase(period))] : []), ...(flag ? [h('div', { flexDirection: 'row', alignItems: 'center', gap: 10, marginTop: period === 'all' ? 10 : 4, fontSize: 24, color: '#a3a3a3' }, [ h('img', { width: 30, height: 30 }, undefined, { src: flag.src, width: 30, height: 30 }), diff --git a/app/src/server/routes/[username]/card.png.get.ts b/app/src/server/routes/[username]/card.png.get.ts index 9824787..158a20d 100644 --- a/app/src/server/routes/[username]/card.png.get.ts +++ b/app/src/server/routes/[username]/card.png.get.ts @@ -2,6 +2,7 @@ import { sendPng } from '../../data/http' import { createError, defineEventHandler, getQuery, getRouterParam } from 'h3' import * as v from 'valibot' import { countryCode, countryName } from '@angularians/shared' +import { parseCardIdentity } from '../../../app/profile/card-identity' import { parseBadgeOptions } from '../../../app/profile/card-badges' import { avatarData, cardFonts, flagData } from '../../card/assets' import { cardBadgeTags } from '../../card/badges' @@ -10,7 +11,7 @@ import { UsernameSchema } from '../../data/schemas' import { contributorsData } from '../../data/store' /** - * `GET /:username/card.png?period=2025&flag=TR`: the Angularian card, for GitHub profile READMEs and the profile's link + * `GET /:username/card.png?period=2025&flag=TR&avatar=off&name=off`: the Angularian card, for GitHub profile READMEs and the profile's link * preview. The URL never changes; the numbers do, every night. */ export default defineEventHandler(async (event) => { @@ -22,8 +23,9 @@ export default defineEventHandler(async (event) => { const period = cardPeriod(profile, getQuery(event)['period']) // `?flag=TR`: the country the owner picked for this card. Otherwise their GitHub location. const code = countryCode(getQuery(event)['flag']) ?? profile.country ?? null - const [avatar, flagSrc, fonts, tags] = await Promise.all([avatarData(profile.githubId), code ? flagData(code) : null, cardFonts(), cardBadgeTags(profile, parseBadgeOptions(getQuery(event)['hide'], getQuery(event)['names']))]) - const png = await renderCard(cardTree(profile, period, avatar, code && flagSrc ? { src: flagSrc, name: countryName(code) } : null, tags), fonts) + const identity = parseCardIdentity(getQuery(event)['avatar'], getQuery(event)['name']) + const [avatar, flagSrc, fonts, tags] = await Promise.all([identity.avatar ? avatarData(profile.githubId) : false as const, code ? flagData(code) : null, cardFonts(), cardBadgeTags(profile, parseBadgeOptions(getQuery(event)['hide'], getQuery(event)['names']))]) + const png = await renderCard(cardTree(profile, period, avatar, code && flagSrc ? { src: flagSrc, name: countryName(code) } : null, tags, identity.name), fonts) // A day in shared caches (GitHub's image proxy too): each night's deploy clears the CDN. return sendPng(event, png) }) diff --git a/app/vite.config.ts b/app/vite.config.ts index 6f0142f..89ca235 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -82,7 +82,7 @@ export default defineConfig(() => ({ // country). Any other one (`?utm_source=`) shares the page's copy. A route reading a new parameter must add it here. // and per value of the signed-in hint cookie (app/src/app/auth/hint.ts), whose pages start with the signed-in // card's skeleton. Every other cookie is ignored by the cache. - '/**': { headers: { 'cache-control': 'public, max-age=0, s-maxage=86400, stale-while-revalidate=86400', 'netlify-cdn-cache-control': 'public, durable, s-maxage=86400, stale-while-revalidate=86400', 'netlify-vary': 'query=period|country|badges|match|page|q|flag|hide|names|v,cookie=angularians-signed-in' } }, + '/**': { headers: { 'cache-control': 'public, max-age=0, s-maxage=86400, stale-while-revalidate=86400', 'netlify-cdn-cache-control': 'public, durable, s-maxage=86400, stale-while-revalidate=86400', 'netlify-vary': 'query=period|country|badges|match|page|q|flag|hide|names|avatar|name|v,cookie=angularians-signed-in' } }, // Sign-in: per person, with cookies. Never in a shared cache. '/api/auth/**': { headers: { 'cache-control': 'private, no-store', 'netlify-cdn-cache-control': 'no-store' } }, // Server functions are POSTs whose input is in the body, which no cache key sees: never cached. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index c9ccf40..9334965 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -164,5 +164,5 @@ Signing in from the home page ends on your profile, or back on the home page if | `GET /api/contributors/:username` | A profile: all-time stats, rank in each period, links | | `GET /api/search/contributors?q=cris&country=TR` | Up to 8 contributors, of that country if given | | `GET /api/map/contributors?period=all` | Contributors by country, and every badge on the board with how many hold it in the period | -| `GET /:username/card.png?period=2025&flag=TR&hide=reviewer&names=official` | The Angularian card, 2400×1260: the README card and the profile's link preview. `names=official` swaps fun project titles for the project and role, `names=none` shows the badges as icons alone; `hide` is the badges the owner left out in the share dialog (`app/src/app/profile/card-badges.ts`), and the profile's own `?hide=` carries them to its link preview. Its flag is the GitHub location's country, or `flag` when the owner picked another; under its stats, the profile's badges as tags with their names, as many as fit in up to three rows (the stats shrink for a third) and the rest as icons alone, a language's own name in Manrope's Cyrillic and extended Latin or a small Noto font holding just its letters (`TAG_FONTS` in `app/src/server/card/tag-fonts.ts`) (`earnedBadges` in `app/src/app/profile/earned-badges.ts`, shared with the profile page; images from the `site-images` server asset) | +| `GET /:username/card.png?period=2025&flag=TR&hide=reviewer&names=official&avatar=off&name=off` | The Angularian card, 2400×1260: the README card and the profile's link preview. `avatar=off` and `name=off` leave the GitHub avatar and the username off (on a GitHub profile both already sit beside the README), and the profile's own `?avatar=off&name=off` carries them to its link preview. `names=official` swaps fun project titles for the project and role, `names=none` shows the badges as icons alone; `hide` is the badges the owner left out in the share dialog (`app/src/app/profile/card-badges.ts`), and the profile's own `?hide=` carries them to its link preview. Its flag is the GitHub location's country, or `flag` when the owner picked another; under its stats, the profile's badges as tags with their names, as many as fit in up to three rows (the stats shrink for a third) and the rest as icons alone, a language's own name in Manrope's Cyrillic and extended Latin or a small Noto font holding just its letters (`TAG_FONTS` in `app/src/server/card/tag-fonts.ts`) (`earnedBadges` in `app/src/app/profile/earned-badges.ts`, shared with the profile page; images from the `site-images` server asset) | | `GET /og.png?period=2025` | The home page's link preview, 2400×1260: all time, or the top of a period | From 60775d4cc0bb5224dfede9f2547a027339324196 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 15 Nov 2026 22:54:22 +0300 Subject: [PATCH 2/2] refactor(app): one card options module, username=off, plain toggle labels --- app/src/app/pages/[username].page.ts | 8 +++--- app/src/app/profile/card-identity.spec.ts | 14 +++++----- app/src/app/profile/card-identity.ts | 8 +++--- app/src/app/profile/card-options.spec.ts | 16 +++++++++++ app/src/app/profile/card-options.ts | 14 ++++++++++ app/src/app/profile/share.html | 6 ++--- app/src/app/profile/share.ts | 18 ++++++------- app/src/server/card/card.ts | 27 ++++++++++++++----- .../server/routes/[username]/card.png.get.ts | 11 ++++---- app/vite.config.ts | 2 +- docs/ARCHITECTURE.md | 2 +- 11 files changed, 83 insertions(+), 43 deletions(-) create mode 100644 app/src/app/profile/card-options.spec.ts create mode 100644 app/src/app/profile/card-options.ts diff --git a/app/src/app/pages/[username].page.ts b/app/src/app/pages/[username].page.ts index cd06ea0..1eaeef6 100644 --- a/app/src/app/pages/[username].page.ts +++ b/app/src/app/pages/[username].page.ts @@ -15,8 +15,7 @@ import { simpleBluesky, simpleFacebook, simpleGithub, simpleInstagram, simpleMastodon, simpleNpm, simpleReddit, simpleThreads, simpleTwitch, simpleX, simpleYoutube, } from '@ng-icons/simple-icons'; -import { identityQuery, parseCardIdentity } from '../profile/card-identity'; -import { badgeQuery, parseBadgeOptions } from '../profile/card-badges'; +import { cardOptionsQuery, parseCardOptions } from '../profile/card-options'; import { BADGE_ICONS, earnedBadges } from '../profile/earned-badges'; import { BadgePill } from '../profile/badge-pill'; import { injectParams } from 'ngxtension/inject-params'; @@ -85,8 +84,7 @@ export default class Profile { private readonly fromCountry = injectQueryParams(params => countryCode(params['country'])); /** The country the owner picked for the shared card, for this link's preview image. */ private readonly cardFlag = injectQueryParams(params => countryCode(params['flag'])); - private readonly cardBadges = injectQueryParams(params => parseBadgeOptions(params['hide'], params['names'])); - private readonly cardIdentity = injectQueryParams(params => parseCardIdentity(params['avatar'], params['name'])); + private readonly cardOptions = injectQueryParams(params => parseCardOptions(params)); /** Every period is in the profile: switching period needs no request. */ protected readonly profile = injectSeededServerFn(getContributor, () => ({ username: this.username() })); @@ -239,7 +237,7 @@ export default class Profile { const { title, description } = profileHead(person, this.current(), this.period()); this.title.setTitle(`${title} · Angularians`); this.meta.removeTag('name="robots"'); - const cardQuery = shareQuery(this.period(), this.cardFlag(), { ...badgeQuery(this.cardBadges()), ...identityQuery(this.cardIdentity()) }); + const cardQuery = shareQuery(this.period(), this.cardFlag(), cardOptionsQuery(this.cardOptions())); setShareMeta(this.meta, this.document, { title, description, diff --git a/app/src/app/profile/card-identity.spec.ts b/app/src/app/profile/card-identity.spec.ts index ebf8160..9d129d5 100644 --- a/app/src/app/profile/card-identity.spec.ts +++ b/app/src/app/profile/card-identity.spec.ts @@ -1,15 +1,15 @@ import { identityQuery, parseCardIdentity } from './card-identity' describe('card identity options', () => { - it('shows the avatar and the name unless the query says off', () => { - expect(parseCardIdentity(undefined, undefined)).toEqual({ avatar: true, name: true }) - expect(parseCardIdentity(['off'], 'on')).toEqual({ avatar: true, name: true }) - expect(parseCardIdentity('off', 'off')).toEqual({ avatar: false, name: false }) + it('shows the avatar and the username unless the query says off', () => { + expect(parseCardIdentity(undefined, undefined)).toEqual({ avatar: true, username: true }) + expect(parseCardIdentity(['off'], 'on')).toEqual({ avatar: true, username: true }) + expect(parseCardIdentity('off', 'off')).toEqual({ avatar: false, username: false }) }) it('writes an option only when it is off', () => { - expect(identityQuery({ avatar: true, name: true })).toEqual({}) - expect(identityQuery({ avatar: false, name: true })).toEqual({ avatar: 'off' }) - expect(identityQuery({ avatar: true, name: false })).toEqual({ name: 'off' }) + expect(identityQuery({ avatar: true, username: true })).toEqual({}) + expect(identityQuery({ avatar: false, username: true })).toEqual({ avatar: 'off' }) + expect(identityQuery({ avatar: true, username: false })).toEqual({ username: 'off' }) }) }) diff --git a/app/src/app/profile/card-identity.ts b/app/src/app/profile/card-identity.ts index d270765..abb0d83 100644 --- a/app/src/app/profile/card-identity.ts +++ b/app/src/app/profile/card-identity.ts @@ -1,11 +1,11 @@ export interface CardIdentity { avatar: boolean - name: boolean + username: boolean } -export const parseCardIdentity = (avatar: unknown, name: unknown): CardIdentity => ({ avatar: avatar !== 'off', name: name !== 'off' }) +export const parseCardIdentity = (avatar: unknown, username: unknown): CardIdentity => ({ avatar: avatar !== 'off', username: username !== 'off' }) -export const identityQuery = ({ avatar, name }: CardIdentity): Record => ({ +export const identityQuery = ({ avatar, username }: CardIdentity): Record => ({ ...(avatar ? {} : { avatar: 'off' }), - ...(name ? {} : { name: 'off' }), + ...(username ? {} : { username: 'off' }), }) diff --git a/app/src/app/profile/card-options.spec.ts b/app/src/app/profile/card-options.spec.ts new file mode 100644 index 0000000..2e5c750 --- /dev/null +++ b/app/src/app/profile/card-options.spec.ts @@ -0,0 +1,16 @@ +import { cardOptionsQuery, parseCardOptions } from './card-options' + +describe('card options', () => { + it('reads the badge and identity options from one query', () => { + expect(parseCardOptions({ hide: 'reviewer', names: 'official', avatar: 'off', username: 'off' })).toEqual({ + badges: { hidden: ['reviewer'], names: 'official' }, + identity: { avatar: false, username: false }, + }) + }) + + it('writes them back as the same query', () => { + const query = { hide: 'reviewer', names: 'official', avatar: 'off', username: 'off' } + expect(cardOptionsQuery(parseCardOptions(query))).toEqual(query) + expect(cardOptionsQuery(parseCardOptions({}))).toEqual({}) + }) +}) diff --git a/app/src/app/profile/card-options.ts b/app/src/app/profile/card-options.ts new file mode 100644 index 0000000..d57ca10 --- /dev/null +++ b/app/src/app/profile/card-options.ts @@ -0,0 +1,14 @@ +import { badgeQuery, parseBadgeOptions, type BadgeOptions } from './card-badges' +import { identityQuery, parseCardIdentity, type CardIdentity } from './card-identity' + +export interface CardOptions { + badges: BadgeOptions + identity: CardIdentity +} + +export const parseCardOptions = (query: Record): CardOptions => ({ + badges: parseBadgeOptions(query['hide'], query['names']), + identity: parseCardIdentity(query['avatar'], query['username']), +}) + +export const cardOptionsQuery = ({ badges, identity }: CardOptions): Record => ({ ...badgeQuery(badges), ...identityQuery(identity) }) diff --git a/app/src/app/profile/share.html b/app/src/app/profile/share.html index 8af1e9c..63cd091 100644 --- a/app/src/app/profile/share.html +++ b/app/src/app/profile/share.html @@ -17,11 +17,11 @@ }

- -
diff --git a/app/src/app/profile/share.ts b/app/src/app/profile/share.ts index a077d7b..1669d24 100644 --- a/app/src/app/profile/share.ts +++ b/app/src/app/profile/share.ts @@ -3,7 +3,7 @@ import { NgTemplateOutlet } from '@angular/common' import { Component, computed, input, linkedSignal, signal } from '@angular/core' import { periodPhrase, sortPeriods, type Period, COUNTRIES, countryName } from '@angularians/shared' import { NgIcon, provideIcons } from '@ng-icons/core' -import { remixCheckLine, remixDownloadLine, remixFileCopyLine, remixImageLine, remixLinkedinBoxFill, remixLinkM, remixMarkdownLine, remixShareLine, remixUserForbidLine, remixUserLine, remixEyeLine, remixEyeOffLine } from '@ng-icons/remixicon' +import { remixCheckLine, remixDownloadLine, remixEyeLine, remixEyeOffLine, remixFileCopyLine, remixImageLine, remixLinkedinBoxFill, remixLinkM, remixMarkdownLine, remixShareLine, remixUserForbidLine, remixUserLine } from '@ng-icons/remixicon' import { simpleBluesky, simpleX } from '@ng-icons/simple-icons' import { HlmButton } from '@spartan-ng/helm/button' import { HlmDialogImports } from '@spartan-ng/helm/dialog' @@ -13,9 +13,9 @@ import { HlmSkeleton } from '@spartan-ng/helm/skeleton' import { SITE_URL } from '../site' import { shareQuery } from './share-query' import { CardBadgeOptions } from './card-badge-options' -import { identityQuery } from './card-identity' -import { badgeQuery, type BadgeNameStyle } from './card-badges' +import type { BadgeNameStyle } from './card-badges' import { CARD_DESIGN } from './card-design' +import { cardOptionsQuery } from './card-options' import type { EarnedBadge } from './earned-badges' /** The skeleton shows at least this long, so a fast card does not flicker it. */ @@ -64,9 +64,9 @@ export class Share { protected readonly hiddenBadges = signal([]) protected readonly names = signal('fun') protected readonly showAvatar = signal(true) - protected readonly showName = signal(true) + protected readonly showUsername = signal(true) protected readonly avatarLabel = computed(() => (this.showAvatar() ? 'Hide picture' : 'Show picture')) - protected readonly nameLabel = computed(() => (this.showName() ? 'Hide name' : 'Show name')) + protected readonly usernameLabel = computed(() => (this.showUsername() ? 'Hide name' : 'Show name')) protected readonly allCountries = Object.keys(COUNTRIES).map(code => ({ code, count: 0, top: [] })) protected readonly name = countryName protected readonly flagLabel = computed(() => { @@ -75,7 +75,7 @@ export class Share { }) protected readonly cardPeriods = computed(() => sortPeriods(['all', ...this.periods()])) - private readonly cardOptions = computed(() => ({ ...badgeQuery({ hidden: this.hiddenBadges(), names: this.names() }), ...identityQuery({ avatar: this.showAvatar(), name: this.showName() }) })) + private readonly cardOptions = computed(() => cardOptionsQuery({ badges: { hidden: this.hiddenBadges(), names: this.names() }, identity: { avatar: this.showAvatar(), username: this.showUsername() } })) private readonly profileUrl = computed(() => `${SITE_URL}/${this.username()}${shareQuery(this.period())}`) /** The profile with the card's period and flag: what a post links to, and the README card's link. */ private readonly cardProfileUrl = computed(() => `${SITE_URL}/${this.username()}${shareQuery(this.cardPeriod(), this.flag(), this.cardOptions())}`) @@ -110,7 +110,7 @@ export class Share { this.hiddenBadges.set([]) this.names.set('fun') this.showAvatar.set(true) - this.showName.set(true) + this.showUsername.set(true) this.shownUrl.set(null) this.startLoading() } @@ -132,8 +132,8 @@ export class Share { this.startLoading() } - protected toggleName(): void { - this.showName.update(shown => !shown) + protected toggleUsername(): void { + this.showUsername.update(shown => !shown) this.startLoading() } diff --git a/app/src/server/card/card.ts b/app/src/server/card/card.ts index 1383e66..a645d74 100644 --- a/app/src/server/card/card.ts +++ b/app/src/server/card/card.ts @@ -9,6 +9,7 @@ import { formatMonth } from '../../app/text/date-format' import { formatNumber, formatPoints, formatRank } from '../../app/text/number-format' import { statWord } from '../../app/text/stat-names' import { TAG_FONT_SIZE, TAG_GAP, TAG_HEIGHT, TAG_ICON_SIZE, TAG_ICON_WIDTH, TAG_LARGE_ICON, TAG_LARGE_SIZE, TAG_PADDING, type CardTag } from './card-tags' +import type { CardIdentity } from '../../app/profile/card-identity' import type { TagColors } from './tag-colors' import { TAG_FONTS } from './tag-fonts' @@ -105,11 +106,23 @@ export function cardPeriod(profile: ContributorProfile, requested: unknown): Per return period !== 'all' && profile.periods.some(row => row.period === period) ? period : 'all' } -/** `avatar`: a data URL, `null` when GitHub did not send it (a grey circle instead), or `false` when the owner left it off. */ -export function cardTree(profile: ContributorProfile, period: Period, avatar: string | null | false, flag: { src: string, name: string } | null = null, tags: readonly CardTag[] = [], showName = true): Node { +function cardHead({ avatar, username }: CardIdentity) { + const bare = !avatar && !username + return { + justify: avatar && username ? 'flex-start' : 'center', + usernameTop: avatar ? 12 : 0, + rankTop: username ? 6 : avatar ? 12 : 0, + rankSize: bare ? 128 : 84, + pointsSize: bare ? 36 : 30, + } +} + +/** `avatar`: a data URL, or `null` when GitHub did not send it (a grey circle instead). `identity`: what the owner left on. */ +export function cardTree(profile: ContributorProfile, period: Period, avatar: string | null, flag: { src: string, name: string } | null = null, tags: readonly CardTag[] = [], identity: CardIdentity = { avatar: true, username: true }): Node { const tiles = !tags.length ? TILES : tags.some(tag => tag.row === 3) ? TILES_WITH_THREE_ROWS : TILES_WITH_TAGS const stats = period === 'all' ? profile : profile.periods.find(row => row.period === period)! const since = profile.firstContributionAt ? formatMonth(profile.firstContributionAt) : null + const head = cardHead(identity) const rows = [ [ { label: statWord('pullRequests', stats.pullRequests.all), value: stats.pullRequests.all, color: COLORS.pullRequests, icon: ICONS.pullRequests }, @@ -122,13 +135,13 @@ export function cardTree(profile: ContributorProfile, period: Period, avatar: st ] return h('div', { width: '100%', height: '100%', flexDirection: 'column', justifyContent: 'space-between', backgroundColor: '#0a0a0a', color: '#ffffff', paddingTop: 44, paddingRight: 64, paddingBottom: 36, paddingLeft: 64, fontFamily: 'Manrope' }, [ h('div', { flexDirection: 'row', gap: 64 }, [ - h('div', { flexDirection: 'column', width: 380, justifyContent: avatar === false || !showName ? 'center' : 'flex-start' }, [ - ...(avatar === false ? [] : [avatar + h('div', { flexDirection: 'column', width: 380, justifyContent: head.justify }, [ + ...(!identity.avatar ? [] : [avatar ? h('img', { width: 108, height: 108, borderRadius: 9999, border: '4px solid #262626' }, undefined, { src: avatar, width: 108, height: 108 }) : h('div', { width: 108, height: 108, borderRadius: 9999, backgroundColor: '#262626' })]), - ...(showName ? [h('div', { fontSize: 40, fontWeight: 600, marginTop: avatar === false ? 0 : 12, maxWidth: 380, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, profile.username)] : []), - h('div', { fontFamily: 'Norse', fontWeight: 700, fontSize: avatar === false && !showName ? 128 : 84, lineHeight: 1, letterSpacing: 2, color: BRAND, marginTop: showName ? 6 : avatar === false ? 0 : 12 }, formatRank(period === 'all' ? profile.rank : stats.rank)), - h('div', { fontSize: avatar === false && !showName ? 36 : 30, fontWeight: 600, color: BRAND, marginTop: 4 }, formatPoints(stats.score)), + ...(identity.username ? [h('div', { fontSize: 40, fontWeight: 600, marginTop: head.usernameTop, maxWidth: 380, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, profile.username)] : []), + h('div', { fontFamily: 'Norse', fontWeight: 700, fontSize: head.rankSize, lineHeight: 1, letterSpacing: 2, color: BRAND, marginTop: head.rankTop }, formatRank(period === 'all' ? profile.rank : stats.rank)), + h('div', { fontSize: head.pointsSize, fontWeight: 600, color: BRAND, marginTop: 4 }, formatPoints(stats.score)), ...(period !== 'all' ? [h('div', { fontSize: 24, color: '#a3a3a3', marginTop: 4 }, periodPhrase(period))] : []), ...(flag ? [h('div', { flexDirection: 'row', alignItems: 'center', gap: 10, marginTop: period === 'all' ? 10 : 4, fontSize: 24, color: '#a3a3a3' }, [ h('img', { width: 30, height: 30 }, undefined, { src: flag.src, width: 30, height: 30 }), diff --git a/app/src/server/routes/[username]/card.png.get.ts b/app/src/server/routes/[username]/card.png.get.ts index 158a20d..19c6283 100644 --- a/app/src/server/routes/[username]/card.png.get.ts +++ b/app/src/server/routes/[username]/card.png.get.ts @@ -2,8 +2,7 @@ import { sendPng } from '../../data/http' import { createError, defineEventHandler, getQuery, getRouterParam } from 'h3' import * as v from 'valibot' import { countryCode, countryName } from '@angularians/shared' -import { parseCardIdentity } from '../../../app/profile/card-identity' -import { parseBadgeOptions } from '../../../app/profile/card-badges' +import { parseCardOptions } from '../../../app/profile/card-options' import { avatarData, cardFonts, flagData } from '../../card/assets' import { cardBadgeTags } from '../../card/badges' import { cardPeriod, cardTree, renderCard } from '../../card/card' @@ -11,7 +10,7 @@ import { UsernameSchema } from '../../data/schemas' import { contributorsData } from '../../data/store' /** - * `GET /:username/card.png?period=2025&flag=TR&avatar=off&name=off`: the Angularian card, for GitHub profile READMEs and the profile's link + * `GET /:username/card.png?period=2025&flag=TR&avatar=off&username=off`: the Angularian card, for GitHub profile READMEs and the profile's link * preview. The URL never changes; the numbers do, every night. */ export default defineEventHandler(async (event) => { @@ -23,9 +22,9 @@ export default defineEventHandler(async (event) => { const period = cardPeriod(profile, getQuery(event)['period']) // `?flag=TR`: the country the owner picked for this card. Otherwise their GitHub location. const code = countryCode(getQuery(event)['flag']) ?? profile.country ?? null - const identity = parseCardIdentity(getQuery(event)['avatar'], getQuery(event)['name']) - const [avatar, flagSrc, fonts, tags] = await Promise.all([identity.avatar ? avatarData(profile.githubId) : false as const, code ? flagData(code) : null, cardFonts(), cardBadgeTags(profile, parseBadgeOptions(getQuery(event)['hide'], getQuery(event)['names']))]) - const png = await renderCard(cardTree(profile, period, avatar, code && flagSrc ? { src: flagSrc, name: countryName(code) } : null, tags, identity.name), fonts) + const { badges, identity } = parseCardOptions(getQuery(event)) + const [avatar, flagSrc, fonts, tags] = await Promise.all([identity.avatar ? avatarData(profile.githubId) : null, code ? flagData(code) : null, cardFonts(), cardBadgeTags(profile, badges)]) + const png = await renderCard(cardTree(profile, period, avatar, code && flagSrc ? { src: flagSrc, name: countryName(code) } : null, tags, identity), fonts) // A day in shared caches (GitHub's image proxy too): each night's deploy clears the CDN. return sendPng(event, png) }) diff --git a/app/vite.config.ts b/app/vite.config.ts index 89ca235..13579e0 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -82,7 +82,7 @@ export default defineConfig(() => ({ // country). Any other one (`?utm_source=`) shares the page's copy. A route reading a new parameter must add it here. // and per value of the signed-in hint cookie (app/src/app/auth/hint.ts), whose pages start with the signed-in // card's skeleton. Every other cookie is ignored by the cache. - '/**': { headers: { 'cache-control': 'public, max-age=0, s-maxage=86400, stale-while-revalidate=86400', 'netlify-cdn-cache-control': 'public, durable, s-maxage=86400, stale-while-revalidate=86400', 'netlify-vary': 'query=period|country|badges|match|page|q|flag|hide|names|avatar|name|v,cookie=angularians-signed-in' } }, + '/**': { headers: { 'cache-control': 'public, max-age=0, s-maxage=86400, stale-while-revalidate=86400', 'netlify-cdn-cache-control': 'public, durable, s-maxage=86400, stale-while-revalidate=86400', 'netlify-vary': 'query=period|country|badges|match|page|q|flag|hide|names|avatar|username|v,cookie=angularians-signed-in' } }, // Sign-in: per person, with cookies. Never in a shared cache. '/api/auth/**': { headers: { 'cache-control': 'private, no-store', 'netlify-cdn-cache-control': 'no-store' } }, // Server functions are POSTs whose input is in the body, which no cache key sees: never cached. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 9334965..e7fa8f4 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -164,5 +164,5 @@ Signing in from the home page ends on your profile, or back on the home page if | `GET /api/contributors/:username` | A profile: all-time stats, rank in each period, links | | `GET /api/search/contributors?q=cris&country=TR` | Up to 8 contributors, of that country if given | | `GET /api/map/contributors?period=all` | Contributors by country, and every badge on the board with how many hold it in the period | -| `GET /:username/card.png?period=2025&flag=TR&hide=reviewer&names=official&avatar=off&name=off` | The Angularian card, 2400×1260: the README card and the profile's link preview. `avatar=off` and `name=off` leave the GitHub avatar and the username off (on a GitHub profile both already sit beside the README), and the profile's own `?avatar=off&name=off` carries them to its link preview. `names=official` swaps fun project titles for the project and role, `names=none` shows the badges as icons alone; `hide` is the badges the owner left out in the share dialog (`app/src/app/profile/card-badges.ts`), and the profile's own `?hide=` carries them to its link preview. Its flag is the GitHub location's country, or `flag` when the owner picked another; under its stats, the profile's badges as tags with their names, as many as fit in up to three rows (the stats shrink for a third) and the rest as icons alone, a language's own name in Manrope's Cyrillic and extended Latin or a small Noto font holding just its letters (`TAG_FONTS` in `app/src/server/card/tag-fonts.ts`) (`earnedBadges` in `app/src/app/profile/earned-badges.ts`, shared with the profile page; images from the `site-images` server asset) | +| `GET /:username/card.png?period=2025&flag=TR&hide=reviewer&names=official&avatar=off&username=off` | The Angularian card, 2400×1260: the README card and the profile's link preview. `avatar=off` and `username=off` leave the GitHub avatar and the username off (on a GitHub profile both already sit beside the README), and the profile's own `?avatar=off&username=off` carries them to its link preview. `names=official` swaps fun project titles for the project and role, `names=none` shows the badges as icons alone; `hide` is the badges the owner left out in the share dialog (`app/src/app/profile/card-badges.ts`), and the profile's own `?hide=` carries them to its link preview. Its flag is the GitHub location's country, or `flag` when the owner picked another; under its stats, the profile's badges as tags with their names, as many as fit in up to three rows (the stats shrink for a third) and the rest as icons alone, a language's own name in Manrope's Cyrillic and extended Latin or a small Noto font holding just its letters (`TAG_FONTS` in `app/src/server/card/tag-fonts.ts`) (`earnedBadges` in `app/src/app/profile/earned-badges.ts`, shared with the profile page; images from the `site-images` server asset) | | `GET /og.png?period=2025` | The home page's link preview, 2400×1260: all time, or the top of a period |