mirror of https://github.com/VERT-sh/VERT.git
Compare commits
No commits in common. "da486dc4ec4c3385741530c7649427fb2bcde480" and "95284a84d4096df7d76d5a50b1cd6bc004c25461" have entirely different histories.
da486dc4ec
...
95284a84d4
|
@ -1,113 +1,46 @@
|
||||||
import { converters } from "$lib/converters";
|
import { converters } from "$lib/converters";
|
||||||
import type { EntryGenerator } from "./$types";
|
import type { EntryGenerator } from "./$types";
|
||||||
|
|
||||||
// only generate slugs for popular formats
|
// generate conversion pairs at build time (e.g. mkv-mp4) for SEO
|
||||||
// vert is static, so we can't generate all possible combinations
|
|
||||||
const VIDEO_FORMATS = [
|
|
||||||
"mp4",
|
|
||||||
"mkv",
|
|
||||||
"avi",
|
|
||||||
"mov",
|
|
||||||
"webm",
|
|
||||||
"flv",
|
|
||||||
"wmv",
|
|
||||||
"mpg",
|
|
||||||
"3gp",
|
|
||||||
];
|
|
||||||
|
|
||||||
const AUDIO_FORMATS = [
|
|
||||||
"mp3",
|
|
||||||
"wav",
|
|
||||||
"flac",
|
|
||||||
"m4a",
|
|
||||||
"ogg",
|
|
||||||
"aiff",
|
|
||||||
"wma",
|
|
||||||
];
|
|
||||||
|
|
||||||
const IMAGE_FORMATS = [
|
|
||||||
"png",
|
|
||||||
"jpg",
|
|
||||||
"jpeg",
|
|
||||||
"jfif",
|
|
||||||
"webp",
|
|
||||||
"jxl",
|
|
||||||
"psd",
|
|
||||||
"ico",
|
|
||||||
"icns",
|
|
||||||
"ppm",
|
|
||||||
"gif",
|
|
||||||
"svg",
|
|
||||||
"bmp",
|
|
||||||
"tiff",
|
|
||||||
"heic",
|
|
||||||
"heif",
|
|
||||||
"avif",
|
|
||||||
];
|
|
||||||
|
|
||||||
const DOCUMENT_FORMATS = [
|
|
||||||
"docx",
|
|
||||||
"doc",
|
|
||||||
"md",
|
|
||||||
"rtf",
|
|
||||||
"odt",
|
|
||||||
"html",
|
|
||||||
"csv",
|
|
||||||
"tsv",
|
|
||||||
"rst",
|
|
||||||
"epub",
|
|
||||||
"docbook",
|
|
||||||
];
|
|
||||||
|
|
||||||
const POPULAR_FORMATS = [
|
|
||||||
...VIDEO_FORMATS,
|
|
||||||
...AUDIO_FORMATS,
|
|
||||||
...IMAGE_FORMATS,
|
|
||||||
...DOCUMENT_FORMATS,
|
|
||||||
];
|
|
||||||
|
|
||||||
export const entries: EntryGenerator = () => {
|
export const entries: EntryGenerator = () => {
|
||||||
const seenPairs = new Set<string>();
|
const seenPairs = new Set<string>();
|
||||||
|
|
||||||
// this would be unnecessary, but certain formats can only be converted one-way (so avoid generating them)
|
const addPair = (
|
||||||
// e.g. heic -> jpg works, but not jpg -> heic
|
fromName: string,
|
||||||
const canConvert = (from: string, to: string): boolean => {
|
fromSupported: boolean,
|
||||||
const fromFormat = `.${from}`;
|
toName: string,
|
||||||
const toFormat = `.${to}`;
|
toSupported: boolean,
|
||||||
|
) => {
|
||||||
|
if (!fromSupported || !toSupported || fromName === toName) return;
|
||||||
|
|
||||||
// check if any converter supports this conversion
|
const from = fromName.replace(".", "").toLowerCase();
|
||||||
for (const converter of converters) {
|
const to = toName.replace(".", "").toLowerCase();
|
||||||
let from = false;
|
const slug = `${from}-${to}`;
|
||||||
let to = false;
|
|
||||||
|
|
||||||
for (const f of converter.supportedFormats) {
|
if (!seenPairs.has(slug)) seenPairs.add(slug);
|
||||||
if (f.name === fromFormat && f.fromSupported) from = true;
|
|
||||||
if (f.name === toFormat && f.toSupported) to = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (from && to) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// generate all combinations from the formats list
|
// check all conversions (same converter and cross-converter)
|
||||||
for (const fromFormat of POPULAR_FORMATS) {
|
for (const fromConverter of converters) {
|
||||||
for (const toFormat of POPULAR_FORMATS) {
|
for (const toConverter of converters) {
|
||||||
if (fromFormat === toFormat) continue;
|
const sameConverter = fromConverter.name === toConverter.name;
|
||||||
|
|
||||||
// exclude video <-> audio conversions
|
for (const fromFormat of fromConverter.supportedFormats) {
|
||||||
const fromVideo = VIDEO_FORMATS.includes(fromFormat);
|
for (const toFormat of toConverter.supportedFormats) {
|
||||||
const toVideo = VIDEO_FORMATS.includes(toFormat);
|
// skip if same converter and same format, or if different converter but formats are the same
|
||||||
const fromAudio = AUDIO_FORMATS.includes(fromFormat);
|
if (sameConverter && fromFormat.name === toFormat.name)
|
||||||
const toAudio = AUDIO_FORMATS.includes(toFormat);
|
continue;
|
||||||
|
if (!sameConverter && fromFormat.name === toFormat.name)
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((fromVideo && toAudio) || (fromAudio && toVideo)) continue;
|
addPair(
|
||||||
|
fromFormat.name,
|
||||||
if (!canConvert(fromFormat, toFormat)) continue;
|
fromFormat.fromSupported,
|
||||||
|
toFormat.name,
|
||||||
const slug = `${fromFormat}-${toFormat}`;
|
toFormat.toSupported,
|
||||||
if (!seenPairs.has(slug)) seenPairs.add(slug);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue