Skip to content

Commit 43e5fc1

Browse files
committed
Implement exclude pages functionality #43
1 parent b38c6f0 commit 43e5fc1

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ plugins:
120120
time_zone: Europe/Amsterdam
121121
locale: en
122122
fallback_to_build_date: false
123+
exclude:
124+
- index.md
123125
```
124126

125127
### `type`
@@ -150,6 +152,20 @@ Default is `None`. Specify a two letter [ISO639](https://en.wikipedia.org/wiki/L
150152

151153
Default is `false`. If set to `true` the plugin will use the time at `mkdocs build` instead of the file's last git revision date *when git is not available*. This means the revision date can be incorrect, but this can be acceptable if you want your project to also successfully build in environments with no access to GIT.
152154

155+
### `exclude`
156+
157+
Default is empty. Specify a list of page source paths (one per line) that should not have a revision date included. This can be useful for example to remove the revision date from the front page. The source page is relative to your `docs/` folder. To exclude `docs/subfolder/page.md` specify in your `mkdocs.yml` a line under `exclude:` with `- subfolder/page.md`. Example:
158+
159+
```yaml
160+
# mkdocs.yml
161+
plugins:
162+
- git-revision-date-localized:
163+
exclude:
164+
- index.md
165+
- subfolder/page.md
166+
- another_page.md
167+
```
168+
153169
## Contributing
154170

155171
Contributions are very welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) before putting in any work.

mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GitRevisionDateLocalizedPlugin(BasePlugin):
3535
("locale", config_options.Type(str, default=None)),
3636
("type", config_options.Type(str, default="date")),
3737
("timezone", config_options.Type(str, default="UTC")),
38-
("excluded_page_titles", config_options.Type(list, default=[])),
38+
("exclude", config_options.Type(list, default=[])),
3939
)
4040

4141
def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]:
@@ -140,10 +140,10 @@ def on_page_markdown(
140140
Returns:
141141
str: Markdown source text of page as string
142142
"""
143-
excluded_titles = self.config.get("excluded_page_titles", [])
144-
if page.title in excluded_titles:
145-
logging.debug("Excluding page " + page.url)
146-
# page is excluded
143+
# Exclude pages specified in config
144+
excluded_pages = self.config.get("exclude", [])
145+
if page.file.src_path in excluded_pages:
146+
logging.debug("Excluding page " + page.file.src_path)
147147
return markdown
148148

149149
revision_dates = self.util.get_revision_date_for_file(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
site_name: test gitrevisiondatelocalized_plugin
2+
use_directory_urls: true
3+
4+
theme:
5+
name: 'material'
6+
7+
plugins:
8+
- search
9+
- git-revision-date-localized:
10+
exclude:
11+
- subfolder/page_in_subfolder.md
12+
- first_page.md

tests/test_builds.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def test_material_theme_no_locale(tmp_path):
331331
)
332332

333333
# In mkdocs-material, a 'last update' should appear
334-
# in German because locale is set to 'de'
334+
# in english because default locale is set to 'en'
335335
index_file = testproject_path / "site/index.html"
336336
contents = index_file.read_text(encoding="utf8")
337337
assert re.search(r"Last update\:\s[<span class].+", contents)
@@ -358,6 +358,26 @@ def test_build_with_timezone(tmp_path):
358358
)
359359

360360

361+
def test_exclude_pages(tmp_path):
362+
"""
363+
When using mkdocs-material theme, test correct working
364+
"""
365+
# theme set to 'material' with 'locale' set to 'de'
366+
testproject_path = validate_mkdocs_file(
367+
tmp_path, "tests/fixtures/basic_project/mkdocs_exclude.yml"
368+
)
369+
370+
# Make sure revision date does not exist in excluded pages
371+
first_page = testproject_path / "site/first_page/index.html"
372+
contents = first_page.read_text(encoding="utf8")
373+
assert not re.search(r"Last update\:\s[<span class].+", contents)
374+
375+
sub_page = testproject_path / "site/subfolder/page_in_subfolder/index.html"
376+
contents = sub_page.read_text(encoding="utf8")
377+
assert not re.search(r"Last update\:\s[<span class].+", contents)
378+
379+
380+
361381
def test_git_in_docs_dir(tmp_path):
362382
"""
363383
In https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/pull/31

0 commit comments

Comments
 (0)