mkdocs-document-dates 3.8.0__tar.gz → 3.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {mkdocs_document_dates-3.8.0/mkdocs_document_dates.egg-info → mkdocs_document_dates-3.8.1}/PKG-INFO +3 -1
  2. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/README.md +2 -0
  3. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/cache_manager.py +39 -28
  4. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/plugin.py +9 -3
  5. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/utils.py +13 -9
  6. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1/mkdocs_document_dates.egg-info}/PKG-INFO +3 -1
  7. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/pyproject.toml +1 -1
  8. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/setup.py +1 -1
  9. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/LICENSE +0 -0
  10. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/MANIFEST.in +0 -0
  11. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/__init__.py +0 -0
  12. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/hooks/pre-commit +0 -0
  13. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/hooks_installer.py +0 -0
  14. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/.DS_Store +0 -0
  15. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/config/user.config.css +0 -0
  16. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/config/user.config.js +0 -0
  17. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/core.css +0 -0
  18. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/core.js +0 -0
  19. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/default.config.js +0 -0
  20. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/md5.min.js +0 -0
  21. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
  22. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
  23. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/core/utils.js +0 -0
  24. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/fonts/material-icons.css +0 -0
  25. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/fonts/materialicons.woff2 +0 -0
  26. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/templates/recently_updated_detail.html +0 -0
  27. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/templates/recently_updated_grid.html +0 -0
  28. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/templates/recently_updated_group.html +0 -0
  29. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/templates/recently_updated_list.html +0 -0
  30. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
  31. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/light.css +0 -0
  32. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/material.css +0 -0
  33. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
  34. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/scale.css +0 -0
  35. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
  36. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
  37. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
  38. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  39. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  40. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  41. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  42. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  43. {mkdocs_document_dates-3.8.0 → mkdocs_document_dates-3.8.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.8.0
3
+ Version: 3.8.1
4
4
  Summary: A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents
5
5
  Author-email: Aaron Wang <aaronwqt@gmail.com>
6
6
  License-Expression: MIT
@@ -44,6 +44,8 @@ A new generation MkDocs plugin for displaying exact **creation date, last update
44
44
  | git-revision-date-localized<br />git-authors | > 3 s | > 30 s | O(n) |
45
45
  | document-dates | < 0.1 s | < 0.15 s | O(1) |
46
46
 
47
+ > It's 20-500 times faster than `git-revision-date-localized` and `git-authors`
48
+
47
49
  ## Installation
48
50
 
49
51
  ```bash
@@ -26,6 +26,8 @@ A new generation MkDocs plugin for displaying exact **creation date, last update
26
26
  | git-revision-date-localized<br />git-authors | > 3 s | > 30 s | O(n) |
27
27
  | document-dates | < 0.1 s | < 0.15 s | O(1) |
28
28
 
29
+ > It's 20-500 times faster than `git-revision-date-localized` and `git-authors`
30
+
29
31
  ## Installation
30
32
 
31
33
  ```bash
@@ -10,13 +10,19 @@ from .utils import read_jsonl_cache, write_jsonl_cache, load_file_creation_date,
10
10
  logger = logging.getLogger("mkdocs.plugins.document_dates")
11
11
  _LOGGING_CONFIGURED = False
12
12
 
13
+ CONFIG_PRIORITY = {
14
+ "mkdocs.yml": 0,
15
+ "properdocs.yml": 1,
16
+ "mkdocs.yaml": 2,
17
+ "properdocs.yaml": 3,
18
+ }
13
19
 
14
20
  def _default_log_file() -> Path:
15
21
  try:
16
22
  git_root = Path(subprocess.check_output(
17
- ['git', 'rev-parse', '--show-toplevel'],
23
+ ["git", "rev-parse", "--show-toplevel"],
18
24
  env=_clean_git_env(),
19
- encoding='utf-8'
25
+ encoding="utf-8"
20
26
  ).strip())
21
27
  base_dir = git_root
22
28
  except Exception:
@@ -82,20 +88,29 @@ def _clean_git_env():
82
88
 
83
89
  return env
84
90
 
85
- def find_mkdocs_projects():
86
- projects = set()
91
+ def find_mkdocs_projects() -> dict[Path, Path]:
92
+ projects = {}
87
93
 
88
94
  try:
89
95
  git_root = Path(subprocess.check_output(
90
- ['git', 'rev-parse', '--show-toplevel'],
96
+ ["git", "rev-parse", "--show-toplevel"],
91
97
  env=_clean_git_env(),
92
- encoding='utf-8'
98
+ encoding="utf-8"
93
99
  ).strip())
94
100
 
95
- target_names = {'mkdocs.yml', 'properdocs.yml'}
96
- for config_file in git_root.rglob('*.yml'):
97
- if config_file.name.lower() in target_names:
98
- projects.add(config_file.parent)
101
+ for pattern in ("*.yml", "*.yaml"):
102
+ for config_file in git_root.rglob(pattern):
103
+ name = config_file.name.lower()
104
+ if name not in CONFIG_PRIORITY:
105
+ continue
106
+
107
+ project_dir = config_file.parent
108
+ existing = projects.get(project_dir)
109
+ if existing is None:
110
+ projects[project_dir] = config_file
111
+ continue
112
+ if CONFIG_PRIORITY[name] < CONFIG_PRIORITY[existing.name.lower()]:
113
+ projects[project_dir] = config_file
99
114
 
100
115
  if not projects:
101
116
  logger.warning("No MkDocs/ProperDocs projects found in the repository")
@@ -105,19 +120,19 @@ def find_mkdocs_projects():
105
120
  except Exception as e:
106
121
  logger.error(f"Unexpected error while searching for projects: {e}")
107
122
 
108
- return list(projects)
123
+ return projects
109
124
 
110
125
  def setup_gitattributes(docs_dir: Path):
111
126
  try:
112
- gitattributes_path = docs_dir / '.gitattributes'
127
+ gitattributes_path = docs_dir / ".gitattributes"
113
128
  union_merge_line = ".dates_cache.jsonl merge=union"
114
129
  # custom_merge_line = ".dates_cache.json merge=custom_json_merge"
115
- content = gitattributes_path.read_text(encoding='utf-8') if gitattributes_path.exists() else ""
130
+ content = gitattributes_path.read_text(encoding="utf-8") if gitattributes_path.exists() else ""
116
131
  if union_merge_line not in content:
117
- if content and not content.endswith('\n'):
118
- content += '\n'
132
+ if content and not content.endswith("\n"):
133
+ content += "\n"
119
134
  content += f"{union_merge_line}\n"
120
- gitattributes_path.write_text(content, encoding='utf-8')
135
+ gitattributes_path.write_text(content, encoding="utf-8")
121
136
  subprocess.run(["git", "add", str(gitattributes_path)], cwd=docs_dir, env=_clean_git_env(), check=True)
122
137
  logger.info(f"Updated .gitattributes file: {gitattributes_path}")
123
138
  return True
@@ -134,18 +149,14 @@ def update_cache():
134
149
  configure_file_logging(_default_log_file())
135
150
 
136
151
  global_updated = False
137
- for project_dir in find_mkdocs_projects():
152
+ for project_dir, mkdocs_yml in find_mkdocs_projects().items():
138
153
  try:
139
154
  project_updated = False
140
155
 
141
- docs_dir = project_dir / 'docs'
156
+ docs_dir = project_dir / "docs"
142
157
 
143
158
  # 从 mkdocs.yml 中读取 docs_dir 配置覆盖默认值
144
159
  try:
145
- mkdocs_yml = project_dir / "properdocs.yml"
146
- if not mkdocs_yml.exists():
147
- mkdocs_yml = project_dir / "mkdocs.yml"
148
-
149
160
  mkdocs_config = yaml.load(
150
161
  mkdocs_yml.read_text(encoding="utf-8"),
151
162
  Loader=yaml.BaseLoader,
@@ -156,16 +167,16 @@ def update_cache():
156
167
  except (IOError, OSError, yaml.YAMLError) as e:
157
168
  logger.warning(f"Failed to read docs_dir: {e}")
158
169
 
159
- if not docs_dir.exists():
170
+ if not docs_dir.is_dir():
160
171
  logger.info(f"Document directory does not exist: {docs_dir}")
161
172
  continue
162
173
 
163
174
  # 设置.gitattributes文件
164
- global_updated = setup_gitattributes(docs_dir)
175
+ global_updated |= setup_gitattributes(docs_dir)
165
176
 
166
177
  # 获取docs目录下已跟踪(tracked)的markdown文件
167
- cmd = ['git', '-c', 'core.quotepath=false', 'ls-files', '*.md']
168
- result = subprocess.run(cmd, cwd=docs_dir, env=_clean_git_env(), capture_output=True, encoding='utf-8')
178
+ cmd = ["git", "-c", "core.quotepath=false", "ls-files", "*.md"]
179
+ result = subprocess.run(cmd, cwd=docs_dir, env=_clean_git_env(), capture_output=True, encoding="utf-8")
169
180
  tracked_files = result.stdout.splitlines() if result.stdout else []
170
181
 
171
182
  if not tracked_files:
@@ -173,7 +184,7 @@ def update_cache():
173
184
  continue
174
185
 
175
186
  # 读取 JSONL 缓存
176
- jsonl_cache_file = docs_dir / '.dates_cache.jsonl'
187
+ jsonl_cache_file = docs_dir / ".dates_cache.jsonl"
177
188
  jsonl_dates_cache = read_jsonl_cache(jsonl_cache_file)
178
189
 
179
190
  # 根据 git已跟踪的文件来更新
@@ -204,7 +215,7 @@ def update_cache():
204
215
 
205
216
  # 如果有更新,写入 JSONL 缓存文件
206
217
  if project_updated or not jsonl_cache_file.exists():
207
- global_updated = write_jsonl_cache(jsonl_cache_file, jsonl_dates_cache, tracked_files)
218
+ global_updated |= write_jsonl_cache(jsonl_cache_file, jsonl_dates_cache, tracked_files)
208
219
  except subprocess.CalledProcessError as e:
209
220
  logger.error(f"Failed to execute git command: {e}")
210
221
  continue
@@ -53,8 +53,14 @@ class DocumentDatesPlugin(BasePlugin):
53
53
  docs_dir_path = Path(config.docs_dir)
54
54
 
55
55
  # 加载 author 配置
56
- authors_file = docs_dir_path / 'authors.yml'
57
- if not authors_file.exists():
56
+ authors_file = None
57
+ for name in ("authors.yml", "authors.yaml"):
58
+ candidate = docs_dir_path / name
59
+ if candidate.exists():
60
+ authors_file = candidate
61
+ break
62
+
63
+ if authors_file is None:
58
64
  try:
59
65
  blog_config = config.plugins.get(f"{config.theme.name}/blog").config
60
66
  authors_file_resolved = blog_config.authors_file.format(blog=blog_config.blog_dir)
@@ -199,7 +205,7 @@ class DocumentDatesPlugin(BasePlugin):
199
205
  limit = recently_updated_config.get('limit', 10)
200
206
 
201
207
  # 获取站点 URL 路径前缀
202
- site_url = config.get("site_url", "")
208
+ site_url = config.get("site_url") or ""
203
209
  base_path = urlparse(site_url).path.rstrip("/")
204
210
  prefix = f"{base_path}/" if base_path else "/"
205
211
 
@@ -255,12 +255,15 @@ def read_jsonl_cache(jsonl_file: Path):
255
255
  if entry and isinstance(entry, dict) and len(entry) == 1:
256
256
  file_path, file_info = next(iter(entry.items()))
257
257
  if isinstance(file_info, dict):
258
- if file_info.get('created'):
259
- file_info['created'] = int(datetime.fromisoformat(file_info['created']).timestamp())
260
- dates_cache[file_path] = file_info
261
- except (json.JSONDecodeError, StopIteration, ValueError) as e:
258
+ created = file_info.get('created')
259
+ if isinstance(created, str):
260
+ file_info['created'] = int(datetime.fromisoformat(created).timestamp())
261
+ elif isinstance(created, (int, float)):
262
+ file_info['created'] = int(created)
263
+ dates_cache[file_path] = file_info
264
+ except (json.JSONDecodeError, StopIteration, ValueError, TypeError,) as e:
262
265
  logger.warning(f"Skipping invalid JSONL line: {e}")
263
- except IOError as e:
266
+ except OSError as e:
264
267
  logger.warning(f"Error reading from '.dates_cache.jsonl': {str(e)}")
265
268
  return dates_cache
266
269
 
@@ -272,9 +275,10 @@ def write_jsonl_cache(jsonl_file: Path, dates_cache, tracked_files):
272
275
  for file_path in tracked_files:
273
276
  if file_path in dates_cache:
274
277
  file_info = dates_cache[file_path].copy()
275
- if file_info.get('created') is not None:
276
- file_info['created'] = datetime.fromtimestamp(file_info['created'], tz=timezone.utc).isoformat()
277
- entry = {file_path: dates_cache[file_path]}
278
+ created = file_info.get('created')
279
+ if created is not None:
280
+ file_info['created'] = datetime.fromtimestamp(created, tz=timezone.utc).isoformat()
281
+ entry = {file_path: file_info}
278
282
  f.write(json.dumps(entry, ensure_ascii=False) + '\n')
279
283
 
280
284
  # 替换原文件
@@ -284,7 +288,7 @@ def write_jsonl_cache(jsonl_file: Path, dates_cache, tracked_files):
284
288
  subprocess.run(["git", "add", str(jsonl_file)], check=True)
285
289
  logger.info(f"Successfully updated JSONL cache file: {jsonl_file}")
286
290
  return True
287
- except IOError as e:
291
+ except OSError as e:
288
292
  logger.warning(f"Failed to write JSONL cache file {jsonl_file}: {e}")
289
293
  except Exception as e:
290
294
  logger.warning(f"Failed to add JSONL cache file to git: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.8.0
3
+ Version: 3.8.1
4
4
  Summary: A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents
5
5
  Author-email: Aaron Wang <aaronwqt@gmail.com>
6
6
  License-Expression: MIT
@@ -44,6 +44,8 @@ A new generation MkDocs plugin for displaying exact **creation date, last update
44
44
  | git-revision-date-localized<br />git-authors | > 3 s | > 30 s | O(n) |
45
45
  | document-dates | < 0.1 s | < 0.15 s | O(1) |
46
46
 
47
+ > It's 20-500 times faster than `git-revision-date-localized` and `git-authors`
48
+
47
49
  ## Installation
48
50
 
49
51
  ```bash
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "mkdocs-document-dates"
7
- version = "3.8.0"
7
+ version = "3.8.1"
8
8
  description = "A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents"
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  requires-python = ">=3.7"
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
  def legacy_setup():
5
5
  setup(
6
6
  name="mkdocs-document-dates",
7
- version="3.8.0",
7
+ version="3.8.1",
8
8
  author="Aaron Wang",
9
9
  author_email="aaronwqt@gmail.com",
10
10
  license="MIT",