0.13.0 DVD Series

This commit is contained in:
2026-04-10 18:44:41 +00:00
parent 43702b0138
commit 974b7bfad3
36 changed files with 9666 additions and 739 deletions
+33 -2
View File
@@ -45,13 +45,44 @@ function sanitizeFileNameWithExtension(input) {
function renderTemplate(template, values) {
const rawSource = String(template || '${title} (${year})');
const parseToken = (rawToken) => {
const token = String(rawToken || '').trim();
if (!token) {
return { format: '', key: '' };
}
const separatorIndex = token.indexOf(':');
if (separatorIndex <= 0) {
return { format: '', key: token };
}
return {
format: token.slice(0, separatorIndex).trim(),
key: token.slice(separatorIndex + 1).trim()
};
};
const applyFormat = (value, format) => {
const normalizedFormat = String(format || '').trim().toLowerCase();
if (!normalizedFormat) {
return String(value);
}
// {0:key} => number with leading zero (width 2), e.g. 2 -> 02
if (normalizedFormat === '0') {
const raw = String(value);
const match = raw.match(/^(-?)(\d+)$/);
if (match) {
const sign = match[1] || '';
const digits = String(match[2] || '');
return `${sign}${digits.padStart(2, '0')}`;
}
}
return String(value);
};
const resolveToken = (rawKey) => {
const key = String(rawKey || '').trim();
const { format, key } = parseToken(rawKey);
const val = values[key];
if (val === undefined || val === null || val === '') {
return 'unknown';
}
return String(val);
return applyFormat(val, format);
};
const source = (