diff --git a/.agents/skills/add-a-custom-badge/SKILL.md b/.agents/skills/add-a-custom-badge/SKILL.md index 4107dff..24b1cca 100644 --- a/.agents/skills/add-a-custom-badge/SKILL.md +++ b/.agents/skills/add-a-custom-badge/SKILL.md @@ -13,7 +13,7 @@ Ask for anything missing; never guess it. The "Badge request" issue form asks fo | What | Why | | --- | --- | -| Each person's GitHub username and role (`creator`, `co-creator`, `maintainer` or `organizer`) | who wears it | +| Each person's GitHub username and role (`creator`, `co-creator`, `founder`, `co-founder`, `maintainer`, `organizer` or `lead organizer`) | who wears it | | Project name | the tooltip | | Website, its main page | where the badge links | | GitHub repository (required for a library or a tool) | to check the project and the role | @@ -39,8 +39,8 @@ Done when every row not marked optional has an answer (the repository only for a ] }, ``` - - **`badge`.** Two or three words, playful, about what the project does ("Analog alchemist", "Icon smith", "Slide master"). Use a word other badges don't already use. Don't use the plain role ("Creator"): the one exception is the badge of Angularians' own creator. - - **`tone`.** The project's name in kebab case. Add its colours to `app/src/app/profile/badge-pill.css`, after the other projects, built from the brand colour `C` like theirs: `--pill-bg: color-mix(in oklab, C 10%, transparent)`, `--pill-text: L`, `--pill-ring: color-mix(in oklab, C 30%, transparent)` in `.tone-`, then `--pill-text: D` and `--pill-ring: color-mix(in oklab, C 40%, transparent)` in `:host-context(.dark) .tone-`. `L` is `C` darkened until it has 4.5:1 contrast on white. `D` is `C` lightened until it has 4.5:1 on `#0a0a0a`. + - **`badge`.** Two or three words, playful, about what the project does ("Analog alchemist", "Icon smith", "Slide master"). Use a word other badges don't already use. Don't use the plain role ("Creator"): the one exception is the badge of Angularians' own creator. A conference or a community is different: its badge is its real name and the role ("NG Poland organizer"), never a joke, with `badgeIsOfficial: true`. + - **`tone`.** The project's name in kebab case. Add its colours to `app/src/app/profile/badge-pill.css`, after the other projects, built from the brand colour `C` like theirs: `--pill-bg: color-mix(in oklab, C 10%, transparent)`, `--pill-text: L`, `--pill-ring: color-mix(in oklab, C 30%, transparent)` in `.tone-`, then `--pill-text: D` and `--pill-ring: color-mix(in oklab, C 40%, transparent)` in `:host-context(.dark) .tone-`. `L` is `C` darkened until it has 4.5:1 contrast on white. `D` is `C` lightened until it has 4.5:1 on `#0a0a0a`. Add the same `C` and `D` to `TAG_COLORS` in `app/src/server/card/tag-colors.ts`: the card has no theme. - **`builtOn`.** Leave it out. It is only for the tools Angularians itself runs on. 4. **Notices.** Add the logo's credit to `THIRD_PARTY_NOTICES.md`, under "Credited logos". 5. **Data.** Leave `data/` as the collector wrote it. @@ -59,7 +59,7 @@ pnpm dev With `pnpm dev` running, open: - `/`: the badge shows with the logo and title, its tooltip reads " of ", and clicking it opens the website. - Both themes, and phone width. -- `//card.png`: the logo shows in the card's footer. +- `//card.png`: the badge shows under the stats, with its logo, title and colour. Done when the test, typecheck and build pass and each page above shows the badge as described. diff --git a/.agents/skills/add-a-translator/SKILL.md b/.agents/skills/add-a-translator/SKILL.md index 68f1e09..2897dc7 100644 --- a/.agents/skills/add-a-translator/SKILL.md +++ b/.agents/skills/add-a-translator/SKILL.md @@ -17,7 +17,7 @@ Done when you hold the footer link, the date of the angular/angular commit that ## 2. Add it 1. Get each id: `gh api users/ -q .id`. -2. A new translation: an entry in `TRANSLATIONS`, in the footer's order, with `language` in that language, its `code` and `flag` (a country in `COUNTRIES` of `shared/src/countries.ts`), `site`, `repository` and `joinedAt` (the day the footer commit landed: its committer date), and its `.tone-lang-` in `badge-pill.css`, built from the flag's main colour as the other languages' are, added to the dark `:is()` list above them too. A new translator: `{ githubId: , username: '' }` in its `translators`, with `helper: true` unless they lead it (their badge then says contributor, and they score 10). +2. A new translation: an entry in `TRANSLATIONS`, in the footer's order, with `language` in that language, its `code` and `flag` (a country in `COUNTRIES` of `shared/src/countries.ts`), `site`, `repository` and `joinedAt` (the day the footer commit landed: its committer date), and its `.tone-lang-` in `badge-pill.css`, built from the flag's main colour as the other languages' are, added to the dark `:is()` list above them too, and to `TAG_COLORS` in `app/src/server/card/tag-colors.ts` for the card. If its name uses letters the card cannot draw yet, the card says only "Translator": `DRAWABLE` and `TAG_FONTS` in `app/src/server/card/tag-fonts.ts` need it (for Korean, Japanese or Chinese, a font from Google Fonts with `text=` set to the name, kept in `app/src/server/card/fonts`). A new translator: `{ githubId: , username: '' }` in its `translators`, with `helper: true` unless they lead it (their badge then says contributor, and they score 10). 3. Update the list's "as of " line. Done when the ids are in, `pnpm test` passes, and `/` with `pnpm dev` shows " translator" (or " contributor" for a helper). diff --git a/.github/ISSUE_TEMPLATE/badge-request.yml b/.github/ISSUE_TEMPLATE/badge-request.yml index 7775ac4..02536dd 100644 --- a/.github/ISSUE_TEMPLATE/badge-request.yml +++ b/.github/ISSUE_TEMPLATE/badge-request.yml @@ -68,8 +68,11 @@ body: options: - Creator - Co-creator + - Founder + - Co-founder - Maintainer - Organizer + - Lead organizer validations: required: true - type: textarea diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 15736a2..1e21b03 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -108,6 +108,7 @@ MIT, Copyright (c) 2026 HatScripts. The full licence ships with the package. - [Manrope](https://github.com/sharanda/manrope), the site's font: SIL Open Font License 1.1, Copyright 2019 The Manrope Project Authors, through `@fontsource-variable/manrope` (and, for the cards, `app/src/server/card/fonts`). +- [Noto Sans KR, JP, SC and TC](https://fonts.google.com/noto), for the language names on the cards: SIL Open Font License 1.1, Copyright 2014-2021 Adobe, reduced by Google Fonts to the letters used, in `app/src/server/card/fonts`. - [cobe](https://github.com/shuding/cobe), the globe: MIT, Copyright (c) 2021 Shu Ding. - [satori](https://github.com/vercel/satori) and [resvg-js](https://github.com/yisibl/resvg-js), which draw the cards: MPL 2.0, unmodified. @@ -127,7 +128,9 @@ The special badges also show, unchanged, the marks of Pangular Inspector (https: The badges of Ashley Hunter's Angular Native (https://ng-native.com) and Angular Primitives (https://angularprimitives.com) show their marks, unchanged, in `app/public/credits/`. Santosh Yadav's ngx-builders -(https://github.com/ngx-builders) shows its GitHub organization avatar, unchanged. +(https://github.com/ngx-builders) shows its GitHub organization avatar, unchanged. The badges of NG Baguette (https://ngbaguette.angulardevs.fr) and Angular +Devs France (https://angulardevs.fr) show their logos, reduced to 256 pixels (NG Baguette's white logo on a dark tile, so it shows in both themes), and OpenNG (https://www.openng.org) its GitHub +organization avatar. NG Poland (https://ng-poland.pl) and NG Asia (https://ng-asia.org) show the mark their own sites use, and NG Tunisia (https://ng-tunisia.org) its logo, reduced to 256 pixels. Angular Space (https://www.angularspace.com) shows its site icon, unchanged, and Angular Wrocław (https://www.meetup.com/angularwroclaw/) the shield from its Meetup banner. ## Data diff --git a/app/public/credits/angular-devs-france.png b/app/public/credits/angular-devs-france.png new file mode 100644 index 0000000..3feedb3 Binary files /dev/null and b/app/public/credits/angular-devs-france.png differ diff --git a/app/public/credits/angular-space.png b/app/public/credits/angular-space.png new file mode 100644 index 0000000..11fd64e Binary files /dev/null and b/app/public/credits/angular-space.png differ diff --git a/app/public/credits/angular-wroclaw.png b/app/public/credits/angular-wroclaw.png new file mode 100644 index 0000000..b816e81 Binary files /dev/null and b/app/public/credits/angular-wroclaw.png differ diff --git a/app/public/credits/ng-asia.png b/app/public/credits/ng-asia.png new file mode 100644 index 0000000..ed01e6e Binary files /dev/null and b/app/public/credits/ng-asia.png differ diff --git a/app/public/credits/ng-baguette.png b/app/public/credits/ng-baguette.png new file mode 100644 index 0000000..0ae2b04 Binary files /dev/null and b/app/public/credits/ng-baguette.png differ diff --git a/app/public/credits/ng-poland.png b/app/public/credits/ng-poland.png new file mode 100644 index 0000000..7595514 Binary files /dev/null and b/app/public/credits/ng-poland.png differ diff --git a/app/public/credits/ng-tunisia.png b/app/public/credits/ng-tunisia.png new file mode 100644 index 0000000..516129c Binary files /dev/null and b/app/public/credits/ng-tunisia.png differ diff --git a/app/public/credits/openng.png b/app/public/credits/openng.png new file mode 100644 index 0000000..5b26bcb Binary files /dev/null and b/app/public/credits/openng.png differ diff --git a/app/src/app/app.html b/app/src/app/app.html index ddf4007..7a2dba0 100644 --- a/app/src/app/app.html +++ b/app/src/app/app.html @@ -5,3 +5,4 @@ + diff --git a/app/src/app/app.ts b/app/src/app/app.ts index 9272706..42f976c 100644 --- a/app/src/app/app.ts +++ b/app/src/app/app.ts @@ -1,6 +1,7 @@ import { isPlatformBrowser, Location } from '@angular/common'; import { afterNextRender, Component, DestroyRef, inject, Injector, PLATFORM_ID, signal } from '@angular/core'; import { NavigationEnd, NavigationStart, Router, RouterOutlet } from '@angular/router'; +import { AngieIntro } from './layout/angie-intro'; import { HammerStrike } from './layout/hammer-strike'; import { SiteFooter } from './layout/site-footer'; import { SiteHeader } from './layout/site-header'; @@ -8,7 +9,7 @@ import { ThemeService } from './theme.service'; @Component({ selector: 'app-root', - imports: [HammerStrike, RouterOutlet, SiteFooter, SiteHeader], + imports: [AngieIntro, HammerStrike, RouterOutlet, SiteFooter, SiteHeader], templateUrl: './app.html', styleUrl: './app.css', }) diff --git a/app/src/app/layout/angie-intro.css b/app/src/app/layout/angie-intro.css new file mode 100644 index 0000000..2d1ba9b --- /dev/null +++ b/app/src/app/layout/angie-intro.css @@ -0,0 +1,26 @@ +.sponsor { + border: 1px solid var(--github-red); + color: var(--github-red); + background-color: color-mix(in oklab, var(--github-red) 12%, transparent); +} + +.sponsor:hover { + background-color: color-mix(in oklab, var(--github-red) 22%, transparent); +} + +.quiet { + justify-self: center; + font-size: var(--text-xs); + color: var(--muted-foreground); + text-decoration: underline; + text-underline-offset: 2px; +} + +.quiet:hover { + color: var(--foreground); +} + +.quiet:focus-visible { + outline: 2px solid var(--ring); + outline-offset: 2px; +} diff --git a/app/src/app/layout/angie-intro.html b/app/src/app/layout/angie-intro.html new file mode 100644 index 0000000..596a2d7 --- /dev/null +++ b/app/src/app/layout/angie-intro.html @@ -0,0 +1,21 @@ + + + + +

