|
| 1 | +import { favicons } from "favicons"; |
| 2 | +import { mkdirSync, writeFileSync } from "fs"; |
| 3 | +import { basename, join } from "path"; |
| 4 | + |
| 5 | +export async function generateFavicons( |
| 6 | + metaDesc, |
| 7 | + version, |
| 8 | + baseImage = "fav.png", |
| 9 | + appName = basename(process.cwd()), |
| 10 | + basepath = join(process.cwd(), "public"), |
| 11 | + faviconsPath = "favicons", |
| 12 | + devName = "Darsan", |
| 13 | + devWebsite = "https://darsan.in" |
| 14 | +) { |
| 15 | + const options = { |
| 16 | + path: faviconsPath, |
| 17 | + |
| 18 | + appName: appName, |
| 19 | + appDescription: metaDesc, |
| 20 | + version: version, |
| 21 | + |
| 22 | + developerName: devName, |
| 23 | + developerURL: devWebsite, |
| 24 | + |
| 25 | + background: "#fff", |
| 26 | + theme_color: "#fff", |
| 27 | + appleStatusBarStyle: "black-translucent", |
| 28 | + |
| 29 | + display: "fullscreen", |
| 30 | + orientation: "natural", |
| 31 | + |
| 32 | + start_url: "/", |
| 33 | + |
| 34 | + manifestMaskable: true, |
| 35 | + |
| 36 | + icons: { |
| 37 | + android: true, |
| 38 | + appleIcon: true, |
| 39 | + favicons: true, |
| 40 | + yandex: true, |
| 41 | + appleStartup: false, |
| 42 | + windows: false, |
| 43 | + }, |
| 44 | + |
| 45 | + shortcuts: {}, |
| 46 | + }; |
| 47 | + |
| 48 | + try { |
| 49 | + const { images, files, html } = await favicons(baseImage, options); |
| 50 | + |
| 51 | + const rootPath = join(basepath, faviconsPath); |
| 52 | + mkdirSync(rootPath, { recursive: true }); |
| 53 | + |
| 54 | + /* write images */ |
| 55 | + images.forEach((image) => { |
| 56 | + writeFileSync(join(rootPath, image.name), image.contents, { |
| 57 | + encoding: "binary", |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + /* write config files */ |
| 62 | + files.forEach((file) => { |
| 63 | + writeFileSync(join(rootPath, file.name), file.contents, { |
| 64 | + encoding: "utf8", |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + const faviconsHtmlLinks = html.join(""); |
| 69 | + writeFileSync(join(basepath, "links.html"), faviconsHtmlLinks); |
| 70 | + } catch (err) { |
| 71 | + console.error(err); |
| 72 | + process.exit(1); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +generateFavicons( |
| 77 | + "Hawk JS is the ultimate tool for web developers and SEO enthusiasts. Find out how it can streamline your SEO efforts, ensuring your website gains visibility and improves its search engine ranking.", |
| 78 | + "1.0.7" |
| 79 | +); |
0 commit comments