-
-
Notifications
You must be signed in to change notification settings - Fork 12
Generate favicon and PWA icons based on logo with full metadata support #1013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
|
@copilot You did forget to update the pm lock file and keep in mind that the logo can also be placed in the books folder. Since the public folder is deprecated and now the public files should live along the book files. Maybe the logo could even live in the root folder. So logo: test.png should check the root folder, the book folder and the public folder. |
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Updated the logo path resolution to check multiple locations: For relative paths (e.g.,
For absolute paths (e.g.,
The pnpm-lock.yaml has been updated to include the favicons dependency. All tests pass with logos in different locations. Commit: [pending]
Updated the logo path resolution to check multiple locations: For relative paths (e.g.,
For absolute paths (e.g.,
The pnpm-lock.yaml has been updated to include the favicons dependency. All tests pass with logos in different locations. Commit: 189257f |
|
@copilot Can you use more information from the hyperbook.json. Te path to be set to "{ASSETS_FOLDER}/favicons/" (defined in build.ts line 20) The scope should be set to the basePath The lang should be set to the Hyperbook language The theme_color should be set to colors.brand The appname should be set to the name the app description should be set to the description. The developerName and developerUrl should be set to the author.name and author.url And android and apple icons should also be generated. And if use find another thing useful please add it. Here is the documentation of the favicons config: const configuration = {
path: "/", // Path for overriding default icons path. `string`
appName: null, // Your application's name. `string`
appShortName: null, // Your application's short_name. `string`. Optional. If not set, appName will be used
appDescription: null, // Your application's description. `string`
developerName: null, // Your (or your developer's) name. `string`
developerURL: null, // Your (or your developer's) URL. `string`
cacheBustingQueryParam: null, // Query parameter added to all URLs that acts as a cache busting system. `string | null`
dir: "auto", // Primary text direction for name, short_name, and description
lang: "en-US", // Primary language for name and short_name
background: "#fff", // Background colour for flattened icons. `string`
theme_color: "#fff", // Theme color user for example in Android's task switcher. `string`
appleStatusBarStyle: "black-translucent", // Style for Apple status bar: "black-translucent", "default", "black". `string`
display: "standalone", // Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser". `string`
orientation: "any", // Default orientation: "any", "natural", "portrait" or "landscape". `string`
scope: "/", // set of URLs that the browser considers within your app
start_url: "/?homescreen=1", // Start URL when launching the application from a device. `string`
preferRelatedApplications: false, // Should the browser prompt the user to install the native companion app. `boolean`
relatedApplications: undefined, // Information about the native companion apps. This will only be used if `preferRelatedApplications` is `true`. `Array<{ id: string, url: string, platform: string }>`
version: "1.0", // Your application's version string. `string`
pixel_art: false, // Keeps pixels "sharp" when scaling up, for pixel art. Only supported in offline mode.
loadManifestWithCredentials: false, // Browsers don't send cookies when fetching a manifest, enable this to fix that. `boolean`
manifestMaskable: false, // Maskable source image(s) for manifest.json. "true" to use default source. More information at https://web.dev/maskable-icon/. `boolean`, `string`, `buffer` or array of `string`
icons: {
// Platform Options:
// - offset - offset in percentage
// - background:
// * false - use default
// * true - force use default, e.g. set background for Android icons
// * color - set background for the specified icons
//
android: true, // Create Android homescreen icon. `boolean` or `{ offset, background }` or an array of sources
appleIcon: true, // Create Apple touch icons. `boolean` or `{ offset, background }` or an array of sources
appleStartup: true, // Create Apple startup images. `boolean` or `{ offset, background }` or an array of sources
favicons: true, // Create regular favicons. `boolean` or `{ offset, background }` or an array of sources
windows: true, // Create Windows 8 tile icons. `boolean` or `{ offset, background }` or an array of sources
yandex: true, // Create Yandex browser icon. `boolean` or `{ offset, background }` or an array of sources
},
shortcuts: [
// Your applications's Shortcuts (see: https://developer.mozilla.org/docs/Web/Manifest/shortcuts)
// Array of shortcut objects:
{
name: "View your Inbox", // The name of the shortcut. `string`
short_name: "inbox", // optionally, falls back to name. `string`
description: "View your inbox messages", // optionally, not used in any implemention yet. `string`
url: "/inbox", // The URL this shortcut should lead to. `string`
icon: "test/inbox_shortcut.png", // source image(s) for that shortcut. `string`, `buffer` or array of `string`
},
// more shortcuts objects
],
}; |
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Enhanced the favicon generation with all the requested metadata from hyperbook.json: ✅ Path: Set to The generated web manifest includes all metadata and the HTML now includes links to the manifest and Apple touch icons. Backward compatibility maintained with favicon.ico copied to root. Commit: [pending]
Enhanced the favicon generation with all the requested metadata from hyperbook.json: ✅ Path: Set to The generated web manifest includes all metadata and the HTML now includes links to the manifest and Apple touch icons. Backward compatibility maintained with favicon.ico copied to root. Commit: 8ecffc5 |
|
@copilot what platform specific issues can occur, when the favicons package is bundled? |
The favicons package depends on
However, after reviewing this further, I can test whether bundling actually works. The |
|
@copilot Please test it, when the flag is removed. Can you also test it on Windows? |
I tested removing the ❌ Bundled approach failed: When favicons and sharp are bundled, Sharp's native binaries can't be loaded. Error: "Could not load the 'sharp' module using the linux-x64 runtime" ✅ External approach works: With Why bundling fails: Sharp uses platform-specific native Windows testing: I can't test on Windows in this environment (running Linux), but the external approach should work cross-platform since:
The current implementation (using external dependencies) is the correct approach and should work on Windows, macOS, and Linux without platform-specific issues. |
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
|
@copilot Can you write a pnpm changeset and also update the changelog.md in the website/en/book folder? |
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Created changeset and updated changelog: Changeset (
Changelog (
Commit: [pending]
Created changeset and updated changelog: Changeset (
Changelog (
Commit: a569280 |
Overview
Implements automatic favicon and Progressive Web App (PWA) icon generation from the logo defined in
hyperbook.json. When building a Hyperbook project, if nofavicon.icoexists and a logo is configured, a complete set of favicons and PWA assets are automatically generated using the favicons package as suggested by @mikebarkmin.Changes
Core Implementation
Favicon Generation Helper (
packages/hyperbook/helpers/generate-favicons.ts)faviconspackage only when neededfavicon.ico(multi-size ICO format)colors.brand(defaults to #007864)authorfieldsBuild Process Integration (
packages/hyperbook/build.ts)favicon.icoalready exists in the output directory after copying public fileslogois defined inhyperbook.json, generates complete icon set automaticallylogo.png): checks root folder → book folder → public folder/logo.png): checks book folder → public folder{ASSETS_FOLDER}/favicons/directoryfavicon.icoto root for backward compatibilityHTML Integration (
packages/markdown/src/rehypeHtmlStructure.ts)<link rel="icon" type="image/x-icon" href="favicon.ico">to all HTML pages<link rel="apple-touch-icon" sizes="180x180">for Apple devices<link rel="manifest">for Progressive Web App support<head>section before stylesheetsRelease Documentation
.changeset/favicon-generation.md) markinghyperbookfor minor version bump and@hyperbook/markdownfor patch version bumpwebsite/en/book/changelog.md) with feature description in v0.59.0Technical Details
favicons@^7.2.0as a runtime dependency (external dependency, not bundled)faviconsandsharp(native dependency) from bundling to avoid platform-specific issuestsconfig.jsonto add"module": "commonjs"for dynamic import supportpnpm-lock.yamlto reflect the new dependencyBehavior
When favicon exists in public folder:
When favicon doesn't exist but logo is defined:
When neither favicon nor logo exists:
Testing
Example Output
Generated files in
__hyperbook_assets/favicons/directory (60+ files):favicon.ico(33KB, multi-size ICO format, also copied to root)manifest.webmanifestwith full PWA metadata (theme color, scope, language, developer info)Fixes #242
Original prompt
Fixes #242
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.