diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 1b79b05..4e91d53 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -18,12 +18,6 @@ jobs: - name: Create current.json 📝 run: node ./builder/builder.js - - name: Move current.json ↪️ - run: mv current.json src/current.json - - - name: Populate HTML 🌳 - run: node ./builder/populate-html.js - - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@v4 with: diff --git a/README.md b/README.md index 561d4d2..9230d11 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,16 @@ # 1001M -Everyday get one movie from the `1001 Movies You Must See Before You Die` list. \ No newline at end of file +![deployment](https://img.shields.io/github/deployments/rooyca/1001M/github-pages) + +Everyday get one movie from the [1001 Movies You Must See Before You Die](builder/movies.json) list. + +![preview](preview.png) + +## How does it work? + +- We have a list of movies in `builder/movies.json`. +- Everyday a Github Action runs and picks a movie corresponding to the day. +- The movie is moved to `current.json`. +- Another Action runs to populate the HTML file with the movie details. +- Finally, the `src` folder is pushed to the `gh-pages` branch. +- The website is hosted using Github Pages. [Check it out here](https://rooyca.github.io/1001M). \ No newline at end of file diff --git a/builder/builder.js b/builder/builder.js index fc85f73..7514cf4 100644 --- a/builder/builder.js +++ b/builder/builder.js @@ -33,8 +33,25 @@ for (let index = 0; index < sequentialNumbers.length; index++) { const movieToday = getMovieFromJsonAtIndex(index); console.log(`Today's movie: ${movieToday.title}`); const fs = require('fs'); - const content = JSON.stringify(movieToday); - fs.writeFileSync('current.json', content); + + // Read data from current.json + const data = JSON.parse(movieToday); + + // Read the HTML template + let html = fs.readFileSync('./src/index.html', 'utf8'); + + // Replace placeholders with actual data + html = html.replace('__POSTER__', data.img); + html = html.replace('__TITLE__', data.title); + html = html.replace('__DIRECTOR__', data.director); + html = html.replace('__DESCRIPTION__', data.desc); + html = html.replace('__YEAR__', data.year); + html = html.replace('__TAGS__', data.tags); + html = html.replace('__LENGTH__', data.length); + html = html.replace('__DATE__', new Date().toDateString()); + + // Write the populated HTML to a new file + fs.writeFileSync('./src/index.html', html); break; } } diff --git a/preview.png b/preview.png new file mode 100644 index 0000000..94090e5 Binary files /dev/null and b/preview.png differ