From 0d4172bc307a1a655888549dc05b00e9a8bb48f1 Mon Sep 17 00:00:00 2001 From: Chelakhovl <147933854+Chelakhovl@users.noreply.github.com> Date: Fri, 5 Jan 2024 20:56:55 +0300 Subject: [PATCH] Initial commit --- .github/workflows/validate.yml | 70 ++++++++++++++++++++++++++++++++++ README.md | 8 ++++ index.html | 13 +++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/workflows/validate.yml create mode 100644 README.md create mode 100644 index.html diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..43ba6dc --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,70 @@ +name: HTML Proofer + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 20 + + - name: Install dependencies + run: | + [ -f package.json ] && npm ci || npm init -y + npm install puppeteer http-server + + - name: Serve files and render dynamic HTML using Puppeteer + run: | + npx http-server -p 8080 & + SERVER_PID=$! + sleep 5 + + for file in $(find . -maxdepth 1 -iname "*.html" ! -iname "*.partial.html"); do + echo "Processing file: ${file:2}" + output_file=$file + node -e "const puppeteer = require('puppeteer'); + (async () => { + const url = 'http://localhost:8080/${file:2}'; + const browser = await puppeteer.launch({ + headless: 'new' + }); + const page = await browser.newPage(); + await page.goto(url, {waitUntil: 'networkidle0'}); + const html = await page.content(); + await browser.close(); + const fs = require('fs'); + fs.writeFileSync('$output_file', html); + })().catch(err => { + console.error('Error processing file:', err); + process.exit(1); + });" + done + + kill $SERVER_PID + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 + + - name: Install HTML Proofer + run: gem install html-proofer + + - name: Run HTML Proofer + run: | + for file in $(find . -maxdepth 1 -iname "*.html" ! -iname "*.partial.html"); do + htmlproofer $file --disable-external + done diff --git a/README.md b/README.md new file mode 100644 index 0000000..06efdd1 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# HTML Template Repository with HTML Proofer + +This template repository includes preconfigured GitHub Action that will validate html files in a project with (HTMLProofer)[https://github.com/gjtorikian/html-proofer/]. + +Validation is performed with dynamic pre-rendering of html files so it will allow to construct them with JavaScript on the fly. + +HTML files with 'partial.html' suffix will be ignored, so validator is compatible with dynamic construction of website with html includes like (HTML Data Include)[https://github.com/programmingmentor/html-data-include]. + diff --git a/index.html b/index.html new file mode 100644 index 0000000..e559af6 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + + + +