Skip to content

Commit

Permalink
update: simpler builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Rooyca committed Mar 13, 2024
1 parent 862750c commit 58c5f14
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# 1001M

Everyday get one movie from the `1001 Movies You Must See Before You Die` list.
![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).
21 changes: 19 additions & 2 deletions builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Binary file added preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 58c5f14

Please sign in to comment.