Repository navigation
Add npm run icon: fetch a doc's icon from its website - #2781
Draft
buggypather wants to merge 1 commit into
Draft
buggypather wants to merge 1 commit into
buggypather wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 writespublic/icons/docs/<slug>/16.png,16@2x.pngandSOURCE.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 tonpm run typecheck.package.json: adds theiconscript and includestest/scriptsinnpm test.docs/adding-docs.md: mentions the script in step 11 (adding the icon).Testing
npm testandnpm run typecheckpass locally on Node 24.thor sprites:generate) on the output, but the files have the same names and sizes as the existing icon folders.🤖 Generated with Claude Code