Supporting value wrap in summary template.

This commit is contained in:
DebaucheryLibrarian 2024-08-29 02:19:57 +02:00
parent e3ed54fe3c
commit aa3eb3df33
1 changed files with 4 additions and 6 deletions

View File

@ -48,13 +48,11 @@ function curateValue(value, item) {
.slice(0, item.limit || Infinity) .slice(0, item.limit || Infinity)
.map((listValue) => (item.slugify ? slugify(listValue, item.slugify) : listValue)) .map((listValue) => (item.slugify ? slugify(listValue, item.slugify) : listValue))
.map((listValue) => ellipsis(listValue, item.slice || Infinity, item.ellipsis || '')) .map((listValue) => ellipsis(listValue, item.slice || Infinity, item.ellipsis || ''))
.map((listValue) => `${item.wrap?.[0] || ''}${listValue}${item.wrap?.[1] || ''}`)
.join(item.delimit || ', '); .join(item.delimit || ', ');
} }
function traverseTemplate(chain, release, { function traverseTemplate(chain, release, { delimit = ' ' } = {}) {
delimit = ' ',
wrap = ['', ''],
} = {}) {
const results = chain.reduce((result, item) => { const results = chain.reduce((result, item) => {
const keys = typeof item === 'string' ? item : item.key; const keys = typeof item === 'string' ? item : item.key;
@ -77,7 +75,6 @@ function traverseTemplate(chain, release, {
if (item.items) { if (item.items) {
const group = traverseTemplate(item.items, release, { const group = traverseTemplate(item.items, release, {
delimit: item.delimit, delimit: item.delimit,
wrap: item.wrap,
}); });
return result.concat(curateValue(group, item)); return result.concat(curateValue(group, item));
@ -87,7 +84,8 @@ function traverseTemplate(chain, release, {
}, []); }, []);
if (results.length > 0) { if (results.length > 0) {
return `${wrap[0] || ''}${results.filter(Boolean).join(delimit)}${wrap[1] || ''}`; // return `${wrap[0] || ''}${results.filter(Boolean).join(delimit)}${wrap[1] || ''}`;
return results.filter(Boolean).join(delimit);
} }
return ''; return '';