Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Chelakhovl authored Jan 5, 2024
0 parents commit 0d4172b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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].

13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="shortcut icon" href="https://placekitten.com/96/139" type="image/x-icon">
</head>
<body>
<script src="https://unpkg.com/[email protected]/html-data-include.js"></script>
</body>
</html>

0 comments on commit 0d4172b

Please sign in to comment.