feat: initial release
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { building } from "$app/environment";
|
||||
import { readdirSync } from "node:fs";
|
||||
import { join } from "path";
|
||||
|
||||
export function loadFonts() {
|
||||
try {
|
||||
const fontsDir = join(process.cwd(), "static", "fonts");
|
||||
console.log(fontsDir);
|
||||
const files = readdirSync(fontsDir);
|
||||
console.log(files);
|
||||
|
||||
let fonts = files
|
||||
.filter((file) => /\.(woff2|woff|ttf|otf)$/i.test(file))
|
||||
.map((file) => ({
|
||||
name: file.replace(/\.[^/.]+$/, ""),
|
||||
file,
|
||||
url: `/fonts/${file}`,
|
||||
format: getFormat(file),
|
||||
}));
|
||||
|
||||
return fonts;
|
||||
} catch (error) {
|
||||
console.log("err");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getFormat(filename: string) {
|
||||
if (filename.endsWith(".woff2")) return "woff2";
|
||||
if (filename.endsWith(".woff")) return "woff";
|
||||
if (filename.endsWith(".ttf")) return "truetype";
|
||||
return "opentype";
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { building } from "$app/environment";
|
||||
import { readdirSync } from "node:fs";
|
||||
import { join } from "path";
|
||||
|
||||
export function loadImages() {
|
||||
try {
|
||||
const imagesDir = join(process.cwd(), "static", "backgrounds");
|
||||
const files = readdirSync(imagesDir);
|
||||
|
||||
let fonts = files.filter((file) => /\.(png|jpg)$/i.test(file));
|
||||
|
||||
return fonts;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user