That was Angie

+

She is Angular’s official mascot. Here she guards ng-halla, the hall of every Angularian. Click that word or a logo and she comes back.

+
+

+ @if (starred()) { + If you can, a sponsor helps pay for the hosting and keeps the hall open. + } @else { + It is free, has no ads and is run by one maintainer. A star helps other Angular developers find it, and a sponsor helps pay for the hosting. + } +

+ + +
+
diff --git a/app/src/app/layout/angie-intro.spec.ts b/app/src/app/layout/angie-intro.spec.ts new file mode 100644 index 0000000..7d5ed10 --- /dev/null +++ b/app/src/app/layout/angie-intro.spec.ts @@ -0,0 +1,31 @@ +import { TestBed } from '@angular/core/testing' +import { vi } from 'vitest' +import { AngieIntro } from './angie-intro' +import { AngieService } from './angie.service' + +describe('AngieIntro', () => { + beforeEach(() => { + localStorage.clear() + vi.useFakeTimers() + }) + + afterEach(() => vi.useRealTimers()) + + it('offers the close button five seconds after it opens', () => { + const fixture = TestBed.createComponent(AngieIntro) + const canClose = () => (fixture.componentInstance as unknown as { canClose(): boolean }).canClose() + TestBed.inject(AngieService).stormEnded() + TestBed.tick() + vi.advanceTimersByTime(4999) + expect(canClose()).toBe(false) + vi.advanceTimersByTime(1) + expect(canClose()).toBe(true) + }) + + it('thanks for the star', () => { + const intro = TestBed.createComponent(AngieIntro).componentInstance as unknown as { markStarred(): void, starLabel(): string } + expect(intro.starLabel()).toBe('Star on GitHub') + intro.markStarred() + expect(intro.starLabel()).toBe('Thanks for the star') + }) +}) diff --git a/app/src/app/layout/angie-intro.ts b/app/src/app/layout/angie-intro.ts new file mode 100644 index 0000000..e29c963 --- /dev/null +++ b/app/src/app/layout/angie-intro.ts @@ -0,0 +1,55 @@ +import { Component, computed, effect, inject, linkedSignal, signal } from '@angular/core' +import { NgIcon, provideIcons } from '@ng-icons/core' +import { remixCheckLine, remixHeartLine, remixStarLine } from '@ng-icons/remixicon' +import { HlmButton } from '@spartan-ng/helm/button' +import { HlmDialogImports } from '@spartan-ng/helm/dialog' +import { REPO_URL, SITE_AUTHOR, SPONSOR_URL } from '../site' +import { AngieService } from './angie.service' +import { AngularLogo } from './angular-logo' + +const CLOSE_BUTTON_DELAY = 5000 +const PRESS_KIT_URL = 'https://angular.dev/press-kit' + +@Component({ + selector: 'app-angie-intro', + imports: [AngularLogo, HlmButton, HlmDialogImports, NgIcon], + providers: [provideIcons({ remixCheckLine, remixHeartLine, remixStarLine })], + templateUrl: './angie-intro.html', + styleUrl: './angie-intro.css', +}) +export class AngieIntro { + private readonly angie = inject(AngieService) + protected readonly state = computed(() => (this.angie.introOpen() ? 'open' : 'closed')) + protected readonly canClose = linkedSignal({ source: this.angie.introOpen, computation: () => false }) + protected readonly starred = signal(false) + protected readonly starLabel = computed(() => (this.starred() ? 'Thanks for the star' : 'Star on GitHub')) + protected readonly starIcon = computed(() => (this.starred() ? 'remixCheckLine' : 'remixStarLine')) + protected readonly authorUrl = SITE_AUTHOR.url + protected readonly pressKitUrl = PRESS_KIT_URL + protected readonly repoUrl = REPO_URL + protected readonly sponsorUrl = SPONSOR_URL + + constructor() { + this.revealCloseButtonLater() + } + + protected closeWhenDismissed(state: string): void { + if (state === 'closed') this.angie.closeIntro() + } + + protected markStarred(): void { + this.starred.set(true) + } + + protected turnOff(): void { + this.angie.turnOff() + } + + private revealCloseButtonLater(): void { + effect((onCleanup) => { + if (!this.angie.introOpen()) return + const timer = setTimeout(() => this.canClose.set(true), CLOSE_BUTTON_DELAY) + onCleanup(() => clearTimeout(timer)) + }) + } +} diff --git a/app/src/app/layout/angie.service.spec.ts b/app/src/app/layout/angie.service.spec.ts new file mode 100644 index 0000000..dd4719b --- /dev/null +++ b/app/src/app/layout/angie.service.spec.ts @@ -0,0 +1,53 @@ +import { TestBed } from '@angular/core/testing' +import { ANGIE_MET_KEY, ANGIE_OFF_KEY, AngieService } from './angie.service' + +describe('AngieService', () => { + beforeEach(() => { + localStorage.clear() + TestBed.resetTestingModule() + }) + + it('is on by default', () => { + expect(TestBed.inject(AngieService).on()).toBe(true) + }) + + it('turns off and on, remembering only off', () => { + const angie = TestBed.inject(AngieService) + angie.toggle() + expect(angie.on()).toBe(false) + expect(localStorage.getItem(ANGIE_OFF_KEY)).toBe('1') + angie.toggle() + expect(angie.on()).toBe(true) + expect(localStorage.getItem(ANGIE_OFF_KEY)).toBeNull() + }) + + it('stays off on the next visit', () => { + localStorage.setItem(ANGIE_OFF_KEY, '1') + expect(TestBed.inject(AngieService).on()).toBe(false) + }) + + it('introduces her once, after the first storm', () => { + const angie = TestBed.inject(AngieService) + expect(angie.introOpen()).toBe(false) + angie.stormEnded() + expect(angie.introOpen()).toBe(true) + expect(localStorage.getItem(ANGIE_MET_KEY)).toBe('1') + angie.closeIntro() + angie.stormEnded() + expect(angie.introOpen()).toBe(false) + }) + + it('does not introduce her on a later visit', () => { + localStorage.setItem(ANGIE_MET_KEY, '1') + const angie = TestBed.inject(AngieService) + angie.stormEnded() + expect(angie.introOpen()).toBe(false) + }) + + it('does not introduce her once she is off', () => { + const angie = TestBed.inject(AngieService) + angie.toggle() + angie.stormEnded() + expect(angie.introOpen()).toBe(false) + }) +}) diff --git a/app/src/app/layout/angie.service.ts b/app/src/app/layout/angie.service.ts new file mode 100644 index 0000000..fd6202a --- /dev/null +++ b/app/src/app/layout/angie.service.ts @@ -0,0 +1,68 @@ +import { DOCUMENT, isPlatformBrowser } from '@angular/common' +import { effect, inject, PLATFORM_ID, Service, signal } from '@angular/core' + +export const ANGIE_OFF_KEY = 'angularians-angie-off' +export const ANGIE_MET_KEY = 'angularians-angie-met' + +@Service() +export class AngieService { + private readonly document = inject(DOCUMENT) + private readonly browser = isPlatformBrowser(inject(PLATFORM_ID)) + + private met = false + + readonly on = signal(true) + readonly introOpen = signal(false) + + constructor() { + if (!this.browser) return + this.restoreChoice() + this.markPage() + } + + toggle(): void { + this.on.update(on => !on) + try { + if (this.on()) localStorage.removeItem(ANGIE_OFF_KEY) + else localStorage.setItem(ANGIE_OFF_KEY, '1') + } + catch { + // Not remembered, still applied. + } + } + + stormEnded(): void { + if (!this.on() || this.met) return + this.met = true + this.introOpen.set(true) + try { + localStorage.setItem(ANGIE_MET_KEY, '1') + } + catch { + // Not remembered: she introduces herself again next visit. + } + } + + turnOff(): void { + if (this.on()) this.toggle() + this.closeIntro() + } + + closeIntro(): void { + this.introOpen.set(false) + } + + private restoreChoice(): void { + try { + this.met = localStorage.getItem(ANGIE_MET_KEY) === '1' + if (localStorage.getItem(ANGIE_OFF_KEY) === '1') this.on.set(false) + } + catch { + // Storage can be blocked: on, the default. + } + } + + private markPage(): void { + effect(() => this.document.documentElement.classList.toggle('angie-off', !this.on())) + } +} diff --git a/app/src/app/layout/github-stars.css b/app/src/app/layout/github-stars.css new file mode 100644 index 0000000..c3b4c79 --- /dev/null +++ b/app/src/app/layout/github-stars.css @@ -0,0 +1,46 @@ +.repo { + width: calc(var(--spacing) * 9); + padding-inline: 0; + justify-content: center; +} + +.divider, +.stars { + display: none; +} + +.stars { + align-items: center; + gap: calc(var(--spacing) * 1); + font-size: var(--text-sm); + font-weight: 500; + font-variant-numeric: tabular-nums; + color: var(--muted-foreground); +} + +.stars ng-icon { + color: var(--primary); +} + +@media (width >= 40rem) { + .repo { + width: auto; + min-width: calc(var(--spacing) * 27); + gap: calc(var(--spacing) * 2); + border: 1px solid var(--border); + border-radius: 9999px; + padding-inline: calc(var(--spacing) * 3); + justify-content: center; + } + + .divider { + display: block; + width: 1px; + height: calc(var(--spacing) * 4); + background-color: var(--border); + } + + .stars { + display: inline-flex; + } +} diff --git a/app/src/app/layout/github-stars.html b/app/src/app/layout/github-stars.html new file mode 100644 index 0000000..b234dbd --- /dev/null +++ b/app/src/app/layout/github-stars.html @@ -0,0 +1,7 @@ + + diff --git a/app/src/app/layout/github-stars.spec.ts b/app/src/app/layout/github-stars.spec.ts new file mode 100644 index 0000000..8c34ec4 --- /dev/null +++ b/app/src/app/layout/github-stars.spec.ts @@ -0,0 +1,44 @@ +import { TestBed } from '@angular/core/testing' +import { vi } from 'vitest' +import { GithubStars, STARS_KEY } from './github-stars' + +const settle = async (fixture: ReturnType>) => { + await fixture.whenStable() + await new Promise(resolve => setTimeout(resolve)) + fixture.detectChanges() +} + +describe('GithubStars', () => { + beforeEach(() => sessionStorage.clear()) + afterEach(() => vi.unstubAllGlobals()) + + it('shows the count from GitHub and remembers it for the visit', async () => { + const request = vi.fn(async () => ({ ok: true, json: async () => ({ stargazers_count: 1234 }) })) + vi.stubGlobal('fetch', request) + const fixture = TestBed.createComponent(GithubStars) + await settle(fixture) + const link: HTMLElement = fixture.nativeElement.querySelector('a') + expect(link.textContent).toContain('1,234') + expect(link.getAttribute('aria-label')).toBe('Angularians on GitHub, 1,234 stars') + expect(sessionStorage.getItem(STARS_KEY)).toBe('1234') + }) + + it('uses the remembered count without asking GitHub', async () => { + sessionStorage.setItem(STARS_KEY, '17') + const request = vi.fn() + vi.stubGlobal('fetch', request) + const fixture = TestBed.createComponent(GithubStars) + await settle(fixture) + expect(fixture.nativeElement.textContent).toContain('17') + expect(request).not.toHaveBeenCalled() + }) + + it('stays a plain GitHub link when the count cannot load', async () => { + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: false, json: async () => ({}) }))) + const fixture = TestBed.createComponent(GithubStars) + await settle(fixture) + const link: HTMLElement = fixture.nativeElement.querySelector('a') + expect(link.getAttribute('aria-label')).toBe('Angularians on GitHub') + expect(link.querySelector('.stars')).toBeNull() + }) +}) diff --git a/app/src/app/layout/github-stars.ts b/app/src/app/layout/github-stars.ts new file mode 100644 index 0000000..775f439 --- /dev/null +++ b/app/src/app/layout/github-stars.ts @@ -0,0 +1,64 @@ +import { afterNextRender, Component, computed, signal } from '@angular/core' +import { NgIcon, provideIcons } from '@ng-icons/core' +import { remixStarFill } from '@ng-icons/remixicon' +import { simpleGithub } from '@ng-icons/simple-icons' +import { HlmButton } from '@spartan-ng/helm/button' +import { REPO_URL } from '../site' +import { formatNumber } from '../text/number-format' +import { plural } from '../text/plural' + +export const STARS_KEY = 'angularians-repo-stars' +const API_URL = REPO_URL.replace('https://github.com/', 'https://api.github.com/repos/') + +@Component({ + selector: 'app-github-stars', + imports: [HlmButton, NgIcon], + providers: [provideIcons({ remixStarFill, simpleGithub })], + templateUrl: './github-stars.html', + styleUrl: './github-stars.css', +}) +export class GithubStars { + private readonly count = signal(null) + protected readonly repoUrl = REPO_URL + protected readonly stars = computed(() => { + const count = this.count() + return count === null ? null : formatNumber(count) + }) + protected readonly label = computed(() => { + const count = this.count() + return count === null ? 'Angularians on GitHub' : `Angularians on GitHub, ${plural(count, 'star', 'stars')}` + }) + + constructor() { + afterNextRender(() => void this.loadCount()) + } + + private async loadCount(): Promise { + const remembered = this.rememberedCount() + if (remembered !== null) { + this.count.set(remembered) + return + } + try { + const response = await fetch(API_URL) + if (!response.ok) return + const { stargazers_count: count } = await response.json() as { stargazers_count?: unknown } + if (typeof count !== 'number') return + this.count.set(count) + sessionStorage.setItem(STARS_KEY, String(count)) + } + catch { + // No count: the link still works. + } + } + + private rememberedCount(): number | null { + try { + const saved = sessionStorage.getItem(STARS_KEY) + return saved && Number.isFinite(Number(saved)) ? Number(saved) : null + } + catch { + return null + } + } +} diff --git a/app/src/app/layout/hammer-strike.ts b/app/src/app/layout/hammer-strike.ts index cceb0e4..d215154 100644 --- a/app/src/app/layout/hammer-strike.ts +++ b/app/src/app/layout/hammer-strike.ts @@ -1,5 +1,6 @@ import { isPlatformBrowser } from '@angular/common' -import { afterNextRender, Component, DestroyRef, inject, PLATFORM_ID, signal } from '@angular/core' +import { afterNextRender, Component, DestroyRef, effect, inject, PLATFORM_ID, signal } from '@angular/core' +import { AngieService } from './angie.service' import { lightning, type Strike } from './lightning' /** The thunder follows the flash (`--strike` in the CSS), a quarter of a second later: the light arrives first. */ @@ -13,7 +14,8 @@ const ANGIE = '/angie/angie-hammer.png' * The word "Angularian(s)" or "ng-halla", or a logo, calls Angie: she comes in with her hammer and calls down lightning * somewhere on the page, with thunder. A click on the word calls her any time, a click on a logo once a visit (the tab's * session); the mouse coming onto the word does once a visit too, and only after a first click or key on the page, so - * the browser lets the thunder play. Never on touch screens, a link or button that holds the word, or with reduced motion. + * the browser lets the thunder play. Never on touch screens, a link, button or dialog that holds the word (a link + * can opt in with `data-calls-angie`), with reduced motion, or once the visitor has turned her off in the account menu. */ @Component({ selector: 'app-hammer-strike', @@ -22,33 +24,38 @@ const ANGIE = '/angie/angie-hammer.png' styleUrl: './hammer-strike.css', }) export class HammerStrike { + private readonly angie = inject(AngieService) protected readonly strike = signal(null) + private thunder: HTMLAudioElement | undefined /** Angie has gone: the storm is over. */ protected end(): void { + if (!this.strike()) return this.strike.set(null) + this.angie.stormEnded() } constructor() { const destroyRef = inject(DestroyRef) if (!isPlatformBrowser(inject(PLATFORM_ID))) return + this.stopWhenTurnedOff() afterNextRender(() => { if (matchMedia('(prefers-reduced-motion: reduce), (hover: none)').matches) return let current: Element | null = null let thunderTimer: ReturnType | undefined let endTimer: ReturnType | undefined - let thunder: HTMLAudioElement | undefined let strikes = 0 - let angie: HTMLImageElement | undefined + let portrait: HTMLImageElement | undefined let calling = false const call = (started?: () => void) => { - if (calling || this.strike()) return + if (!this.angie.on() || calling || this.strike()) return calling = true - angie ??= Object.assign(new Image(), { src: ANGIE }) - angie.decode().then(() => { + portrait ??= Object.assign(new Image(), { src: ANGIE }) + portrait.decode().then(() => { + if (!this.angie.on()) return storm() started?.() - }, () => (angie = undefined)).finally(() => (calling = false)) + }, () => (portrait = undefined)).finally(() => (calling = false)) } const storm = () => { const x = innerWidth * (0.2 + Math.random() * 0.5) @@ -58,19 +65,19 @@ export class HammerStrike { endTimer = setTimeout(() => this.end(), STORM) remember(HOVERED) thunderTimer = setTimeout(() => { - if (!thunder) return - thunder.currentTime = 0 - thunder.play().catch(() => { + if (!this.thunder || !this.angie.on()) return + this.thunder.currentTime = 0 + this.thunder.play().catch(() => { // Not allowed yet: no click or key on the page so far. }) }, THUNDER) } // The first click or key wakes the hover up, and loads the thunder ahead of the first storm. const wake = () => { - if (thunder) return - thunder = new Audio('/sounds/thunder.mp3') - thunder.preload = 'auto' - thunder.volume = 0.6 + if (this.thunder) return + this.thunder = new Audio('/sounds/thunder.mp3') + this.thunder.preload = 'auto' + this.thunder.volume = 0.6 } const onOver = (event: PointerEvent) => { if (event.pointerType !== 'mouse') return @@ -78,11 +85,11 @@ export class HammerStrike { // Once per entry into a word: moving inside it, or over its letters, does not call her again. if (word === current) return current = word - if (word && thunder && !usedThisVisit(HOVERED)) call() + if (word && this.thunder && !usedThisVisit(HOVERED)) call() } const onClick = (event: MouseEvent) => { if ((event as PointerEvent).pointerType === 'touch' || this.strike()) return - if (angularian(event.target)) call() + if (angularian(event.target) || (event.target as Element | null)?.closest?.('[data-calls-angie]')) call() else if (headerLogo(event.target) && !usedThisVisit(LOGO)) call(() => remember(LOGO)) } document.addEventListener('pointerover', onOver) @@ -99,13 +106,21 @@ export class HammerStrike { }) }) } + + private stopWhenTurnedOff(): void { + effect(() => { + if (this.angie.on()) return + this.end() + this.thunder?.pause() + }) + } } -/** The word "Angularian(s)" or "ng-halla" under the pointer, not in a link or a button, or `null`. Ranks and headings share its font. */ +/** The word "Angularian(s)" or "ng-halla" under the pointer, not in a link, a button or a dialog, or `null`. Ranks and headings share its font. */ function angularian(target: EventTarget | null): Element | null { const element = target as Element | null const word = element?.closest?.('.brand') - if (!word || word.closest('a, button')) return null + if (!word || word.closest('a, button, hlm-dialog-content')) return null return [element!, word].find(candidate => /^(angularians?|ng-halla)$/i.test(candidate.textContent?.trim() ?? '')) ?? null } diff --git a/app/src/app/layout/site-footer.html b/app/src/app/layout/site-footer.html index d4bf590..5b7a891 100644 --- a/app/src/app/layout/site-footer.html +++ b/app/src/app/layout/site-footer.html @@ -36,6 +36,9 @@ MIT licence · Inspired by Nuxters · Credits + @if (!angie.on()) { + · + }

Community project, not affiliated with Google or the Angular team. Angular is a trademark of Google LLC.

diff --git a/app/src/app/layout/site-footer.ts b/app/src/app/layout/site-footer.ts index e6f1dd0..582547d 100644 --- a/app/src/app/layout/site-footer.ts +++ b/app/src/app/layout/site-footer.ts @@ -3,11 +3,12 @@ import { Router, RouterLink } from '@angular/router'; import { NgIcon, provideIcons } from '@ng-icons/core'; import { simpleGithub } from '@ng-icons/simple-icons'; import { HlmButton } from '@spartan-ng/helm/button'; +import { AngieService } from './angie.service'; import { AngularLogo } from './angular-logo'; import { Container } from './container'; import { scrollHomeToTop } from './home-top'; import { LogoMark } from './logo-mark'; -import { REPO_URL } from '../site'; +import { REPO_URL, SPONSOR_URL } from '../site'; /** The footer: the brand and its pitch, then the small print. */ @Component({ @@ -20,6 +21,7 @@ import { REPO_URL } from '../site'; }) export class SiteFooter { private readonly router = inject(Router); + protected readonly angie = inject(AngieService); protected readonly repo = REPO_URL; /** The footer's links: the board, how to take part, and the people behind it. */ protected readonly groups: ReadonlyArray<{ title: string, links: ReadonlyArray<{ label: string, route?: string, fragment?: string, href?: string }> }> = [ @@ -35,7 +37,7 @@ export class SiteFooter { { label: 'Report a bug', href: `${REPO_URL}/issues/new?template=bug_report.yml` }, ] }, { title: 'People', links: [ - { label: 'Sponsor', href: 'https://github.com/sponsors/erkamyaman' }, + { label: 'Sponsor', href: SPONSOR_URL }, { label: 'Send a raven (ping me)', href: 'https://erkamyaman.dev/links/' }, ] }, ]; diff --git a/app/src/app/layout/site-header.html b/app/src/app/layout/site-header.html index 6322b8a..32be1e0 100644 --- a/app/src/app/layout/site-header.html +++ b/app/src/app/layout/site-header.html @@ -6,14 +6,12 @@