A script and pre-commit hook that enforces that all links
in a Jekyll project are relative to {{ site.baseurl }}.
The reasoning behind this is that links like [link](/absolute/link) will break if the site is not
directly deployed at domain.com, but e.g. at user.github.io/projectname.
For example, the following lines should raise errors:
Markdown:
[link](/absolute/link)
HTML:
href="/absolute/link"
src="/absolute/picture.png"Simply run the following (no explicit installation required)
pre-commit try-repo https://github.com/klieret/jekyll-relative-url-check jekyll-relative-url-check-html --verbose --all-files
pre-commit try-repo https://github.com/klieret/jekyll-relative-url-check jekyll-relative-url-check-markdown --verbose --all-filesInclude the following snippet in your pre-commit config
repos:
- repo: https://github.com/klieret/jekyll-relative-url-check
rev: main
hooks:
- id: jekyll-relative-url-check-html
- id: jekyll-relative-url-check-markdownAfterwards run pre-commit autoupdate to replace main with the latest release.
pip3 install .
jekyll-relative-url-check-html [FILE]...
jekyll-relative-url-check-markdown [FILE]...- Include
JEKYLL_RELATIVE_URL_CHECK_SKIP_FILEin a file to skip checking the entire file. - Include
JEKYLL_RELATIVE_URL_CHECK_SKIP_LINEin a line to skip checking it
Currently this hook only works by checking for several simple regular expressions.