Skip to content

Commit 272dc8f

Browse files
ldeluigitimvink
authored andcommitted
Add fallback option. Fix #51
1 parent e7856bb commit 272dc8f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

mkdocs_git_authors_plugin/plugin.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from mkdocs_git_authors_plugin.git.command import GitCommandError
12
import re
23
from mkdocs.config import config_options
34
from mkdocs.plugins import BasePlugin
@@ -12,12 +13,17 @@ class GitAuthorsPlugin(BasePlugin):
1213
("show_contribution", config_options.Type(bool, default=False)),
1314
("show_line_count", config_options.Type(bool, default=False)),
1415
("count_empty_lines", config_options.Type(bool, default=True)),
16+
("fallback_to_empty_authors", config_options.Type(bool, default=False))
1517
# ('sort_authors_by_name', config_options.Type(bool, default=True)),
1618
# ('sort_reverse', config_options.Type(bool, default=False))
1719
)
1820

1921
def __init__(self):
20-
self._repo = Repo()
22+
try:
23+
self._repo = Repo()
24+
self._fallback = False
25+
except GitCommandError:
26+
self._fallback = True
2127

2228
def on_config(self, config, **kwargs):
2329
"""
@@ -38,6 +44,9 @@ def on_config(self, config, **kwargs):
3844
Returns:
3945
(updated) configuration object
4046
"""
47+
if self._fallback:
48+
return
49+
4150
self.repo().set_config(self.config)
4251

4352
raise_ci_warnings(path = self.repo()._root)
@@ -69,6 +78,8 @@ def on_files(self, files, config, **kwargs):
6978
Returns:
7079
global files collection
7180
"""
81+
if self._fallback:
82+
return
7283
for file in files:
7384
path = file.abs_src_path
7485
if path.endswith(".md"):
@@ -97,6 +108,9 @@ def on_page_content(self, html, page, config, files, **kwargs):
97108
Returns:
98109
str: HTML text of page as string
99110
"""
111+
if self._fallback:
112+
return html
113+
100114
list_pattern = re.compile(
101115
r"\{\{\s*git_site_authors\s*\}\}", flags=re.IGNORECASE
102116
)
@@ -126,6 +140,8 @@ def on_page_markdown(self, markdown, page, config, files, **kwargs):
126140
Returns:
127141
str: Markdown source text of page as string
128142
"""
143+
if self._fallback:
144+
return markdown
129145

130146
pattern_authors_summary = re.compile(
131147
r"\{\{\s*git_authors_summary\s*\}\}", flags=re.IGNORECASE
@@ -168,6 +184,8 @@ def on_page_context(self, context, page, config, nav, **kwargs):
168184
Returns:
169185
dict: template context variables
170186
"""
187+
if self._fallback:
188+
return context
171189

172190
path = page.file.abs_src_path
173191
page_obj = self.repo().page(path)

0 commit comments

Comments
 (0)