mirror of
https://gitlab.com/lvra/lvra.gitlab.io.git
synced 2024-12-25 15:20:26 +01:00
Check links in CI with htmlcheck
Remove test_links.py
This commit is contained in:
parent
9e2c8fe2d5
commit
1f27801aad
4 changed files with 47 additions and 51 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -7,3 +7,6 @@ node_modules/
|
||||||
public/
|
public/
|
||||||
resources/
|
resources/
|
||||||
.deploy*/
|
.deploy*/
|
||||||
|
|
||||||
|
# htmltest
|
||||||
|
tmp/
|
|
@ -1,28 +1,43 @@
|
||||||
variables:
|
variables:
|
||||||
GIT_SUBMODULE_STRATEGY: recursive
|
GIT_SUBMODULE_STRATEGY: recursive
|
||||||
|
|
||||||
test-links:
|
## GitLab defaults to:
|
||||||
image: python:latest
|
# stages:
|
||||||
script:
|
# - build
|
||||||
- python3 ./test_links.py
|
# - test
|
||||||
|
# - deploy
|
||||||
|
|
||||||
test-trailing-spaces:
|
build-site:
|
||||||
script:
|
stage: build
|
||||||
- ./test_trailing_spaces.sh
|
|
||||||
|
|
||||||
test-build:
|
|
||||||
image: registry.gitlab.com/pages/hugo/hugo_extended
|
|
||||||
script:
|
|
||||||
- hugo
|
|
||||||
except:
|
|
||||||
- main
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: registry.gitlab.com/pages/hugo/hugo_extended
|
image: registry.gitlab.com/pages/hugo/hugo_extended
|
||||||
script:
|
script:
|
||||||
- hugo
|
- hugo
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
|
||||||
|
test-html:
|
||||||
|
stage: test
|
||||||
|
image:
|
||||||
|
name: wjdp/htmltest:latest
|
||||||
|
entrypoint: [""]
|
||||||
|
cache:
|
||||||
|
key: htmltest-cache
|
||||||
|
paths:
|
||||||
|
- tmp/
|
||||||
|
script:
|
||||||
|
- htmltest
|
||||||
|
|
||||||
|
test-trailing-spaces:
|
||||||
|
stage: test
|
||||||
|
needs: [] # ok to run before build-site
|
||||||
|
script:
|
||||||
|
- ./test_trailing_spaces.sh
|
||||||
|
|
||||||
|
# The GitLab Pages job must always be named "pages", and result in a "public" artifact.
|
||||||
|
# Our "public" artifact is created above, but GitLab jobs will fetch all artifacts from previous stages.
|
||||||
|
pages:
|
||||||
|
stage: deploy
|
||||||
|
script: ls -ld public
|
||||||
only:
|
only:
|
||||||
- main
|
- main
|
||||||
|
|
11
.htmltest.yml
Normal file
11
.htmltest.yml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# https://github.com/wjdp/htmltest?tab=readme-ov-file#wrench-configuration
|
||||||
|
|
||||||
|
DirectoryPath: "public"
|
||||||
|
EnforceHTTPS: true
|
||||||
|
IgnoreURLs:
|
||||||
|
# - "example.com"
|
||||||
|
# - "^/misc/js/script.js$"
|
||||||
|
- "https://gitlab.com/lvra/lvra.gitlab.io/-/edit"
|
||||||
|
# IgnoreDirs:
|
||||||
|
# - "lib"
|
||||||
|
CacheExpires: "6h"
|
|
@ -1,33 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
from pathlib import Path
|
|
||||||
import re
|
|
||||||
from typing import List
|
|
||||||
from os.path import exists
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_markdown_files():
|
|
||||||
return Path("content").rglob("*.md")
|
|
||||||
|
|
||||||
|
|
||||||
def find_links(f: str) -> List[str]:
|
|
||||||
with open(f, "r") as fd:
|
|
||||||
content = fd.read()
|
|
||||||
return [
|
|
||||||
link.lstrip("]").strip("()") for link in re.findall(r"\]\(\/[\w\/]+\)", content)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def verify_link_exists(link: str) -> bool:
|
|
||||||
return exists(f"content{link}/_index.md") or exists(f'content{link.rstrip("/")}.md')
|
|
||||||
|
|
||||||
|
|
||||||
md_files = get_all_markdown_files()
|
|
||||||
|
|
||||||
res = 0
|
|
||||||
for f in md_files:
|
|
||||||
for link in find_links(f):
|
|
||||||
if not verify_link_exists(link):
|
|
||||||
print(f"E: {f}: {link} does not exist")
|
|
||||||
res = 1
|
|
||||||
|
|
||||||
exit(res)
|
|
Loading…
Reference in a new issue