mkdocs-document-dates 3.8.7__tar.gz → 3.8.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 (43) hide show
  1. {mkdocs_document_dates-3.8.7/mkdocs_document_dates.egg-info → mkdocs_document_dates-3.8.9}/PKG-INFO +3 -3
  2. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/README.md +2 -2
  3. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/cache_manager.py +1 -1
  4. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/plugin.py +26 -7
  5. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/templates/recently_updated_detail.html +4 -4
  6. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/templates/recently_updated_grid.html +4 -4
  7. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/templates/recently_updated_group.html +5 -5
  8. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/utils.py +31 -5
  9. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9/mkdocs_document_dates.egg-info}/PKG-INFO +3 -3
  10. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/pyproject.toml +1 -1
  11. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/setup.py +1 -1
  12. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/LICENSE +0 -0
  13. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/MANIFEST.in +0 -0
  14. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/__init__.py +0 -0
  15. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/hooks/pre-commit +0 -0
  16. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/hooks_installer.py +0 -0
  17. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/.DS_Store +0 -0
  18. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/config/config.css +0 -0
  19. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/config/config.js +0 -0
  20. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/core.css +0 -0
  21. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/core.js +0 -0
  22. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/default.config.js +0 -0
  23. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/md5.min.js +0 -0
  24. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
  25. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
  26. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/core/utils.js +0 -0
  27. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/fonts/material-icons.css +0 -0
  28. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/fonts/materialicons.woff2 +0 -0
  29. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/templates/recently_updated_list.html +0 -0
  30. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
  31. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/light.css +0 -0
  32. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/material.css +0 -0
  33. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
  34. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/scale.css +0 -0
  35. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
  36. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
  37. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
  38. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  39. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  40. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  41. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  42. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  43. {mkdocs_document_dates-3.8.7 → mkdocs_document_dates-3.8.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.8.7
3
+ Version: 3.8.9
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
@@ -25,7 +25,7 @@ English | [简体中文](README_zh.md)
25
25
 
26
26
  A new generation MkDocs plugin for displaying exact **creation date, last updated date, authors, email** of documents
27
27
 
28
- ![render](render.gif)
28
+ ![render](docs/assets/document-dates.gif)
29
29
 
30
30
  ## Features
31
31
 
@@ -90,7 +90,7 @@ In addition to the above basic configuration, the plug-in also provides a wealth
90
90
 
91
91
  See the documentation for details: https://jaywhj.netlify.app/document-dates-en
92
92
 
93
- ![recently-updated](recently-updated-en.gif)
93
+ ![recently-updated](docs/assets/recently-updated-en.gif)
94
94
 
95
95
  ## Other Projects
96
96
 
@@ -6,7 +6,7 @@ English | [简体中文](README_zh.md)
6
6
 
7
7
  A new generation MkDocs plugin for displaying exact **creation date, last updated date, authors, email** of documents
8
8
 
9
- ![render](render.gif)
9
+ ![render](docs/assets/document-dates.gif)
10
10
 
11
11
  ## Features
12
12
 
@@ -71,7 +71,7 @@ In addition to the above basic configuration, the plug-in also provides a wealth
71
71
 
72
72
  See the documentation for details: https://jaywhj.netlify.app/document-dates-en
73
73
 
74
- ![recently-updated](recently-updated-en.gif)
74
+ ![recently-updated](docs/assets/recently-updated-en.gif)
75
75
 
76
76
  ## Other Projects
77
77
 
@@ -88,7 +88,7 @@ def _clean_git_env():
88
88
 
89
89
  return env
90
90
 
91
- def find_mkdocs_projects() -> dict[Path, Path]:
91
+ def find_mkdocs_projects():
92
92
  projects = {}
93
93
 
94
94
  try:
@@ -9,6 +9,7 @@ from mkdocs.config import config_options
9
9
  from mkdocs.structure.pages import Page
10
10
  from mkdocs.utils import get_relative_url
11
11
  from urllib.parse import urlparse
12
+ from babel.core import default_locale
12
13
  from babel.dates import format_datetime
13
14
  from .utils import compile_exclude_patterns, is_excluded, get_recently_updated_files, load_dates_and_authors, DEFAULT_WPM, DEFAULT_WPM_CJK
14
15
 
@@ -23,6 +24,8 @@ class Author:
23
24
  self.avatar = avatar
24
25
  self.url = url
25
26
  self.description = description
27
+ for k, v in kwargs.items():
28
+ setattr(self, k, v)
26
29
 
27
30
 
28
31
  class DocumentDatesPlugin(BasePlugin):
@@ -270,11 +273,15 @@ class DocumentDatesPlugin(BasePlugin):
270
273
  with open(file_path, 'r', encoding='utf-8') as f:
271
274
  data = yaml.safe_load(f)
272
275
  for key, info in (data or {}).get('authors', {}).items():
273
- self.authors_yml[key] = Author(**info)
276
+ author_obj = Author(**info)
277
+ self.authors_yml[key] = author_obj
278
+ if author_obj.name and author_obj.name not in self.authors_yml:
279
+ self.authors_yml[author_obj.name] = author_obj
280
+ if author_obj.email and author_obj.email not in self.authors_yml:
281
+ self.authors_yml[author_obj.email] = author_obj
274
282
  except Exception as e:
275
283
  logger.info(f"Error parsing .authors.yml: {e}")
276
284
 
277
-
278
285
  def _render_recently_updated_html(self, env, config, recently_updated_data, summary_lines):
279
286
  # 设置模板加载器
280
287
  template_path = Path(__file__).parent / 'static' / 'templates'
@@ -321,22 +328,31 @@ class DocumentDatesPlugin(BasePlugin):
321
328
  authors_list = self.data_cached.get(rel_path, {}).get('authors', None)
322
329
  if authors_list:
323
330
  authors = []
331
+ seen_names = set()
324
332
  for data in authors_list:
325
- full_author = self.authors_yml.get(data['name'])
333
+ full_author = self.authors_yml.get(data.get('name')) or self.authors_yml.get(data.get('email'))
326
334
  if full_author:
327
- authors.append(self._repair_author(full_author, page.url))
335
+ if getattr(full_author, 'ignore', False) or getattr(full_author, 'exclude', False) or getattr(full_author, 'hidden', False):
336
+ continue
337
+ repaired = self._repair_author(full_author, page.url)
338
+ if repaired.name not in seen_names:
339
+ seen_names.add(repaired.name)
340
+ authors.append(repaired)
328
341
  else:
329
- authors.append(Author(**data))
342
+ if data.get('name') not in seen_names:
343
+ seen_names.add(data.get('name'))
344
+ authors.append(Author(**data))
330
345
  return authors
331
346
 
332
347
  # 2. site_author 或 PC username
333
348
  name = config.get('site_author') or Path.home().name
334
349
  full_author = self.authors_yml.get(name)
335
350
  if full_author:
351
+ if getattr(full_author, 'ignore', False) or getattr(full_author, 'exclude', False) or getattr(full_author, 'hidden', False):
352
+ return []
336
353
  return [self._repair_author(full_author, page.url)]
337
354
  else:
338
355
  return [Author(name=name)]
339
-
340
356
  def _load_meta_author(self, meta, page_url):
341
357
  try:
342
358
  # 匹配 authors 数组
@@ -381,7 +397,9 @@ class DocumentDatesPlugin(BasePlugin):
381
397
 
382
398
 
383
399
  def _formatting_date(self, date: datetime):
384
- locale = self.config.get('locale', 'en')
400
+ # 空配置表示自动检测系统 locale;若运行环境未设置 locale,则回退到英语。
401
+ locale = (self.config.get('locale') or '').strip()
402
+ locale = locale or default_locale('LC_TIME') or 'en'
385
403
 
386
404
  # 兼容旧 strftime 配置,转换为 Babel/ICU 格式
387
405
  date_format = (
@@ -429,6 +447,7 @@ class DocumentDatesPlugin(BasePlugin):
429
447
  html_parts = []
430
448
  position_class = 'document-dates-top' if self.config['position'] == 'top' else 'document-dates-bottom'
431
449
  html_parts.append(f"<div class='document-dates-plugin-wrapper {position_class}'>")
450
+ # 前端 locale 留给浏览器语言回退逻辑;这里只传递用户显式配置。
432
451
  html_parts.append(f"<div class='document-dates-plugin' locale='{self.config['locale']}'>")
433
452
 
434
453
  def build_time_icon(time_obj: datetime, icon: str):
@@ -82,15 +82,15 @@
82
82
  <div>
83
83
  {%- for mtime, rel_path, title, url, cover, summary in recent_docs %}
84
84
  <div class="article-card">
85
- <a class="card-header" href="{{ url }}" target="_blank">
86
- <div class="card-title">{{ title }}</div>
85
+ <a class="card-header" href="{{ url | e }}" target="_blank">
86
+ <div class="card-title">{{ title | e }}</div>
87
87
  <time class="dd-timeago card-date" datetime="{{ mtime }}">{{ mtime[:10] }}</time>
88
88
  </a>
89
89
  <div class="card-body">
90
- <div class="card-summary">{{ summary }}</div>
90
+ <div class="card-summary">{{ summary | e }}</div>
91
91
  {%- if cover %}
92
92
  <div class="card-cover">
93
- <img src="{{ cover }}" alt="{{ title }}">
93
+ <img src="{{ cover | e }}" alt="{{ title | e }}">
94
94
  </div>
95
95
  {%- endif %}
96
96
  </div>
@@ -89,15 +89,15 @@
89
89
  <div class="article-grid">
90
90
  {%- for mtime, rel_path, title, url, cover, summary in recent_docs %}
91
91
  <div class="article-card">
92
- <a class="card-header" href="{{ url }}" target="_blank">
93
- <div class="card-title">{{ title }}</div>
92
+ <a class="card-header" href="{{ url | e }}" target="_blank">
93
+ <div class="card-title">{{ title | e }}</div>
94
94
  <time class="dd-timeago card-date" datetime="{{ mtime }}">{{ mtime[:10] }}</time>
95
95
  </a>
96
96
  <div class="card-body">
97
- <div class="card-summary">{{ summary }}</div>
97
+ <div class="card-summary">{{ summary | e }}</div>
98
98
  {%- if cover %}
99
99
  <div class="card-cover">
100
- <img src="{{ cover }}" alt="{{ title }}">
100
+ <img src="{{ cover | e }}" alt="{{ title | e }}">
101
101
  </div>
102
102
  {%- endif %}
103
103
  </div>
@@ -270,17 +270,17 @@
270
270
  {%- set readtime = doc.readtime | default(0) %}
271
271
  {%- set tags = doc.tags | default([]) %}
272
272
  <div class="article-card">
273
- <a class="card-header" href="{{ url }}" target="_blank">
274
- <div class="card-title">{{ title }}</div>
273
+ <a class="card-header" href="{{ url | e }}" target="_blank">
274
+ <div class="card-title">{{ title | e }}</div>
275
275
  <time class="dd-timeago card-date" datetime="{{ updated_dt }}">{{ updated }}</time>
276
276
  </a>
277
277
  <div class="card-body">
278
278
  {%- if cover %}
279
279
  <div class="card-cover">
280
- <img src="{{ cover }}" alt="{{ title }}">
280
+ <img src="{{ cover | e }}" alt="{{ title | e }}">
281
281
  </div>
282
282
  {%- endif %}
283
- <div class="card-summary">{{ summary }}</div>
283
+ <div class="card-summary">{{ summary | e }}</div>
284
284
  </div>
285
285
 
286
286
  {%- if tags or readtime > 0 %}
@@ -298,7 +298,7 @@
298
298
  {%- if tags %}
299
299
  <div class="md-tags">
300
300
  {%- for tag in tags %}
301
- <span class="md-tag md-tag-icon">{{- tag -}}</span>
301
+ <span class="md-tag md-tag-icon">{{- tag | e -}}</span>
302
302
  {%- endfor %}
303
303
  </div>
304
304
  {%- endif %}
@@ -110,12 +110,38 @@ COAUTHOR_RE = re.compile(
110
110
  r'^Co-authored-by:\s*(.+?) <([^<>]+)>$',
111
111
  re.MULTILINE | re.IGNORECASE
112
112
  )
113
- def parse_commit_authors(name, email, body):
113
+ def check_mailmap(name: str, email: str, git_root: Path = None, cache: dict = None):
114
+ key = (name, email)
115
+ if cache is not None and key in cache:
116
+ return cache[key]
117
+ if git_root:
118
+ try:
119
+ proc = subprocess.run(
120
+ ['git', 'check-mailmap', f'{name} <{email}>'],
121
+ cwd=git_root,
122
+ capture_output=True,
123
+ encoding='utf-8'
124
+ )
125
+ if proc.returncode == 0 and proc.stdout.strip():
126
+ m = re.match(r'^(.*?)\s*<([^<>]+)>$', proc.stdout.strip())
127
+ if m:
128
+ res = (m.group(1).strip(), m.group(2).strip())
129
+ if cache is not None:
130
+ cache[key] = res
131
+ return res
132
+ except Exception as e:
133
+ logger.debug(f"Error checking mailmap for {name} <{email}>: {e}")
134
+ if cache is not None:
135
+ cache[key] = key
136
+ return key
137
+
138
+ def parse_commit_authors(name, email, body, git_root: Path = None, mailmap_cache: dict = None):
139
+ # name/email come from `git log --use-mailmap`; mapping them again can diverge on chained entries
114
140
  authors = [(name, email)]
115
141
  seen = {(name, email)}
116
142
 
117
143
  for co_name, co_email in COAUTHOR_RE.findall(body):
118
- author = (co_name, co_email)
144
+ author = check_mailmap(co_name, co_email, git_root, mailmap_cache)
119
145
  if author in seen:
120
146
  continue
121
147
 
@@ -157,6 +183,7 @@ def load_git_metadata(docs_dir_path: Path):
157
183
  authors_dict = defaultdict(dict)
158
184
  first_commit = {}
159
185
  current_commit = None
186
+ mailmap_cache = {}
160
187
 
161
188
  records = process.stdout.split('\x00')
162
189
  for item in records:
@@ -167,7 +194,7 @@ def load_git_metadata(docs_dir_path: Path):
167
194
  parts = item.split('\x1f', 3)
168
195
  if len(parts) == 4:
169
196
  name, email, created, body = parts
170
- authors = parse_commit_authors(name, email, body)
197
+ authors = parse_commit_authors(name, email, body, git_root, mailmap_cache)
171
198
  current_commit = (authors, int(created))
172
199
  elif item.endswith('.md') and current_commit:
173
200
  authors, created = current_commit
@@ -178,7 +205,6 @@ def load_git_metadata(docs_dir_path: Path):
178
205
  authors_dict[item].setdefault(author, None)
179
206
 
180
207
  first_commit.setdefault(item, created)
181
-
182
208
  # 构建最终的缓存数据
183
209
  for file_path in first_commit:
184
210
  authors_list = [
@@ -434,7 +460,7 @@ BRACE_RE = re.compile(r"\{[^}]*\}")
434
460
  MD_SYNTAX_RE = re.compile(r"[`*_#]+")
435
461
 
436
462
 
437
- def analyze_markdown(md: str, readtime_wpm: int = DEFAULT_WPM, readtime_wpm_cjk: int = DEFAULT_WPM_CJK) -> tuple[int, str]:
463
+ def analyze_markdown(md: str, readtime_wpm: int = DEFAULT_WPM, readtime_wpm_cjk: int = DEFAULT_WPM_CJK):
438
464
  # ---------- for Readtime ----------
439
465
  words = 0
440
466
  cjk = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.8.7
3
+ Version: 3.8.9
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
@@ -25,7 +25,7 @@ English | [简体中文](README_zh.md)
25
25
 
26
26
  A new generation MkDocs plugin for displaying exact **creation date, last updated date, authors, email** of documents
27
27
 
28
- ![render](render.gif)
28
+ ![render](docs/assets/document-dates.gif)
29
29
 
30
30
  ## Features
31
31
 
@@ -90,7 +90,7 @@ In addition to the above basic configuration, the plug-in also provides a wealth
90
90
 
91
91
  See the documentation for details: https://jaywhj.netlify.app/document-dates-en
92
92
 
93
- ![recently-updated](recently-updated-en.gif)
93
+ ![recently-updated](docs/assets/recently-updated-en.gif)
94
94
 
95
95
  ## Other Projects
96
96
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "mkdocs-document-dates"
7
- version = "3.8.7"
7
+ version = "3.8.9"
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.7",
7
+ version="3.8.9",
8
8
  author="Aaron Wang",
9
9
  author_email="aaronwqt@gmail.com",
10
10
  license="MIT",