Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Last active June 13, 2024 02:49
Show Gist options
  • Save devinschumacher/613b02f0752afaf2e004cdc95862eff4 to your computer and use it in GitHub Desktop.
Save devinschumacher/613b02f0752afaf2e004cdc95862eff4 to your computer and use it in GitHub Desktop.
How to run @nuxtjs/html-validator to validate rendered HTML files locally
tags
vue, nuxt, CICD

How to run @nuxtjs/html-validator to validate rendered HTML files locally

  1. Generate static pages with nuxi generate
  2. Get the list of distinct page routes from the generated HTML files
  3. Run html-validator for each distinct page route and create the report

🚧 WIP: Still a work in progress. The script below does not quite work properly, but it's on the righ track

1. Generate static pages with nuxi generate

npx nuxi generate

2. Get the list of distinct page routes from the generated HTML files

pages=$(find . -name '*.html' -print0 | xargs -0 -n 1 basename | cut -d'.' -f1 | sort -u)

3. Run html-validator for each distinct page route and create the report

for page in $pages; do
  echo "Validating page: $page"
  npx html-validator --input dist/$page.html >> html-validator-report.txt 2>&1
done

Bonus: All in one script

# Generate static pages
npx nuxi generate

# Get the list of distinct page routes from the generated HTML files
pages=$(find dist -name '*.html' -print0 | xargs -0 -n 1 basename | cut -d'.' -f1 | sort -u)

# Run html-validator for each distinct page route and create the report
echo "Running HTML validator on generated pages..."
for page in $pages; do
  echo "Validating page: $page"
  npx html-validator --input dist/$page.html --logLevel verbose >> html-validator-report.txt 2>&1
done

echo "HTML validation report generated in html-validator-report.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment