Skip to content
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

Fix issue from logo bugfix #2620

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/server/utils/generate-manifest-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,47 @@ type Icon = { sizes: string; src: string; type: string; purpose: string };
const iconSizes = [72, 96, 128, 144, 152, 192, 384, 512];
let icons: Icon[] | null = null;

function mapIcon(src: string, size: number): Icon {
return {
sizes: `${size}x${size}`,
type: "image/png",
src,
purpose: "any maskable",
};
}

function generateDefaultIcons() {
return iconSizes.map(size =>
mapIcon(`${getStaticDir()}/assets/icons/icon-${size}x${size}.png`, size),
);
}

export default async function (site: Site) {
if (!icons) {
try {
const icon = site.icon ? await fetchIconPng(site.icon) : null;

icons = await Promise.all(
iconSizes.map(async size => {
let src = `${getStaticDir()}/assets/icons/icon-${size}x${size}.png`;

if (icon) {
if (icon) {
icons = await Promise.all(
iconSizes.map(async size => {
const sharp = (await import("sharp")).default;
src = `data:image/png:base64,${await sharp(icon)
const src = `data:image/png:base64,${await sharp(icon)
.resize(size, size)
.png()
.toBuffer()
.then(buf => buf.toString("base64"))}`;
}

return {
sizes: `${size}x${size}`,
type: "image/png",
src,
purpose: "any maskable",
};
}),
);
return mapIcon(src, size);
}),
);
} else {
icons = generateDefaultIcons();
}
} catch (e) {
console.log(
`Failed to fetch site logo for manifest icon. Using default icon`,
);
icons = generateDefaultIcons();
}
}

Expand Down