# Added prettier-hmtl.yml ## GitHub Workflow ## Purpose The GitHub Workflow formats the html files on gh-pages. The html files generated are always on a single line. This makes scaling programs a lot more difficult. By formatting the HTML files, al-folio can now be used to generate code which can then be modified to allow for using back-end. ## Errors found I want to let you know that when I was using prettier for this, it kept crashing and after some debugging I found out that al-folio was generating an invalid tag ```</source>```. ```<source>``` is a self-closing tag and doesn't have a separate closing tag. Error: ```<source src="URL" type="type"></source>``` Correct: ```<source src="URL" type="type">``` ## Workflow Description 1. The workflow starts by checking out the gh-pages branch. 2. Then it finds all ```</source>``` tags in all html files and deletes them. 3. It Installs NodeJS and then Prettier. To make sure the code was executed properly, the workflow checks if prettier is present. 4. Then the workflow runs prettier on all html files present in gh-pages 5. It ends by committing the changes and pushing them to the gh-pages directory # Example: > Before >  > After > 
37 lines
935 B
YAML
37 lines
935 B
YAML
name: Prettify gh-pages
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
format:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout gh-pages branch
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: gh-pages
|
|
|
|
- name: Find and Remove </source> Tags
|
|
run: find . -type f -name "*.html" -exec sed -i 's/<\/source>//g' {} +
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
|
|
- name: Install Prettier
|
|
run: npm install -g prettier
|
|
|
|
- name: Check for Prettier
|
|
run: npx prettier --version || echo "Prettier not found"
|
|
|
|
- name: Run Prettier on HTML files
|
|
run: npx prettier --write '**/*.html'
|
|
|
|
- name: Commit and push changes
|
|
run: |
|
|
git config user.name "github-actions"
|
|
git config user.email "actions@github.com"
|
|
git add .
|
|
git commit -m "Formatted HTML files" || echo "No changes to commit"
|
|
git push
|