Skip to content

Commit

Permalink
add header test
Browse files Browse the repository at this point in the history
  • Loading branch information
alifeee committed Sep 16, 2023
1 parent 24edbc2 commit 58d68e4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Verify page formatting

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Verify header
run: |
python ./utilities.py/header.py
33 changes: 33 additions & 0 deletions utilities.py/header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""ensure all headers have the same format"""

import os
import re

# test for two <a tags (for header and rss feed)
# <header>
# <a href="./">
# <h1>alifeee's blog</h1>
# </a>
# <a id="rss" href="./feed.xml">
# <img alt="_RSS_" src="./icons/rss.svg" />
# </a>
# </header>

HEADER_REGEX = r"<header>[.\n\s\S]*<a[.\n\s\S]*<a[.\n\s\S]*<\/header>"


def get_all_html_files():
"""get all html files recursively"""
html_files = []
for root, _, files in os.walk("."):
for foile in files:
if foile.endswith(".html"):
html_files.append(os.path.join(root, foile))
return html_files


for file in get_all_html_files():
with open(file, "r", encoding="utf-8") as f:
content = f.read()
if not re.search(HEADER_REGEX, content):
raise AssertionError(f"Header not found in {file}")

0 comments on commit 58d68e4

Please sign in to comment.