Skip to content

Commit

Permalink
v3.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
JakiChen committed Dec 10, 2024
1 parent 4e26024 commit db703ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
30 changes: 21 additions & 9 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,39 @@ import type {
Options,
} from "../types";

type Platformed<T> = T & { platform: PlatformName };

type PlatformedResponse = {
readonly images: Platformed<FaviconResponse["images"][number]>[];
readonly files: Platformed<FaviconResponse["files"][number]>[];
readonly html: FaviconResponse["html"];
};

// type PlatformedResponse = {
// [K in keyof FaviconResponse]: Platformed<FaviconResponse[K][number]>[];
// };

type Params = {
options: Options;
platform: PlatformName;
options: Options;
};

async function handleIcons(
async function getIconsForPlatform(
input: Source,
params: Params,
): Promise<FaviconResponse> {
const { options, platform } = params;

const iconOptions = Object.fromEntries(
const offOptions = Object.fromEntries(
Object.entries(options.icons).map(([key, value]) => [
key,
key === platform ? value : false,
key === platform ? value : false, // 将其他平台设置为 false
]),
);

return await favicons(input, {
...options,
icons: iconOptions as Record<
icons: offOptions as Record<
PlatformName,
boolean | (string | NamedIconOptions)[]
>,
Expand All @@ -37,7 +49,7 @@ async function handleIcons(

function mergeResults(
results: { platform: PlatformName; response: FaviconResponse }[],
): FaviconResponse {
): PlatformedResponse {
return results.reduce(
(acc, { platform, response }) => {
acc.images.push(
Expand All @@ -47,19 +59,19 @@ function mergeResults(
acc.html.push(...response.html);
return acc;
},
{ images: [], files: [], html: [] } as FaviconResponse,
{ images: [], files: [], html: [] } as PlatformedResponse,
);
}

export async function collect(
input: InputSource,
options: Options,
): Promise<FaviconResponse> {
): Promise<PlatformedResponse> {
const platforms = Object.keys(options.icons) as PlatformName[];
const results = await Promise.all(
platforms.map(async (platform) => ({
platform,
response: await handleIcons(input?.[platform], { platform, options }),
response: await getIconsForPlatform(input?.[platform], { platform, options }),
})),
);
return mergeResults(results);
Expand Down
5 changes: 4 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ export function mime(fileName: string): string {

const contentTypes: Record<string, string> = {
ico: "image/x-icon",
png: "image/png",
svg: "image/svg+xml",
png: "image/png",
webp: "image/webp",
jpg: "image/jpeg",
jpeg: "image/jpeg",
json: "application/json",
xml: "application/xml",
webmanifest: "application/manifest+json",
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { handleAssets } from "./plugin";
export const name = "astro-favicons";
export interface Options extends FaviconOptions {
/**
* @description
* Specify the source image(s) used to generate platform-specific assets.
* @default `public/favicon.svg`.
* @example
Expand Down
7 changes: 0 additions & 7 deletions src/utils/styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@

const Styles = {
Reset: "\x1b[0m",
Bright: "\x1b[1m",
Dim: "\x1b[2m",
Underscore: "\x1b[4m",
ResetBoldDim: "\x1b[22m",

FgBlack: "\x1b[30m",
FgGreen: "\x1b[32m",
FgYellow: "\x1b[33m",
FgBlue: "\x1b[34m",

BgGreen: "\x1b[42m",
BgBlue: "\x1b[44m",
};

type Style = keyof typeof Styles;
Expand Down

0 comments on commit db703ca

Please sign in to comment.