Fix ugens madplan buttoncardjstemplateerror

- Skift YAML > (folded) til | (literal) - bevarer newlines korrekt
- Fjern nested template literals som button-card ikke kan parse
- Brug string concatenation i stedet for backtick templates
- Tilføj null-check for manglende entity data
- Fjern // kommentarer der kan foldes forkert
This commit is contained in:
2026-04-19 13:31:43 +02:00
parent 6e9e28274c
commit 27228815ba
+16 -29
View File
@@ -80,29 +80,23 @@ cards:
- background: none - background: none
- box-shadow: none - box-shadow: none
custom_fields: custom_fields:
week: > week: |
[[[ [[[
const items = entity.attributes.items || []; if (!entity || !entity.attributes || !entity.attributes.items)
return 'Ingen madplan data';
const items = entity.attributes.items;
const dayNames = ['Søndag','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag']; const dayNames = ['Søndag','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag'];
const today = new Date().toISOString().slice(0,10); const today = new Date().toISOString().slice(0,10);
// Build date->meal map
const meals = {}; const meals = {};
items.forEach(item => { items.forEach(function(item) {
if (item.recipe && item.recipe.name) { if (item.recipe && item.recipe.name) {
meals[item.date] = { meals[item.date] = { name: item.recipe.name, slug: item.recipe.slug || '' };
name: item.recipe.name,
slug: item.recipe.slug || ''
};
} }
}); });
// Generate 7 days starting from Monday of current week
const now = new Date(); const now = new Date();
const dayOfWeek = now.getDay(); const dayOfWeek = now.getDay();
const monday = new Date(now); const monday = new Date(now);
monday.setDate(now.getDate() - (dayOfWeek === 0 ? 6 : dayOfWeek - 1)); monday.setDate(now.getDate() - (dayOfWeek === 0 ? 6 : dayOfWeek - 1));
let html = '<div style="width:100%">'; let html = '<div style="width:100%">';
for (let i = 0; i < 7; i++) { for (let i = 0; i < 7; i++) {
const d = new Date(monday); const d = new Date(monday);
@@ -111,33 +105,26 @@ cards:
const dayName = dayNames[d.getDay()]; const dayName = dayNames[d.getDay()];
const meal = meals[dateStr]; const meal = meals[dateStr];
const isToday = dateStr === today; const isToday = dateStr === today;
const bg = isToday ? 'var(--primary-color)' : 'transparent'; const bg = isToday ? 'var(--primary-color)' : 'transparent';
const textColor = isToday ? 'white' : 'var(--primary-text-color)'; const textColor = isToday ? 'white' : 'var(--primary-text-color)';
const dayColor = isToday ? 'rgba(255,255,255,0.7)' : 'var(--secondary-text-color)'; const dayColor = isToday ? 'rgba(255,255,255,0.7)' : 'var(--secondary-text-color)';
const weight = isToday ? 'bold' : 'normal'; const weight = isToday ? 'bold' : 'normal';
const radius = isToday ? '8px' : '0'; const radius = isToday ? '8px' : '0';
const border = isToday ? 'none' : '1px solid var(--divider-color)'; const border = isToday ? 'none' : '1px solid var(--divider-color)';
const mealName = meal ? meal.name : '—'; const mealName = meal ? meal.name : '—';
const slug = meal ? meal.slug : ''; const slug = meal ? meal.slug : '';
const link = slug ? 'http://anneclaus.dk:9925/g/home/r/' + slug : ''; const link = slug ? 'http://anneclaus.dk:9925/g/home/r/' + slug : '';
const cursor = slug ? 'pointer' : 'default'; const cursor = slug ? 'pointer' : 'default';
const clickAttr = slug ? ' onclick="window.open(\'' + link + '\',\'_blank\')"' : '';
html += ` html += '<div style="display:flex;align-items:center;padding:10px 12px;'
<div style="display:flex; align-items:center; padding:10px 12px; + 'background:' + bg + ';border-radius:' + radius + ';'
background:${bg}; border-radius:${radius}; + 'border-bottom:' + border + ';cursor:' + cursor + '"'
border-bottom:${border}; cursor:${cursor}" + clickAttr + '>'
${slug ? `onclick="window.open('${link}','_blank')"` : ''}> + '<div style="width:70px;font-size:12px;color:' + dayColor
<div style="width:70px; font-size:12px; color:${dayColor}; + ';text-transform:uppercase;font-weight:600">' + dayName + '</div>'
text-transform:uppercase; font-weight:600"> + '<div style="flex:1;font-size:15px;color:' + textColor
${dayName} + ';font-weight:' + weight + '">' + mealName + '</div>'
</div> + '</div>';
<div style="flex:1; font-size:15px; color:${textColor};
font-weight:${weight}">
${mealName}
</div>
</div>`;
} }
html += '</div>'; html += '</div>';
return html; return html;