Skip to content

Add npm run icon: fetch a doc's icon from its website - #2781

Draft
buggypather wants to merge 1 commit into
freeCodeCamp:mainfrom
buggypather:icon-fetch-script
Draft

buggypather wants to merge 1 commit into
freeCodeCamp:mainfrom
buggypather:icon-fetch-script

Conversation

@buggypather

Copy link
Copy Markdown

Proposed in #2780. This is a draft until maintainers say whether they want it.

Adds npm run icon -- <doc_slug> <website>, which finds a website's icon and writes public/icons/docs/<slug>/16.png, 16@2x.png and SOURCE.

Changes

  • scripts/fetch_icon.js: finds the icon, reads PNG and ICO files, resizes the icon and writes the three files. It uses only Node's standard library. --icon <image address> uses a specific image instead, which helps when a site only offers an SVG icon.
  • test/scripts/fetch_icon_test.js: tests for image reading, resizing and the order icons are tried in, plus full runs against a fake website (no network access).
  • test/scripts/tsconfig.json: adds the script and its tests to npm run typecheck.
  • package.json: adds the icon script and includes test/scripts in npm test.
  • docs/adding-docs.md: mentions the script in step 11 (adding the icon).

Testing

  • npm test and npm run typecheck pass locally on Node 24.
  • Tried on python.org and docs.github.com; the 16- and 32-pixel results look right. On vuejs.org, the script explains that only an SVG icon is offered.
  • No Ruby code changed. I haven't run the spritesheet build (thor sprites:generate) on the output, but the files have the same names and sizes as the existing icon folders.

🤖 Generated with Claude Code

Finding, resizing and saving a doc's icon is a manual step today. The script
looks up the website's icon (<link rel=icon>, apple-touch-icon, then
/apple-touch-icon.png and /favicon.ico), reads PNG and ICO files, scales it to
16 and 32 pixels by area averaging and writes public/icons/docs/<slug>/16.png,
16@2x.png and SOURCE. It uses only Node's standard library. SVG-only icons
can't be converted without a dependency, so it says so and accepts --icon with
an image address instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant