@mintlify/prebuild 1.0.681 → 1.0.683

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import type { MintConfig } from '@mintlify/models';
2
2
  import type { DocsConfig } from '@mintlify/validation';
3
3
  import { type FaviconResponse, type FaviconOptions } from 'favicons';
4
+ export declare const getImageBuf: (path: string) => Promise<Buffer | null>;
4
5
  export declare function generateFavicons(config: MintConfig | DocsConfig, contentDirectoryPath: string): Promise<FaviconResponse[] | undefined>;
5
6
  export declare function getFaviconsConfig(name: string): FaviconOptions;
@@ -1,22 +1,43 @@
1
1
  import favicons from 'favicons';
2
2
  import { readFile } from 'fs/promises';
3
3
  import { join } from 'path';
4
+ import sharp from 'sharp';
5
+ import { sharpsFromIco } from 'sharp-ico';
6
+ export const getImageBuf = async (path) => {
7
+ if (path.endsWith('.ico')) {
8
+ const icoFaviconBuffer = await readFile(path);
9
+ const sharps = sharpsFromIco(icoFaviconBuffer);
10
+ const icos = await Promise.all(sharps.map(async (ico) => {
11
+ const buf = 'data' in ico ? await sharp(ico.data).png().toBuffer() : await ico.png().toBuffer();
12
+ return { buf, len: buf.length };
13
+ }));
14
+ icos.sort((a, b) => b.len - a.len);
15
+ return icos[0]?.buf ?? null;
16
+ }
17
+ else {
18
+ const faviconBuffer = await readFile(path);
19
+ return faviconBuffer;
20
+ }
21
+ };
4
22
  export async function generateFavicons(config, contentDirectoryPath) {
5
23
  if (config.favicon == null)
6
24
  return;
7
25
  const faviconsConfig = getFaviconsConfig(config.name);
8
26
  try {
9
27
  if (typeof config.favicon === 'string') {
10
- const desiredPath = join(contentDirectoryPath, config.favicon);
11
- const favicon = await readFile(desiredPath);
28
+ const favicon = await getImageBuf(join(contentDirectoryPath, config.favicon));
29
+ if (!favicon)
30
+ return;
12
31
  const icons = await favicons(favicon, faviconsConfig);
13
32
  return [icons];
14
33
  }
15
34
  else {
16
35
  const lightPath = join(contentDirectoryPath, config.favicon.light);
17
36
  const darkPath = join(contentDirectoryPath, config.favicon.dark);
18
- const lightFavicon = await readFile(lightPath);
19
- const darkFavicon = await readFile(darkPath);
37
+ const lightFavicon = await getImageBuf(lightPath);
38
+ const darkFavicon = await getImageBuf(darkPath);
39
+ if (!lightFavicon || !darkFavicon)
40
+ return;
20
41
  const [lightIcons, darkIcons] = await Promise.all([
21
42
  favicons(lightFavicon, faviconsConfig),
22
43
  favicons(darkFavicon, { ...faviconsConfig, path: '/favicons-dark' }),
@@ -26,7 +47,7 @@ export async function generateFavicons(config, contentDirectoryPath) {
26
47
  }
27
48
  catch (err) {
28
49
  if (err instanceof Error) {
29
- console.log(err.message);
50
+ console.log('Error generating favicons: ', err.message);
30
51
  }
31
52
  }
32
53
  }