Skip to content

Commit f2033b0

Browse files
twsltimvink
authored andcommitted
Add check for generated files
1 parent 6734d25 commit f2033b0

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

mkdocs_git_authors_plugin/plugin.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def on_files(
9393
So in any on_page_XXX event the contributions of an author
9494
to the current page *and* the repository as a whole are available.
9595
96+
Note:
97+
Since MkDocs 1.6 a file may alternatively be stored in memory - `content_string`/`content_bytes`.
98+
`src_dir` *should* be populated for real files and should be `None` for generated files.
99+
100+
See:
101+
https://www.mkdocs.org/dev-guide/api/#mkdocs.structure.files.File
102+
96103
Args:
97104
files: global files collection
98105
config: global configuration object
@@ -111,9 +118,18 @@ def on_files(
111118
if exclude(file.src_path, excluded_pages):
112119
continue
113120

114-
path = file.abs_src_path
115-
if path.endswith(".md"):
116-
_ = self.repo().page(path)
121+
if file.src_dir is None:
122+
logger.debug(
123+
f"[git-authors-plugin] Unable to find path for file {file.src_path}. "
124+
"Generated, in-memory files won't have a git history."
125+
)
126+
elif path := file.abs_src_path:
127+
if path.endswith(".md"):
128+
_ = self.repo().page(path)
129+
else:
130+
logger.warning(
131+
"[git-authors-plugin] Unexpected behaviour. Unable to find path for {file.src_path}."
132+
)
117133

118134
def on_page_content(
119135
self, html: str, *, page: Page, config: MkDocsConfig, files: Files, **kwargs

0 commit comments

Comments
 (0)