Skip to content

Commit 5955b20

Browse files
authored
Merge pull request #168 from timvink/monorepo_compat
Fix monorepo compatibility
2 parents f341e03 + 1da3a96 commit 5955b20

File tree

29 files changed

+265
-20
lines changed

29 files changed

+265
-20
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ dev-dependencies = [
119119
"mkdocs-gen-files>=0.5.0",
120120
"mkdocs-git-authors-plugin>=0.9.2",
121121
"mkdocs-material>=9.6.7",
122+
"mkdocs-monorepo-plugin>=1.1.0",
122123
"mkdocs-static-i18n>=1.3.0",
123124
"pytest>=8.3.5",
124125
"pytest-cov>=5.0.0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.4.0"
1+
__version__ = "1.4.1"

src/mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from mkdocs_git_revision_date_localized_plugin.util import Util
2424
from mkdocs_git_revision_date_localized_plugin.exclude import exclude
2525

26-
from typing import Any, Dict
26+
from typing import Any, Dict, Optional
2727
from collections import OrderedDict
2828

2929
from packaging.version import Version
@@ -145,12 +145,15 @@ def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]:
145145
return config
146146

147147

148-
def parallel_compute_commit_timestamps(self, files, docs_dir, is_first_commit=False):
148+
def parallel_compute_commit_timestamps(self, files, original_source: Optional[Dict] = None, is_first_commit=False):
149149
pool = multiprocessing.Pool(processes=min(10, multiprocessing.cpu_count()))
150150
results = []
151151
for file in files:
152152
if file.is_documentation_page():
153-
abs_src_path = os.path.join(docs_dir, file.src_uri)
153+
abs_src_path = file.abs_src_path
154+
# Support plugins like monorep that might have moved the files from the original source that is under git
155+
if original_source and abs_src_path in original_source:
156+
abs_src_path = original_source[abs_src_path]
154157
result = pool.apply_async(
155158
self.util.get_git_commit_timestamp, args=(abs_src_path, is_first_commit)
156159
)
@@ -170,14 +173,17 @@ def on_files(self, files: Files, config: MkDocsConfig):
170173
"""
171174
if not self.config.get("enabled") or not self.config.get("enable_parallel_processing"):
172175
return
173-
# Some plugins like TechDocs/monorepo copies docs_dir to a tmp dir and we need the real git path.
174-
real_docs_dir = os.path.join(
175-
os.path.dirname(config["config_file_path"]), "docs"
176-
)
176+
177+
# Support monorepo/techdocs, which copies the docs_dir to a temporary directory
178+
if "monorepo" in config.get('plugins', {}):
179+
original_source = config.get('plugins').get('monorepo').merger.files_source_dir
180+
else:
181+
original_source = None
182+
177183
if not self.last_revision_commits:
178-
self.parallel_compute_commit_timestamps(files=files, docs_dir=real_docs_dir, is_first_commit=False)
184+
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=False)
179185
if not self.created_commits:
180-
self.parallel_compute_commit_timestamps(files=files, docs_dir=real_docs_dir, is_first_commit=True)
186+
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=True)
181187

182188

183189
def on_page_markdown(self, markdown: str, page: Page, config: config_options.Config, files, **kwargs) -> str:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Docs for A
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site_name: Component A
2+
3+
nav:
4+
- Home: "README.md"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Docs for B
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site_name: Component B
2+
3+
nav:
4+
- Home: "README.md"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Docs for C
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site_name: Component C
2+
3+
nav:
4+
- Home: "README.md"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Component D
2+
3+
This will not be included

0 commit comments

Comments
 (0)