Skip to content

Add support for ignoring every URL on a page #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ plugins:
warn_on_ignored_urls: true
```

### `ignore_pages`

Avoid validating the URLs on the given list of markdown pages by ignoring them altogether.
Each page in the list supports unix style wildcards `*`, `[]`, `?`, etc.

```yaml
plugins:
- search
- htmlproofer:
raise_error: True
ignore_pages:
- path/to/file
- path/to/folder/*
```

### `validate_external_urls`

Avoids validating any external URLs (i.e those starting with http:// or https://).
Expand Down
7 changes: 7 additions & 0 deletions htmlproofer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class HtmlProoferPlugin(BasePlugin):
('validate_rendered_template', config_options.Type(bool, default=False)),
('ignore_urls', config_options.Type(list, default=[])),
('warn_on_ignored_urls', config_options.Type(bool, default=False)),
('ignore_pages', config_options.Type(list, default=[])),
)

def __init__(self):
Expand Down Expand Up @@ -123,6 +124,12 @@ def on_post_page(self, output_content: str, page: Page, config: Config) -> None:
if any(fnmatch.fnmatch(url, ignore_url) for ignore_url in self.config['ignore_urls']):
if self.config['warn_on_ignored_urls']:
log_warning(f"ignoring URL {url} from {page.file.src_path}")
elif any(
fnmatch.fnmatch(page.file.src_path, ignore_page)
for ignore_page in self.config['ignore_pages']
):
if self.config['warn_on_ignored_urls']:
log_warning(f"ignoring URL {url} from {page.file.src_path}")
else:
url_status = self.get_url_status(url, page.file.src_path, all_element_ids, opt_files)
if self.bad_url(url_status) and self.is_error(self.config, url, url_status):
Expand Down
Loading