summaryrefslogtreecommitdiff
path: root/client/simple/tools
diff options
context:
space:
mode:
authorIvan Gabaldon <igabaldon@inetol.net>2025-07-06 12:27:28 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-08-18 16:38:32 +0200
commit60bd8b90f04d5d825fc8ac279cb7fdfde9fe78ea (patch)
tree19b2639638e7845597f9aa839eda39a456188a1c /client/simple/tools
parentadc4361eb919604889dc0661e75ef6ac8cfc4d23 (diff)
[enh] theme/simple: custom router
Lay the foundation for loading scripts granularly depending on the endpoint it's on. Remove vendor specific prefixes as there are now managed by browserslist and LightningCSS. Enabled quite a few rules in Biome that don't come in recommended to better catch issues and improve consistency. Related: - https://github.com/searxng/searxng/pull/5073#discussion_r2256037965 - https://github.com/searxng/searxng/pull/5073#discussion_r2256057100
Diffstat (limited to 'client/simple/tools')
-rw-r--r--client/simple/tools/img.ts40
-rw-r--r--client/simple/tools/jinja_svg_catalog.ts18
-rw-r--r--client/simple/tools/plg.ts6
3 files changed, 30 insertions, 34 deletions
diff --git a/client/simple/tools/img.ts b/client/simple/tools/img.ts
index db4e08645..be27f03fa 100644
--- a/client/simple/tools/img.ts
+++ b/client/simple/tools/img.ts
@@ -17,24 +17,24 @@ export type Src2Dest = {
*
* @param items - Array of SVG files (src: SVG, dest:PNG) to convert.
*/
-export const svg2png = async (items: Src2Dest[]) => {
+export const svg2png = (items: Src2Dest[]): void => {
for (const item of items) {
- try {
- fs.mkdirSync(path.dirname(item.dest), { recursive: true });
+ fs.mkdirSync(path.dirname(item.dest), { recursive: true });
- const info = await sharp(item.src)
- .png({
- force: true,
- compressionLevel: 9,
- palette: true
- })
- .toFile(item.dest);
-
- console.log(`[svg2png] created ${item.dest} -- bytes: ${info.size}, w:${info.width}px, h:${info.height}px`);
- } catch (err) {
- console.error(`ERROR: ${item.dest} -- ${err}`);
- throw err;
- }
+ sharp(item.src)
+ .png({
+ force: true,
+ compressionLevel: 9,
+ palette: true
+ })
+ .toFile(item.dest)
+ .then((info) => {
+ console.log(`[svg2png] created ${item.dest} -- bytes: ${info.size}, w:${info.width}px, h:${info.height}px`);
+ })
+ .catch((error) => {
+ console.error(`ERROR: ${item.dest} -- ${error}`);
+ throw error;
+ });
}
};
@@ -44,7 +44,7 @@ export const svg2png = async (items: Src2Dest[]) => {
* @param items - Array of SVG files (src:SVG, dest:SVG) to optimize.
* @param svgo_opts - Options passed to svgo.
*/
-export const svg2svg = (items: Src2Dest[], svgo_opts: Config) => {
+export const svg2svg = (items: Src2Dest[], svgo_opts: Config): void => {
for (const item of items) {
try {
fs.mkdirSync(path.dirname(item.dest), { recursive: true });
@@ -54,9 +54,9 @@ export const svg2svg = (items: Src2Dest[], svgo_opts: Config) => {
fs.writeFileSync(item.dest, opt.data);
console.log(`[svg2svg] optimized: ${item.dest} -- src: ${item.src}`);
- } catch (err) {
- console.error(`ERROR: optimize src: ${item.src} -- ${err}`);
- throw err;
+ } catch (error) {
+ console.error(`ERROR: optimize src: ${item.src} -- ${error}`);
+ throw error;
}
}
};
diff --git a/client/simple/tools/jinja_svg_catalog.ts b/client/simple/tools/jinja_svg_catalog.ts
index 1fa1a6676..68d9a695d 100644
--- a/client/simple/tools/jinja_svg_catalog.ts
+++ b/client/simple/tools/jinja_svg_catalog.ts
@@ -1,10 +1,8 @@
import fs from "node:fs";
import { dirname, resolve } from "node:path";
-import { fileURLToPath } from "node:url";
import { Edge } from "edge.js";
import { type Config as SvgoConfig, optimize as svgo } from "svgo";
-const __dirname = dirname(fileURLToPath(import.meta.url));
const __jinja_class_placeholder__ = "__jinja_class_placeholder__";
// A set of icons
@@ -43,9 +41,9 @@ export type JinjaMacro = {
* @param macros - Jinja macros to create.
* @param items - Array of SVG items.
*/
-export const jinja_svg_catalog = (dest: string, macros: JinjaMacro[], items: IconSVG[]) => {
+export const jinja_svg_catalog = (dest: string, macros: JinjaMacro[], items: IconSVG[]): void => {
const svg_catalog: Record<string, string> = {};
- const edge_template = resolve(__dirname, "jinja_svg_catalog.html.edge");
+ const edge_template = resolve(import.meta.dirname, "jinja_svg_catalog.html.edge");
for (const item of items) {
// JSON.stringify & JSON.parse are used to create a deep copy of the item.svgo_opts object
@@ -63,15 +61,13 @@ export const jinja_svg_catalog = (dest: string, macros: JinjaMacro[], items: Ico
const opt = svgo(raw, svgo_opts);
svg_catalog[item.name] = opt.data;
- } catch (err) {
- console.error(`ERROR: jinja_svg_catalog processing ${item.name} src: ${item.src} -- ${err}`);
- throw err;
+ } catch (error) {
+ console.error(`ERROR: jinja_svg_catalog processing ${item.name} src: ${item.src} -- ${error}`);
+ throw error;
}
}
- fs.mkdir(dirname(dest), { recursive: true }, (err) => {
- if (err) throw err;
- });
+ fs.mkdirSync(dirname(dest), { recursive: true });
const ctx = {
svg_catalog: svg_catalog,
@@ -97,7 +93,7 @@ export const jinja_svg_catalog = (dest: string, macros: JinjaMacro[], items: Ico
* @param macros - Jinja macros to create.
* @param sets - Array of SVG sets.
*/
-export const jinja_svg_sets = (dest: string, macros: JinjaMacro[], sets: IconSet[]) => {
+export const jinja_svg_sets = (dest: string, macros: JinjaMacro[], sets: IconSet[]): void => {
const items: IconSVG[] = [];
const all: string[] = [];
diff --git a/client/simple/tools/plg.ts b/client/simple/tools/plg.ts
index 2db891d4f..20c2c4e64 100644
--- a/client/simple/tools/plg.ts
+++ b/client/simple/tools/plg.ts
@@ -20,8 +20,8 @@ export const plg_svg2png = (items: Src2Dest[]): Plugin => {
return {
name: "searxng-simple-svg2png",
apply: "build",
- async writeBundle() {
- await svg2png(items);
+ writeBundle: () => {
+ svg2png(items);
}
};
};
@@ -36,7 +36,7 @@ export const plg_svg2svg = (items: Src2Dest[], svgo_opts: Config): Plugin => {
return {
name: "searxng-simple-svg2svg",
apply: "build",
- writeBundle() {
+ writeBundle: () => {
svg2svg(items, svgo_opts);
}
};