Skip to content

Commit 60b1a7c

Browse files
authored
Merge pull request #31 from Fir121/master
2 parents bc6ec96 + 0afd746 commit 60b1a7c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ More information about plugins in the [MkDocs documentation][mkdocs-plugins].
5151
- `enterprise_hostname` - For GitHub enterprise: the enterprise hostname.
5252
- `docs_path` - the path to the documentation folder. Defaults to `docs`.
5353
- `cache_dir` - The path which holds the authors cache file to speed up documentation builds. Defaults to `.cache/plugin/git-committers/`. The cache file is named `page-authors.json.json`.
54+
- `exclude` - Specify a list of page source paths (one per line) that should not have author(s) or last commit date included (excluded from processing by this plugin). Default is empty. [Example Usage](https://timvink.github.io/mkdocs-git-authors-plugin/options.html#exclude).
5455

5556
## Usage
5657

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Module to assist exclude certain files being processed by plugin.
3+
Inspired by https://github.com/apenwarr/mkdocs-exclude
4+
"""
5+
import os
6+
import fnmatch
7+
from typing import List
8+
9+
10+
def exclude(src_path: str, globs: List[str]) -> bool:
11+
"""
12+
Determine if a src_path should be excluded.
13+
Supports globs (e.g. folder/* or *.md).
14+
Credits: code adapted from
15+
https://github.com/timvink/mkdocs-git-authors-plugin/blob/master/mkdocs_git_authors_plugin/exclude.py
16+
Args:
17+
src_path (src): Path of file
18+
globs (list): list of globs
19+
Returns:
20+
(bool): whether src_path should be excluded
21+
"""
22+
assert isinstance(src_path, str)
23+
assert isinstance(globs, list)
24+
25+
for g in globs:
26+
if fnmatch.fnmatchcase(src_path, g):
27+
return True
28+
29+
# Windows reports filenames as eg. a\\b\\c instead of a/b/c.
30+
# To make the same globs/regexes match filenames on Windows and
31+
# other OSes, let's try matching against converted filenames.
32+
# On the other hand, Unix actually allows filenames to contain
33+
# literal \\ characters (although it is rare), so we won't
34+
# always convert them. We only convert if os.sep reports
35+
# something unusual. Conversely, some future mkdocs might
36+
# report Windows filenames using / separators regardless of
37+
# os.sep, so we *always* test with / above.
38+
if os.sep != "/":
39+
src_path_fix = src_path.replace(os.sep, "/")
40+
if fnmatch.fnmatchcase(src_path_fix, g):
41+
return True
42+
43+
return False

mkdocs_git_committers_plugin_2/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import re
1818
from bs4 import BeautifulSoup as bs
1919

20+
from mkdocs_git_committers_plugin_2.exclude import exclude
21+
2022
LOG = logging.getLogger("mkdocs.plugins." + __name__)
2123

2224
class GitCommittersPlugin(BasePlugin):
@@ -28,6 +30,7 @@ class GitCommittersPlugin(BasePlugin):
2830
('docs_path', config_options.Type(str, default='docs/')),
2931
('enabled', config_options.Type(bool, default=True)),
3032
('cache_dir', config_options.Type(str, default='.cache/plugin/git-committers')),
33+
("exclude", config_options.Type(list, default=[])),
3134
)
3235

3336
def __init__(self):
@@ -36,6 +39,7 @@ def __init__(self):
3639
self.enabled = True
3740
self.authors = dict()
3841
self.cache_page_authors = dict()
42+
self.exclude = list()
3943
self.cache_date = ''
4044

4145
def on_config(self, config):
@@ -55,9 +59,13 @@ def on_config(self, config):
5559
self.githuburl = "https://github.com/"
5660
self.localrepo = Repo(".")
5761
self.branch = self.config['branch']
62+
self.excluded_pages = self.config['exclude']
5863
return config
5964

6065
def list_contributors(self, path):
66+
if exclude(path.lstrip(self.config['docs_path']), self.excluded_pages):
67+
return None, None
68+
6169
last_commit_date = ""
6270
path = path.replace("\\", "/")
6371
for c in Commit.iter_items(self.localrepo, self.localrepo.head, path):

0 commit comments

Comments
 (0)