mirror of
https://github.com/PeterMaquiran/tvone.git
synced 2026-04-23 12:35:51 +00:00
This commit is contained in:
+55
-55
@@ -1,63 +1,63 @@
|
|||||||
// import fs from "fs";
|
import fs from "fs";
|
||||||
// import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
// export type SliderPhoto = { src: string; alt: string };
|
export type SliderPhoto = { src: string; alt: string };
|
||||||
|
|
||||||
// function slugToAlt(filename: string): string {
|
function slugToAlt(filename: string): string {
|
||||||
// const base = filename.replace(/\.[^.]+$/, "");
|
const base = filename.replace(/\.[^.]+$/, "");
|
||||||
// const words = base.replace(/[-_]+/g, " ").trim();
|
const words = base.replace(/[-_]+/g, " ").trim();
|
||||||
// return words || "Slide";
|
return words || "Slide";
|
||||||
// }
|
}
|
||||||
|
|
||||||
// export function parseManifest(data: unknown): SliderPhoto[] {
|
export function parseManifest(data: unknown): SliderPhoto[] {
|
||||||
// if (!Array.isArray(data)) return [];
|
if (!Array.isArray(data)) return [];
|
||||||
// const out: SliderPhoto[] = [];
|
const out: SliderPhoto[] = [];
|
||||||
// for (const item of data) {
|
for (const item of data) {
|
||||||
// if (typeof item !== "object" || item === null || !("src" in item)) continue;
|
if (typeof item !== "object" || item === null || !("src" in item)) continue;
|
||||||
// const src = (item as { src: unknown }).src;
|
const src = (item as { src: unknown }).src;
|
||||||
// if (typeof src !== "string" || !src.startsWith("/")) continue;
|
if (typeof src !== "string" || !src.startsWith("/")) continue;
|
||||||
// const altRaw = (item as { alt?: unknown }).alt;
|
const altRaw = (item as { alt?: unknown }).alt;
|
||||||
// const alt = typeof altRaw === "string" && altRaw.trim() ? altRaw.trim() : slugToAlt(src.split("/").pop() ?? "");
|
const alt = typeof altRaw === "string" && altRaw.trim() ? altRaw.trim() : slugToAlt(src.split("/").pop() ?? "");
|
||||||
// out.push({ src, alt });
|
out.push({ src, alt });
|
||||||
// }
|
}
|
||||||
// return out;
|
return out;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// const IMAGE_EXT = /\.(jpe?g|png|webp|gif|avif)$/i;
|
const IMAGE_EXT = /\.(jpe?g|png|webp|gif|avif)$/i;
|
||||||
|
|
||||||
// function scanSliderDirectory(dir: string): SliderPhoto[] {
|
function scanSliderDirectory(dir: string): SliderPhoto[] {
|
||||||
// let names: string[] = [];
|
let names: string[] = [];
|
||||||
// try {
|
try {
|
||||||
// names = fs.readdirSync(dir);
|
names = fs.readdirSync(dir);
|
||||||
// } catch {
|
} catch {
|
||||||
// return [];
|
return [];
|
||||||
// }
|
}
|
||||||
// return names
|
return names
|
||||||
// .filter((f) => IMAGE_EXT.test(f))
|
.filter((f) => IMAGE_EXT.test(f))
|
||||||
// .sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }))
|
.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }))
|
||||||
// .map((f) => ({
|
.map((f) => ({
|
||||||
// src: `/slider/${f}`,
|
src: `/slider/${f}`,
|
||||||
// alt: slugToAlt(f),
|
alt: slugToAlt(f),
|
||||||
// }));
|
}));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Reads `public/slider/manifest.json` when present (full control: order + alt).
|
* Reads `public/slider/manifest.json` when present (full control: order + alt).
|
||||||
// * Otherwise scans `public/slider` for image files (drop-in updates, no code edits).
|
* Otherwise scans `public/slider` for image files (drop-in updates, no code edits).
|
||||||
// */
|
*/
|
||||||
// export function readSliderPhotos(): SliderPhoto[] {
|
export function readSliderPhotos(): SliderPhoto[] {
|
||||||
// const dir = path.join(process.cwd(), "public", "slider");
|
const dir = path.join(process.cwd(), "public", "slider");
|
||||||
// if (!fs.existsSync(dir)) return [];
|
if (!fs.existsSync(dir)) return [];
|
||||||
|
|
||||||
// const manifestPath = path.join(dir, "manifest.json");
|
const manifestPath = path.join(dir, "manifest.json");
|
||||||
// if (fs.existsSync(manifestPath)) {
|
if (fs.existsSync(manifestPath)) {
|
||||||
// try {
|
try {
|
||||||
// const raw = JSON.parse(fs.readFileSync(manifestPath, "utf8")) as unknown;
|
const raw = JSON.parse(fs.readFileSync(manifestPath, "utf8")) as unknown;
|
||||||
// return parseManifest(raw);
|
return parseManifest(raw);
|
||||||
// } catch {
|
} catch {
|
||||||
// return [];
|
return [];
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return scanSliderDirectory(dir);
|
return scanSliderDirectory(dir);
|
||||||
// }
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user