mkdocs-document-dates 3.4.7__tar.gz → 3.4.9__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 (38) hide show
  1. {mkdocs_document_dates-3.4.7/mkdocs_document_dates.egg-info → mkdocs_document_dates-3.4.9}/PKG-INFO +3 -3
  2. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/README.md +2 -2
  3. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/cache_manager.py +6 -14
  4. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/plugin.py +64 -51
  5. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/utils.py +0 -10
  6. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9/mkdocs_document_dates.egg-info}/PKG-INFO +3 -3
  7. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/setup.py +1 -1
  8. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/LICENSE +0 -0
  9. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/MANIFEST.in +0 -0
  10. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/__init__.py +0 -0
  11. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/hooks/pre-commit +0 -0
  12. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/hooks_installer.py +0 -0
  13. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/config/user.config.css +0 -0
  14. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/config/user.config.js +0 -0
  15. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/core/core.css +0 -0
  16. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/core/core.js +0 -0
  17. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/core/default.config.js +0 -0
  18. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
  19. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
  20. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/core/utils.js +0 -0
  21. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/fonts/material-icons.css +0 -0
  22. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/fonts/materialicons.woff2 +0 -0
  23. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/templates/recently_updated.html +0 -0
  24. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
  25. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/light.css +0 -0
  26. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/material.css +0 -0
  27. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
  28. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/scale.css +0 -0
  29. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
  30. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
  31. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
  32. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  33. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  34. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  35. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  36. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  37. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/pyproject.toml +0 -0
  38. {mkdocs_document_dates-3.4.7 → mkdocs_document_dates-3.4.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.4.7
3
+ Version: 3.4.9
4
4
  Summary: A new generation MkDocs plugin for displaying exact creation time, last update time, authors, email of documents
5
5
  Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
6
  Author: Aaron Wang
@@ -47,9 +47,9 @@ A new generation MkDocs plugin for displaying exact **creation time, last update
47
47
  - [x] Smart Tooltip Hover Tips
48
48
  - [x] Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
49
49
  - [x] Cross-platform support (Windows, macOS, Linux)
50
- - [x] **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
50
+ - [x] **Ultimate build efficiency**: O(1), no need to set the env var `!ENV` to distinguish runs
51
51
 
52
- | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
52
+ | Build Speed Comparison: | 100 md: | 1000 md: | Time Complexity: |
53
53
  | --------------------------- | :-----: | :------: | :----------: |
54
54
  | git-revision-date-localized | > 3 s | > 30 s | O(n) |
55
55
  | document-dates | < 0.1 s | < 0.15 s | O(1) |
@@ -21,9 +21,9 @@ A new generation MkDocs plugin for displaying exact **creation time, last update
21
21
  - [x] Smart Tooltip Hover Tips
22
22
  - [x] Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
23
23
  - [x] Cross-platform support (Windows, macOS, Linux)
24
- - [x] **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
24
+ - [x] **Ultimate build efficiency**: O(1), no need to set the env var `!ENV` to distinguish runs
25
25
 
26
- | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
26
+ | Build Speed Comparison: | 100 md: | 1000 md: | Time Complexity: |
27
27
  | --------------------------- | :-----: | :------: | :----------: |
28
28
  | git-revision-date-localized | > 3 s | > 30 s | O(n) |
29
29
  | document-dates | < 0.1 s | < 0.15 s | O(1) |
@@ -1,7 +1,7 @@
1
1
  import logging
2
2
  import subprocess
3
3
  from pathlib import Path
4
- from .utils import read_json_cache, read_jsonl_cache, write_jsonl_cache, get_file_creation_time, get_git_first_commit_time
4
+ from .utils import read_jsonl_cache, write_jsonl_cache, get_file_creation_time, get_git_first_commit_time
5
5
 
6
6
  logger = logging.getLogger("mkdocs.plugins.document_dates")
7
7
  logger.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, CRITICAL
@@ -72,29 +72,21 @@ def update_cache():
72
72
  logger.info(f"No tracked markdown files found in {docs_dir}")
73
73
  continue
74
74
 
75
- # 读取旧的JSON缓存文件(如果存在)
76
- json_cache_file = docs_dir / '.dates_cache.json'
77
- json_dates_cache = read_json_cache(json_cache_file)
78
-
79
- # 读取新的JSONL缓存文件(如果存在)
75
+ # 读取 JSONL 缓存
80
76
  jsonl_cache_file = docs_dir / '.dates_cache.jsonl'
81
77
  jsonl_dates_cache = read_jsonl_cache(jsonl_cache_file)
82
78
 
83
79
  # 根据 git已跟踪的文件来更新
84
80
  for rel_path in tracked_files:
85
81
  try:
86
- # 如果文件已在JSONL缓存中,跳过
82
+ # 如果文件已在 JSONL 缓存中,跳过
87
83
  if rel_path in jsonl_dates_cache:
88
84
  continue
89
85
 
90
86
  full_path = docs_dir / rel_path
91
- # 处理新文件或迁移旧JSON缓存
92
- if rel_path in json_dates_cache:
93
- jsonl_dates_cache[rel_path] = json_dates_cache[rel_path]
94
- project_updated = True
95
- elif full_path.exists():
87
+ if full_path.exists():
96
88
  created_time = get_file_creation_time(full_path).astimezone()
97
- if not jsonl_cache_file.exists() and not json_cache_file.exists():
89
+ if not jsonl_cache_file.exists():
98
90
  git_time = get_git_first_commit_time(full_path)
99
91
  if git_time:
100
92
  created_time = min(created_time, git_time)
@@ -110,7 +102,7 @@ def update_cache():
110
102
  if len(jsonl_dates_cache) > len(tracked_files):
111
103
  project_updated = True
112
104
 
113
- # 如果有更新,写入JSONL缓存文件
105
+ # 如果有更新,写入 JSONL 缓存文件
114
106
  if project_updated or not jsonl_cache_file.exists():
115
107
  global_updated = write_jsonl_cache(jsonl_cache_file, jsonl_dates_cache, tracked_files)
116
108
  except subprocess.CalledProcessError as e:
@@ -8,6 +8,7 @@ from pathlib import Path
8
8
  from mkdocs.plugins import BasePlugin
9
9
  from mkdocs.config import config_options
10
10
  from mkdocs.structure.pages import Page
11
+ from mkdocs.utils import get_relative_url
11
12
  from urllib.parse import urlparse
12
13
  from .utils import get_file_creation_time, load_git_cache, read_jsonl_cache,is_excluded, get_recently_updated_files
13
14
 
@@ -164,31 +165,6 @@ class DocumentDatesPlugin(BasePlugin):
164
165
 
165
166
  return nav
166
167
 
167
- def _render_recently_updated_html(self, docs_dir, template_path, recently_updated_data):
168
- # 获取自定义模板路径
169
- if template_path:
170
- user_full_path = docs_dir / template_path
171
-
172
- # 选择模板路径
173
- if template_path and user_full_path.is_file():
174
- template_dir = user_full_path.parent
175
- template_file = user_full_path.name
176
- else:
177
- # 默认模板路径
178
- default_template_path = Path(__file__).parent / 'static' / 'templates' / 'recently_updated.html'
179
- template_dir = default_template_path.parent
180
- template_file = default_template_path.name
181
-
182
- # 加载模板
183
- env = Environment(
184
- loader=FileSystemLoader(str(template_dir)),
185
- autoescape=select_autoescape(["html", "xml"])
186
- )
187
- template = env.get_template(template_file)
188
-
189
- # 渲染模板
190
- return template.render(recent_docs=recently_updated_data)
191
-
192
168
  def on_page_markdown(self, markdown, page: Page, config, files):
193
169
  # 获取相对路径,src_uri 总是以"/"分隔
194
170
  rel_path = getattr(page.file, 'src_uri', page.file.src_path)
@@ -206,6 +182,10 @@ class DocumentDatesPlugin(BasePlugin):
206
182
 
207
183
  # 获取作者信息
208
184
  authors = self._get_author_info(rel_path, page, config)
185
+ if authors and len(authors) == 1:
186
+ a = authors[0]
187
+ if not a.avatar and self.github_username:
188
+ a.avatar = f"https://avatars.githubusercontent.com/{self.github_username}"
209
189
 
210
190
  # 在排除前暴露 meta 信息给前端使用
211
191
  page.meta['document_dates_created'] = created.isoformat()
@@ -237,6 +217,7 @@ class DocumentDatesPlugin(BasePlugin):
237
217
  if item.is_file():
238
218
  shutil.copy2(item, target_dir / item.name)
239
219
 
220
+
240
221
  def _extract_github_username(self, url):
241
222
  try:
242
223
  parsed = urlparse(url)
@@ -260,6 +241,32 @@ class DocumentDatesPlugin(BasePlugin):
260
241
  logger.info(f"Error parsing .authors.yml: {e}")
261
242
 
262
243
 
244
+ def _render_recently_updated_html(self, docs_dir, template_path, recently_updated_data):
245
+ # 获取自定义模板路径
246
+ if template_path:
247
+ user_full_path = docs_dir / template_path
248
+
249
+ # 选择模板路径
250
+ if template_path and user_full_path.is_file():
251
+ template_dir = user_full_path.parent
252
+ template_file = user_full_path.name
253
+ else:
254
+ # 默认模板路径
255
+ default_template_path = Path(__file__).parent / 'static' / 'templates' / 'recently_updated.html'
256
+ template_dir = default_template_path.parent
257
+ template_file = default_template_path.name
258
+
259
+ # 加载模板
260
+ env = Environment(
261
+ loader=FileSystemLoader(str(template_dir)),
262
+ autoescape=select_autoescape(["html", "xml"])
263
+ )
264
+ template = env.get_template(template_file)
265
+
266
+ # 渲染模板
267
+ return template.render(recent_docs=recently_updated_data)
268
+
269
+
263
270
  def _find_meta_date(self, meta, field_names):
264
271
  for field in field_names:
265
272
  if field in meta:
@@ -290,42 +297,44 @@ class DocumentDatesPlugin(BasePlugin):
290
297
  def _get_author_info(self, rel_path, page, config):
291
298
  if not self.config['show_author']:
292
299
  return None
300
+
293
301
  # 1. meta author
294
- authors = self._process_meta_author(page.meta)
302
+ authors = self._process_meta_author(page.meta, page.url)
295
303
  if authors:
296
304
  return authors
305
+
297
306
  # 2. git author
298
307
  if rel_path in self.dates_cache:
299
308
  authors_list = self.dates_cache[rel_path].get('authors')
300
309
  if authors_list:
301
310
  authors = []
302
- for dict in authors_list:
303
- full_author = self.authors_yml.get(dict['name'])
311
+ for data in authors_list:
312
+ full_author = self.authors_yml.get(data['name'])
304
313
  if full_author:
305
- authors.append(full_author)
306
- # authors.append(Author(**{**vars(full_author), **dict}))
314
+ authors.append(self._get_repaired_author(full_author, page.url))
307
315
  else:
308
- authors.append(Author(**dict))
316
+ authors.append(Author(**data))
309
317
  return authors
318
+
310
319
  # 3. site_author 或 PC username
311
320
  name = config.get('site_author') or Path.home().name
312
321
  full_author = self.authors_yml.get(name)
313
322
  if full_author:
314
- return [full_author]
315
- # return [Author(**{**vars(full_author), "name": name})]
323
+ return [self._get_repaired_author(full_author, page.url)]
316
324
  else:
317
325
  return [Author(name=name)]
318
326
 
319
- def _process_meta_author(self, meta):
327
+ def _process_meta_author(self, meta, page_url):
320
328
  try:
321
329
  # 匹配 authors 数组
322
330
  author_objs = []
323
331
  authors_data = meta.get('authors')
324
332
  for key in authors_data or []:
325
- author = self.authors_yml.get(key)
326
- if not author:
327
- author = Author(name=str(key))
328
- author_objs.append(author)
333
+ full_author = self.authors_yml.get(key)
334
+ if full_author:
335
+ author_objs.append(self._get_repaired_author(full_author, page_url))
336
+ else:
337
+ author_objs.append(Author(name=str(key)))
329
338
  if author_objs:
330
339
  return author_objs
331
340
 
@@ -337,14 +346,26 @@ class DocumentDatesPlugin(BasePlugin):
337
346
  name = email.partition('@')[0]
338
347
  full_author = self.authors_yml.get(name)
339
348
  if full_author:
340
- return [full_author]
341
- # return [Author(**{**vars(full_author), "name": name, "email": email or full_author.email})]
349
+ return [self._get_repaired_author(full_author, page_url)]
342
350
  else:
343
351
  return [Author(name=name, email=email)]
344
352
  except Exception as e:
345
353
  logger.warning(f"Error processing author meta: {e}")
346
354
  return None
347
355
 
356
+ def _get_repaired_author(self, author: Author, page_url: str) -> Author:
357
+ try:
358
+ if not author.avatar:
359
+ return author
360
+ parsed = urlparse(author.avatar)
361
+ if parsed.scheme or author.avatar.startswith('//'):
362
+ return author
363
+ # 处理本地路径(相对路径 & 绝对路径)
364
+ avatar = get_relative_url(author.avatar.lstrip('/'), page_url or '')
365
+ return Author(**{**vars(author), 'avatar': avatar})
366
+ except Exception:
367
+ return author
368
+
348
369
 
349
370
  def _get_formatted_date(self, date: datetime):
350
371
  if self.config['type'] == 'timeago':
@@ -382,13 +403,6 @@ class DocumentDatesPlugin(BasePlugin):
382
403
  return f'<a href="mailto:{author.email}">{author.name}</a>'
383
404
  return author.name
384
405
 
385
- def get_avatar_img_url(author):
386
- if author.avatar:
387
- return author.avatar
388
- elif self.github_username and len(authors) == 1:
389
- return f"https://avatars.githubusercontent.com/{self.github_username}"
390
- return ""
391
-
392
406
  if self.config['show_author'] == 'text':
393
407
  # 显示文本模式
394
408
  tooltip_text = ',&nbsp;'.join(get_author_tooltip(author) for author in authors)
@@ -407,11 +421,10 @@ class DocumentDatesPlugin(BasePlugin):
407
421
  html_parts.append("<div class='avatar-group'>")
408
422
  for author in authors:
409
423
  tooltip = get_author_tooltip(author)
410
- img_url = get_avatar_img_url(author)
411
424
  html_parts.append(
412
425
  f"<div class='avatar-wrapper' data-name='{author.name}' data-tippy-content data-tippy-raw='{tooltip}'>"
413
426
  f"<span class='avatar-text'></span>"
414
- f"<img class='avatar' src='{img_url}' onerror=\"this.style.display='none'\" />"
427
+ f"<img class='avatar' src='{author.avatar}' onerror=\"this.style.display='none'\" />"
415
428
  f"</div>"
416
429
  )
417
430
  html_parts.append("</div>")
@@ -426,14 +439,14 @@ class DocumentDatesPlugin(BasePlugin):
426
439
 
427
440
  def _insert_date_info(self, markdown: str, date_info: str):
428
441
  if self.config['position'] == 'top':
429
- first_line, insert_pos = self.find_markdown_body_start(markdown)
442
+ first_line, insert_pos = self._find_markdown_body_start(markdown)
430
443
  if first_line.startswith(('# ', '<h1')):
431
444
  return markdown[:insert_pos] + '\n' + date_info + '\n' + markdown[insert_pos:]
432
445
  else:
433
446
  return f"{date_info}\n{markdown}"
434
447
  return f"{markdown}\n\n{date_info}"
435
448
 
436
- def find_markdown_body_start(self, text: str):
449
+ def _find_markdown_body_start(self, text: str):
437
450
  pos = 0
438
451
  length = len(text)
439
452
  in_comment = False
@@ -171,16 +171,6 @@ def get_recently_updated_files(docs_dir_path: Path, files: Files, exclude_list:
171
171
 
172
172
  return doc_mtime_map, recently_updated_results
173
173
 
174
- def read_json_cache(cache_file: Path):
175
- dates_cache = {}
176
- if cache_file.exists():
177
- try:
178
- with open(cache_file, 'r', encoding='utf-8') as f:
179
- dates_cache = json.load(f)
180
- except (IOError, json.JSONDecodeError) as e:
181
- logger.warning(f"Error reading from '.dates_cache.json': {str(e)}")
182
- return dates_cache
183
-
184
174
  def read_jsonl_cache(jsonl_file: Path):
185
175
  dates_cache = {}
186
176
  if jsonl_file.exists():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.4.7
3
+ Version: 3.4.9
4
4
  Summary: A new generation MkDocs plugin for displaying exact creation time, last update time, authors, email of documents
5
5
  Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
6
  Author: Aaron Wang
@@ -47,9 +47,9 @@ A new generation MkDocs plugin for displaying exact **creation time, last update
47
47
  - [x] Smart Tooltip Hover Tips
48
48
  - [x] Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
49
49
  - [x] Cross-platform support (Windows, macOS, Linux)
50
- - [x] **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
50
+ - [x] **Ultimate build efficiency**: O(1), no need to set the env var `!ENV` to distinguish runs
51
51
 
52
- | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
52
+ | Build Speed Comparison: | 100 md: | 1000 md: | Time Complexity: |
53
53
  | --------------------------- | :-----: | :------: | :----------: |
54
54
  | git-revision-date-localized | > 3 s | > 30 s | O(n) |
55
55
  | document-dates | < 0.1 s | < 0.15 s | O(1) |
@@ -23,7 +23,7 @@ class CustomInstallCommand(install):
23
23
  install.run(self)
24
24
 
25
25
 
26
- VERSION = '3.4.7'
26
+ VERSION = '3.4.9'
27
27
 
28
28
  setup(
29
29
  name="mkdocs-document-dates",