mirror of https://github.com/VERT-sh/VERT.git
Compare commits
2 Commits
95284a84d4
...
da486dc4ec
Author | SHA1 | Date |
---|---|---|
|
da486dc4ec | |
|
4e88a1fd52 |
|
@ -1,46 +1,113 @@
|
||||||
import { converters } from "$lib/converters";
|
import { converters } from "$lib/converters";
|
||||||
import type { EntryGenerator } from "./$types";
|
import type { EntryGenerator } from "./$types";
|
||||||
|
|
||||||
// generate conversion pairs at build time (e.g. mkv-mp4) for SEO
|
// only generate slugs for popular formats
|
||||||
|
// 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>();
|
||||||
|
|
||||||
const addPair = (
|
// this would be unnecessary, but certain formats can only be converted one-way (so avoid generating them)
|
||||||
fromName: string,
|
// e.g. heic -> jpg works, but not jpg -> heic
|
||||||
fromSupported: boolean,
|
const canConvert = (from: string, to: string): boolean => {
|
||||||
toName: string,
|
const fromFormat = `.${from}`;
|
||||||
toSupported: boolean,
|
const toFormat = `.${to}`;
|
||||||
) => {
|
|
||||||
if (!fromSupported || !toSupported || fromName === toName) return;
|
|
||||||
|
|
||||||
const from = fromName.replace(".", "").toLowerCase();
|
// check if any converter supports this conversion
|
||||||
const to = toName.replace(".", "").toLowerCase();
|
for (const converter of converters) {
|
||||||
const slug = `${from}-${to}`;
|
let from = false;
|
||||||
|
let to = false;
|
||||||
|
|
||||||
if (!seenPairs.has(slug)) seenPairs.add(slug);
|
for (const f of converter.supportedFormats) {
|
||||||
|
if (f.name === fromFormat && f.fromSupported) from = true;
|
||||||
|
if (f.name === toFormat && f.toSupported) to = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (from && to) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// check all conversions (same converter and cross-converter)
|
// generate all combinations from the formats list
|
||||||
for (const fromConverter of converters) {
|
for (const fromFormat of POPULAR_FORMATS) {
|
||||||
for (const toConverter of converters) {
|
for (const toFormat of POPULAR_FORMATS) {
|
||||||
const sameConverter = fromConverter.name === toConverter.name;
|
if (fromFormat === toFormat) continue;
|
||||||
|
|
||||||
for (const fromFormat of fromConverter.supportedFormats) {
|
// exclude video <-> audio conversions
|
||||||
for (const toFormat of toConverter.supportedFormats) {
|
const fromVideo = VIDEO_FORMATS.includes(fromFormat);
|
||||||
// skip if same converter and same format, or if different converter but formats are the same
|
const toVideo = VIDEO_FORMATS.includes(toFormat);
|
||||||
if (sameConverter && fromFormat.name === toFormat.name)
|
const fromAudio = AUDIO_FORMATS.includes(fromFormat);
|
||||||
continue;
|
const toAudio = AUDIO_FORMATS.includes(toFormat);
|
||||||
if (!sameConverter && fromFormat.name === toFormat.name)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
addPair(
|
if ((fromVideo && toAudio) || (fromAudio && toVideo)) continue;
|
||||||
fromFormat.name,
|
|
||||||
fromFormat.fromSupported,
|
if (!canConvert(fromFormat, toFormat)) continue;
|
||||||
toFormat.name,
|
|
||||||
toFormat.toSupported,
|
const slug = `${fromFormat}-${toFormat}`;
|
||||||
);
|
if (!seenPairs.has(slug)) seenPairs.add(slug);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue