Skip to content

Commit

Permalink
Update expire-old-content.js
Browse files Browse the repository at this point in the history
Co-Authored-By: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
RichardKanshen and coderabbitai[bot] committed Nov 10, 2024
1 parent 0927126 commit c1d0d22
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions expire-old-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function updateOldComponents() {
// First pass: collect expired image names that should be removed
content.replace(/<img [^>]*src=\{([^}]+)\}[^>]*valid-until="([^"]+)"[^>]*>/g, (match, imgVar, dateStr) => {
const expirationDate = new Date(dateStr);
if (isNaN(expirationDate.getTime())) {
if (Number.isNaN(expirationDate.getTime())) {
console.log(`WARNING! Invalid date format - ${dateStr}`);
return match;
}
Expand Down Expand Up @@ -155,8 +155,18 @@ function updateCronSchedule() {
// Format dates for cron
const cronEntries = Array.from(cronDates).map(dateStr => {
const date = new Date(dateStr);
if (Number.isNaN(date.getTime())) {
console.log(`WARNING! Invalid date format - ${dateStr} - Skipping cron entry.`);
return null;
}
const day = date.getDate();
const month = date.getMonth() + 1;
if (day < 1 || day > 31 || month < 1 || month > 12) {
console.log(`WARNING! Invalid date values - ${dateStr} - Skipping cron entry.`);
return null;
}
return ` - cron: "0 0 ${date.getDate()} ${date.getMonth() + 1} *"`;
}).join('\n');
}).filter(Boolean).join('\n');

// Read and update the workflow file
try {
Expand Down

0 comments on commit c1d0d22

Please sign in to comment.