@stephansama/astro-iconify-svgmap
Version:
Astro integration for generating iconify svgmaps for ssg sites
59 lines (57 loc) • 1.98 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/const.ts
var const_exports = {};
__export(const_exports, {
CONFIG_FILENAME: () => CONFIG_FILENAME,
LOADED_ICONS_FILENAME: () => LOADED_ICONS_FILENAME,
defaultConfig: () => defaultConfig
});
var FILE_PREFIX, CONFIG_FILENAME, LOADED_ICONS_FILENAME, defaultConfig;
var init_const = __esm({
"src/const.ts"() {
"use strict";
FILE_PREFIX = "node_modules/";
CONFIG_FILENAME = FILE_PREFIX + "iconifysvgmap.config.json";
LOADED_ICONS_FILENAME = FILE_PREFIX + "iconifysvgmap.json";
defaultConfig = {
outDir: "public"
};
}
});
// src/get.ts
async function getIcon(pack, name) {
const onServer = typeof document === "undefined";
const selectedPack = pack === "noto-emoji" ? "noto" : pack;
if (!onServer) return `/${selectedPack}.svg#${name}`;
const fs = await import("fs");
const { LOADED_ICONS_FILENAME: LOADED_ICONS_FILENAME2 } = await Promise.resolve().then(() => (init_const(), const_exports));
const current = fs.readFileSync(LOADED_ICONS_FILENAME2, {
encoding: "utf-8",
flag: "as+"
});
const currentRepresentation = JSON.parse(current || "{}");
const newPack = currentRepresentation[selectedPack]?.includes(name) ? currentRepresentation[selectedPack] : [
.../* @__PURE__ */ new Set([
name,
...currentRepresentation[selectedPack] ? currentRepresentation[selectedPack] : []
])
];
const newRepresentation = {
...currentRepresentation,
[selectedPack]: newPack
};
fs.writeFileSync(LOADED_ICONS_FILENAME2, JSON.stringify(newRepresentation));
return `/${selectedPack}.svg#${name}`;
}
export {
getIcon
};
//# sourceMappingURL=get.js.map