Skip to content

Commit

Permalink
Add support for ignoring every URL on a page (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-i-v-e authored Sep 13, 2024
1 parent 7b1285f commit 00f9e29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 00f9e29

Please sign in to comment.