Skip to content

Instantly share code, notes, and snippets.

@jhancock532
Created April 5, 2022 08:23
Show Gist options
  • Save jhancock532/96ef67901731af496ff87df92d1c214e to your computer and use it in GitHub Desktop.
Save jhancock532/96ef67901731af496ff87df92d1c214e to your computer and use it in GitHub Desktop.
Generates a pa11y.config.js file for a Django pattern library site
import glob
import re
base_url = "http://localhost:8000/pattern-library/render-pattern/patterns"
pattern_libray_pages = glob.glob('**/patterns/pages/**/*.html', recursive=True)
config = """module.exports = {
defaults: {
standard: "WCAG2AAA",
runners: ["axe"],
},
urls: [
"""
for html_file in pattern_libray_pages:
url = base_url + re.sub(r'^.*?patterns', '', html_file)
config += ' "'
config += url
config += '",\n'
config += """ ]
};
"""
f = open("pa11y.config.js", "w")
f.write(config)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment