Skip to content

Commit

Permalink
update: clear builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Rooyca committed Mar 13, 2024
1 parent 559a767 commit c7a1070
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions builder/builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Function to generate sequential numbers
function generateSequentialNumbers(startDate, endDate) {
let result = [];
const result = [];
let currentDate = new Date(startDate);

while (currentDate <= endDate) {
Expand All @@ -10,7 +10,7 @@ function generateSequentialNumbers(startDate, endDate) {
return result;
}

function getMovieFromJsonAtIndex(index){
function getMovieFromJsonAtIndex(index) {
const movies = require('./movies.json');
return movies['movies'][index];
}
Expand All @@ -25,30 +25,45 @@ const sequentialNumbers = generateSequentialNumbers(startDate, endDate);
const today = new Date();
const formattedDate = today.toISOString().split('T')[0];

// Read the HTML template once
const fs = require('fs');
let html = fs.readFileSync('./src/index.html', 'utf8');

for (let index = 0; index < sequentialNumbers.length; index++) {
const number = sequentialNumbers[index];
const date = new Date(number);
if (date.toISOString().split('T')[0] === formattedDate) {
console.log(`Today's number is: ${index+1}`);
console.log(`Today's number is: ${index + 1}`);
const movieToday = getMovieFromJsonAtIndex(index);
console.log(`Today's movie: ${movieToday.title}`);
const fs = require('fs');

// Read the HTML template
let html = fs.readFileSync('./src/index.html', 'utf8');

// Replace placeholders with actual data
html = html.replace('__POSTER__', movieToday.img);
html = html.replace('__TITLE__', movieToday.title);
html = html.replace('__DIRECTOR__', movieToday.director);
html = html.replace('__DESCRIPTION__', movieToday.desc);
html = html.replace('__YEAR__', movieToday.year);
html = html.replace('__TAGS__', movieToday.tags);
html = html.replace('__LENGTH__', movieToday.length);
html = html.replace('__DATE__', new Date().toDateString());

// Write the populated HTML
fs.writeFileSync('./src/index.html', html);
html = html.replace(/__POSTER__|__TITLE__|__DIRECTOR__|__DESCRIPTION__|__YEAR__|__TAGS__|__LENGTH__|__DATE__/g, match => {
switch (match) {
case '__POSTER__':
return movieToday.img;
case '__TITLE__':
return movieToday.title;
case '__DIRECTOR__':
return movieToday.director;
case '__DESCRIPTION__':
return movieToday.desc;
case '__YEAR__':
return movieToday.year;
case '__TAGS__':
return movieToday.tags;
case '__LENGTH__':
return movieToday.length;
case '__DATE__':
return new Date().toDateString();
default:
return match;
}
});

break;
}
}

// Write the populated HTML
fs.writeFileSync('./src/index.html', html);

0 comments on commit c7a1070

Please sign in to comment.