Skip to content

Commit 4759c7a

Browse files
committed
Fixed error when using git-revision-date-localized-plugin with blog
1 parent 85f0d74 commit 4759c7a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

material/plugins/blog/plugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,23 @@ def _slugify_category(self, name: str):
770770
# either inside the temporary directory or the docs directory
771771
def _path_to_file(self, path: str, config: MkDocsConfig, *, temp = True):
772772
assert path.endswith(".md")
773-
return File(
773+
file = File(
774774
path,
775775
config.docs_dir if not temp else self.temp_dir,
776776
config.site_dir,
777777
config.use_directory_urls
778778
)
779779

780+
# Hack: mark file as generated, so other plugins don't think it's part
781+
# of the file system. This is more or less a new quasi-standard that
782+
# still needs to be adopted by MkDocs, and was introduced by the
783+
# git-revision-date-localized-plugin - see https://bit.ly/3ZUmdBx
784+
if temp:
785+
file.generated_by = "material/blog"
786+
787+
# Return file
788+
return file
789+
780790
# Write the content to the file located at the given path
781791
def _save_to_file(self, path: str, content: str):
782792
os.makedirs(os.path.dirname(path), exist_ok = True)

src/plugins/blog/plugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,23 @@ def _slugify_category(self, name: str):
770770
# either inside the temporary directory or the docs directory
771771
def _path_to_file(self, path: str, config: MkDocsConfig, *, temp = True):
772772
assert path.endswith(".md")
773-
return File(
773+
file = File(
774774
path,
775775
config.docs_dir if not temp else self.temp_dir,
776776
config.site_dir,
777777
config.use_directory_urls
778778
)
779779

780+
# Hack: mark file as generated, so other plugins don't think it's part
781+
# of the file system. This is more or less a new quasi-standard that
782+
# still needs to be adopted by MkDocs, and was introduced by the
783+
# git-revision-date-localized-plugin - see https://bit.ly/3ZUmdBx
784+
if temp:
785+
file.generated_by = "material/blog"
786+
787+
# Return file
788+
return file
789+
780790
# Write the content to the file located at the given path
781791
def _save_to_file(self, path: str, content: str):
782792
os.makedirs(os.path.dirname(path), exist_ok = True)

0 commit comments

Comments
 (0)