mkdocs-document-dates 3.4__tar.gz → 3.4.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 (41) hide show
  1. mkdocs_document_dates-3.4.1/PKG-INFO +102 -0
  2. mkdocs_document_dates-3.4.1/README.md +76 -0
  3. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/plugin.py +101 -52
  4. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/config/user.config.js +1 -1
  5. mkdocs_document_dates-3.4.1/mkdocs_document_dates/static/templates/recently_updated.html +42 -0
  6. mkdocs_document_dates-3.4.1/mkdocs_document_dates.egg-info/PKG-INFO +102 -0
  7. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/SOURCES.txt +2 -0
  8. mkdocs_document_dates-3.4.1/pyproject.toml +4 -0
  9. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/setup.py +2 -1
  10. mkdocs_document_dates-3.4/PKG-INFO +0 -240
  11. mkdocs_document_dates-3.4/README.md +0 -214
  12. mkdocs_document_dates-3.4/mkdocs_document_dates.egg-info/PKG-INFO +0 -240
  13. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/LICENSE +0 -0
  14. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/MANIFEST.in +0 -0
  15. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/__init__.py +0 -0
  16. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/cache_manager.py +0 -0
  17. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/hooks/pre-commit +0 -0
  18. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/hooks_installer.py +0 -0
  19. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/config/user.config.css +0 -0
  20. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/core.css +0 -0
  21. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/core.js +0 -0
  22. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/default.config.js +0 -0
  23. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
  24. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
  25. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/utils.js +0 -0
  26. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/fonts/material-icons.css +0 -0
  27. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/fonts/materialicons.woff2 +0 -0
  28. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
  29. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/light.css +0 -0
  30. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/material.css +0 -0
  31. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
  32. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/scale.css +0 -0
  33. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
  34. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
  35. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
  36. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/utils.py +0 -0
  37. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  38. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  39. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  40. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  41. {mkdocs_document_dates-3.4 → mkdocs_document_dates-3.4.1}/setup.cfg +0 -0
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: mkdocs-document-dates
3
+ Version: 3.4.1
4
+ Summary: A new generation MkDocs plugin for displaying exact creation time, last update time, authors, email of documents
5
+ Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
+ Author: Aaron Wang
7
+ Author-email: aaronwqt@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: mkdocs>=1.1.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # mkdocs-document-dates
28
+
29
+ English | [简体中文](README_zh.md)
30
+
31
+ <br />
32
+
33
+ A new generation MkDocs plugin for displaying exact **creation time, last update time, authors, email** of documents
34
+
35
+ ![render](render.gif)
36
+
37
+ ## Features
38
+
39
+ - [x] Always display **exact** meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc.)
40
+ - [x] Support for manually specifying time and author in `Front Matter`
41
+ - [x] Support for multiple time formats (date, datetime, timeago)
42
+ - [x] Support for multiple author modes (avatar, text, hidden)
43
+ - [x] Flexible display position (top or bottom)
44
+ - [x] Elegant styling (fully customizable)
45
+ - [x] Smart Tooltip Hover Tips
46
+ - [x] Supports display of recently updated documents in an overall list
47
+ - [x] Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
48
+ - [x] Cross-platform support (Windows, macOS, Linux)
49
+ - [x] **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
50
+
51
+ | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
52
+ | --------------------------- | :-----: | :------: | :----------: |
53
+ | git-revision-date-localized | > 3 s | > 30 s | O(n) |
54
+ | document-dates | < 0.1 s | < 0.15 s | O(1) |
55
+
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install mkdocs-document-dates
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ Just add the plugin to your `mkdocs.yml`:
66
+
67
+ ```yaml
68
+ plugins:
69
+ - document-dates
70
+ ```
71
+
72
+ Or, full configuration:
73
+
74
+ ```yaml
75
+ plugins:
76
+ - document-dates:
77
+ position: top # Display position: top(after title) bottom(end of document)
78
+ type: date # Date type: date datetime timeago, default: date
79
+ exclude: # List of excluded files
80
+ - temp.md # Exclude specific file
81
+ - drafts/* # Exclude all files in drafts folder, including subfolders
82
+ date_format: '%Y-%m-%d' # Date format strings, e.g., %Y-%m-%d, %b %d, %Y
83
+ time_format: '%H:%M:%S' # Time format strings (valid only if type=datetime)
84
+ show_author: true # Author display mode: true(avatar) text(text) false(hidden)
85
+ recently-updated: true # Whether to turn on recently updated data, default: false
86
+ ```
87
+
88
+ ## Customization Settings
89
+
90
+ In addition to the above basic configuration, the plug-in also provides a wealth of customization options to meet a variety of individual needs:
91
+
92
+ - [Specify Datetime](https://jaywhj.netlify.app/document-dates-en#Specify-Datetime): You can manually specify the creation time and last update time for each document
93
+ - [Specify Author](https://jaywhj.netlify.app/document-dates-en#Specify-Author): You can manually specify the author information for each document
94
+ - [Specify Avatar](https://jaywhj.netlify.app/document-dates-en#Specify-Avatar): You can manually specify the avatar for each author
95
+ - [Set Plugin Style](https://jaywhj.netlify.app/document-dates-en#Set-Plugin-Style): Such as icons, themes, colors, fonts, animations, dividing line, etc.
96
+ - [Add Localization Language](https://jaywhj.netlify.app/document-dates-en#Add-Localization-Language): More localization languages for `timeago` and `tooltip`
97
+ - [Use Template Variables](https://jaywhj.netlify.app/document-dates-en#Use-Template-Variables): Can be used to optimize `sitemap.xml` for site SEO, can be used to re-customize plug-ins, etc.
98
+ - [Add Recently Updated Module](https://jaywhj.netlify.app/document-dates-en#Add-Recently-Updated-Module): Enable list of recently updated documents
99
+ - [Other Tips](https://jaywhj.netlify.app/document-dates-en#Other-Tips): Introduction to technical principles, caching mechanisms
100
+ - [Development Stories](https://jaywhj.netlify.app/document-dates-en#Development-Stories): Describes the origin of the plug-in, the difficulties and solutions encountered in development, and the principles and directions of product design
101
+
102
+ See the documentation for details: https://jaywhj.netlify.app/document-dates-en
@@ -0,0 +1,76 @@
1
+ # mkdocs-document-dates
2
+
3
+ English | [简体中文](README_zh.md)
4
+
5
+ <br />
6
+
7
+ A new generation MkDocs plugin for displaying exact **creation time, last update time, authors, email** of documents
8
+
9
+ ![render](render.gif)
10
+
11
+ ## Features
12
+
13
+ - [x] Always display **exact** meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc.)
14
+ - [x] Support for manually specifying time and author in `Front Matter`
15
+ - [x] Support for multiple time formats (date, datetime, timeago)
16
+ - [x] Support for multiple author modes (avatar, text, hidden)
17
+ - [x] Flexible display position (top or bottom)
18
+ - [x] Elegant styling (fully customizable)
19
+ - [x] Smart Tooltip Hover Tips
20
+ - [x] Supports display of recently updated documents in an overall list
21
+ - [x] Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
22
+ - [x] Cross-platform support (Windows, macOS, Linux)
23
+ - [x] **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
24
+
25
+ | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
26
+ | --------------------------- | :-----: | :------: | :----------: |
27
+ | git-revision-date-localized | > 3 s | > 30 s | O(n) |
28
+ | document-dates | < 0.1 s | < 0.15 s | O(1) |
29
+
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install mkdocs-document-dates
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ Just add the plugin to your `mkdocs.yml`:
40
+
41
+ ```yaml
42
+ plugins:
43
+ - document-dates
44
+ ```
45
+
46
+ Or, full configuration:
47
+
48
+ ```yaml
49
+ plugins:
50
+ - document-dates:
51
+ position: top # Display position: top(after title) bottom(end of document)
52
+ type: date # Date type: date datetime timeago, default: date
53
+ exclude: # List of excluded files
54
+ - temp.md # Exclude specific file
55
+ - drafts/* # Exclude all files in drafts folder, including subfolders
56
+ date_format: '%Y-%m-%d' # Date format strings, e.g., %Y-%m-%d, %b %d, %Y
57
+ time_format: '%H:%M:%S' # Time format strings (valid only if type=datetime)
58
+ show_author: true # Author display mode: true(avatar) text(text) false(hidden)
59
+ recently-updated: true # Whether to turn on recently updated data, default: false
60
+ ```
61
+
62
+ ## Customization Settings
63
+
64
+ In addition to the above basic configuration, the plug-in also provides a wealth of customization options to meet a variety of individual needs:
65
+
66
+ - [Specify Datetime](https://jaywhj.netlify.app/document-dates-en#Specify-Datetime): You can manually specify the creation time and last update time for each document
67
+ - [Specify Author](https://jaywhj.netlify.app/document-dates-en#Specify-Author): You can manually specify the author information for each document
68
+ - [Specify Avatar](https://jaywhj.netlify.app/document-dates-en#Specify-Avatar): You can manually specify the avatar for each author
69
+ - [Set Plugin Style](https://jaywhj.netlify.app/document-dates-en#Set-Plugin-Style): Such as icons, themes, colors, fonts, animations, dividing line, etc.
70
+ - [Add Localization Language](https://jaywhj.netlify.app/document-dates-en#Add-Localization-Language): More localization languages for `timeago` and `tooltip`
71
+ - [Use Template Variables](https://jaywhj.netlify.app/document-dates-en#Use-Template-Variables): Can be used to optimize `sitemap.xml` for site SEO, can be used to re-customize plug-ins, etc.
72
+ - [Add Recently Updated Module](https://jaywhj.netlify.app/document-dates-en#Add-Recently-Updated-Module): Enable list of recently updated documents
73
+ - [Other Tips](https://jaywhj.netlify.app/document-dates-en#Other-Tips): Introduction to technical principles, caching mechanisms
74
+ - [Development Stories](https://jaywhj.netlify.app/document-dates-en#Development-Stories): Describes the origin of the plug-in, the difficulties and solutions encountered in development, and the principles and directions of product design
75
+
76
+ See the documentation for details: https://jaywhj.netlify.app/document-dates-en
@@ -2,6 +2,7 @@ import os
2
2
  import yaml
3
3
  import shutil
4
4
  import logging
5
+ from jinja2 import Environment, FileSystemLoader, select_autoescape
5
6
  from datetime import datetime
6
7
  from pathlib import Path
7
8
  from mkdocs.plugins import BasePlugin
@@ -42,7 +43,7 @@ class DocumentDatesPlugin(BasePlugin):
42
43
  ('exclude', config_options.Type(list, default=[])),
43
44
  ('created_field_names', config_options.Type(list, default=['created', 'date', 'creation'])),
44
45
  ('modified_field_names', config_options.Type(list, default=['modified', 'updated', 'last_modified', 'last_updated'])),
45
- ('show_author', config_options.Type(bool, default=True)),
46
+ ('show_author', config_options.Choice((True, False, 'text'), default=True)),
46
47
  ('recently-updated', config_options.Type((dict, bool), default={}))
47
48
  )
48
49
 
@@ -51,6 +52,8 @@ class DocumentDatesPlugin(BasePlugin):
51
52
  self.dates_cache = {}
52
53
  self.authors_yml = {}
53
54
  self.github_username = None
55
+ self.recent_docs_html = None
56
+ self.recent_enable = False
54
57
 
55
58
  def on_config(self, config):
56
59
  docs_dir_path = Path(config['docs_dir'])
@@ -70,7 +73,7 @@ class DocumentDatesPlugin(BasePlugin):
70
73
 
71
74
  # 加载 git 缓存
72
75
  self.dates_cache = load_git_cache(docs_dir_path)
73
- # 加载 jsonl 缓存覆盖
76
+ # 覆盖 jsonl 文件缓存
74
77
  jsonl_cache_file = docs_dir_path / '.dates_cache.jsonl'
75
78
  if jsonl_cache_file.exists():
76
79
  jsonl_cache = read_jsonl_cache(jsonl_cache_file)
@@ -78,35 +81,9 @@ class DocumentDatesPlugin(BasePlugin):
78
81
  if filename in self.dates_cache:
79
82
  self.dates_cache[filename].update(new_info)
80
83
 
81
- """
82
- Tippy.js, for Tooltip
83
- # core
84
- https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js
85
- https://unpkg.com/tippy.js@6/dist/tippy.umd.min.js
86
- https://unpkg.com/tippy.js@6/dist/tippy.css
87
- # animations
88
- https://unpkg.com/tippy.js@6/animations/scale.css
89
- # animations: Material filling effect
90
- https://unpkg.com/tippy.js@6/dist/backdrop.css
91
- https://unpkg.com/tippy.js@6/animations/shift-away.css
92
- # themes
93
- https://unpkg.com/tippy.js@6/themes/light.css
94
- https://unpkg.com/tippy.js@6/themes/material.css
95
- """
96
- # 复制静态资源到用户目录
84
+ # 复制配置文件到用户目录(如果不存在)
97
85
  dest_dir = docs_dir_path / 'assets' / 'document_dates'
98
86
  dest_dir.mkdir(parents=True, exist_ok=True)
99
-
100
- for dir_name in ['tippy', 'core', 'fonts']:
101
- source_dir = Path(__file__).parent / 'static' / dir_name
102
- target_dir = dest_dir / dir_name
103
- # shutil.copytree(source_dir, target_dir, dirs_exist_ok=True)
104
- target_dir.mkdir(parents=True, exist_ok=True)
105
- for item in source_dir.iterdir():
106
- if item.is_file():
107
- shutil.copy2(item, target_dir / item.name)
108
-
109
- # 复制配置文件模板到用户目录(如果不存在)
110
87
  config_files = ['user.config.css', 'user.config.js']
111
88
  for config_file in config_files:
112
89
  source_config = Path(__file__).parent / 'static' / 'config' / config_file
@@ -114,35 +91,49 @@ class DocumentDatesPlugin(BasePlugin):
114
91
  if not target_config.exists():
115
92
  shutil.copy2(source_config, target_config)
116
93
 
117
- # 加载离线 Google Fonts Icons: https://fonts.google.com/icons
94
+ # 添加离线 Google Fonts Icons: https://fonts.google.com/icons
118
95
  # material_icons_url = 'https://fonts.googleapis.com/icon?family=Material+Icons'
119
96
  material_icons_url = 'assets/document_dates/fonts/material-icons.css'
120
- if material_icons_url not in config['extra_css']:
121
- config['extra_css'].append(material_icons_url)
122
-
123
- # 加载 timeago.js
97
+ config['extra_css'].append(material_icons_url)
98
+
99
+ # 添加 timeago.js
124
100
  # https://cdn.jsdelivr.net/npm/timeago.js@4.0.2/dist/timeago.min.js
125
101
  # https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.2/timeago.full.min.js
126
102
  if self.config['type'] == 'timeago':
127
103
  config['extra_javascript'].insert(0, 'assets/document_dates/core/timeago.min.js')
128
104
 
129
- # 加载 Tippy CSS 文件
130
- tippy_css_dir = dest_dir / 'tippy'
105
+ """
106
+ Tippy.js, for Tooltip
107
+ # core
108
+ https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js
109
+ https://unpkg.com/tippy.js@6/dist/tippy.umd.min.js
110
+ https://unpkg.com/tippy.js@6/dist/tippy.css
111
+ # animations
112
+ https://unpkg.com/tippy.js@6/animations/scale.css
113
+ # animations: Material filling effect
114
+ https://unpkg.com/tippy.js@6/dist/backdrop.css
115
+ https://unpkg.com/tippy.js@6/animations/shift-away.css
116
+ # themes
117
+ https://unpkg.com/tippy.js@6/themes/light.css
118
+ https://unpkg.com/tippy.js@6/themes/material.css
119
+ """
120
+ # 添加 Tippy CSS 文件
121
+ tippy_css_dir = Path(__file__).parent / 'static' / 'tippy'
131
122
  for css_file in tippy_css_dir.glob('*.css'):
132
123
  config['extra_css'].append(f'assets/document_dates/tippy/{css_file.name}')
133
124
 
134
- # 加载自定义 CSS 文件
125
+ # 添加自定义 CSS 文件
135
126
  config['extra_css'].extend([
136
127
  'assets/document_dates/core/core.css',
137
128
  'assets/document_dates/user.config.css'
138
129
  ])
139
130
 
140
- # 按顺序加载 Tippy JS 文件
131
+ # 按顺序添加 Tippy JS 文件
141
132
  js_core_files = ['popper.min.js', 'tippy.umd.min.js']
142
133
  for js_file in js_core_files:
143
134
  config['extra_javascript'].append(f'assets/document_dates/tippy/{js_file}')
144
135
 
145
- # 加载自定义 JS 文件
136
+ # 添加自定义 JS 文件
146
137
  config['extra_javascript'].extend([
147
138
  'assets/document_dates/core/default.config.js',
148
139
  'assets/document_dates/user.config.js',
@@ -157,6 +148,7 @@ class DocumentDatesPlugin(BasePlugin):
157
148
  if not recently_updated_config:
158
149
  return nav
159
150
 
151
+ self.recent_enable = True
160
152
  # 兼容 true 配置
161
153
  if recently_updated_config is True:
162
154
  recently_updated_config = {}
@@ -164,6 +156,7 @@ class DocumentDatesPlugin(BasePlugin):
164
156
  # 获取配置
165
157
  exclude_list = recently_updated_config.get('exclude', [])
166
158
  limit = recently_updated_config.get('limit', 10)
159
+ template_path = recently_updated_config.get("template")
167
160
 
168
161
  # 获取 docs 目录下最近更新的文档
169
162
  recently_modified_files = get_recently_modified_files(files, exclude_list, limit)
@@ -173,8 +166,37 @@ class DocumentDatesPlugin(BasePlugin):
173
166
  config['extra'] = {}
174
167
  config['extra']['recently_updated_docs'] = recently_modified_files
175
168
 
169
+ # 渲染HTML
170
+ docs_dir = Path(config['docs_dir'])
171
+ self.recent_docs_html = self._render_recently_updated_html(docs_dir, template_path, recently_modified_files)
172
+
176
173
  return nav
177
174
 
175
+ def _render_recently_updated_html(self, docs_dir, template_path, recently_updated_data):
176
+ # 获取自定义模板路径
177
+ if template_path:
178
+ user_full_path = docs_dir / template_path
179
+
180
+ # 选择模板路径
181
+ if template_path and user_full_path.is_file():
182
+ template_dir = user_full_path.parent
183
+ template_file = user_full_path.name
184
+ else:
185
+ # 默认模板路径
186
+ default_template_path = Path(__file__).parent / 'static' / 'templates' / 'recently_updated.html'
187
+ template_dir = default_template_path.parent
188
+ template_file = default_template_path.name
189
+
190
+ # 加载模板
191
+ env = Environment(
192
+ loader=FileSystemLoader(str(template_dir)),
193
+ autoescape=select_autoescape(["html", "xml"])
194
+ )
195
+ template = env.get_template(template_file)
196
+
197
+ # 渲染模板
198
+ return template.render(recent_docs=recently_updated_data)
199
+
178
200
  def on_page_markdown(self, markdown, page: Page, config, files):
179
201
  # 获取相对路径,src_uri 总是以"/"分隔
180
202
  rel_path = getattr(page.file, 'src_uri', page.file.src_path)
@@ -198,6 +220,10 @@ class DocumentDatesPlugin(BasePlugin):
198
220
  page.meta['document_dates_modified'] = modified.isoformat()
199
221
  page.meta['document_dates_authors'] = authors
200
222
 
223
+ # 占位符替换
224
+ if self.recent_enable and '<!-- RECENTLY_UPDATED_DOCS -->' in markdown:
225
+ markdown = markdown.replace('<!-- RECENTLY_UPDATED_DOCS -->', self.recent_docs_html or '')
226
+
201
227
  # 检查是否需要排除
202
228
  if is_excluded(rel_path, self.config['exclude']):
203
229
  return markdown
@@ -208,6 +234,16 @@ class DocumentDatesPlugin(BasePlugin):
208
234
  # 将信息写入 markdown
209
235
  return self._insert_date_info(markdown, info_html)
210
236
 
237
+ def on_post_build(self, config):
238
+ site_dest_dir = Path(config['site_dir']) / 'assets' / 'document_dates'
239
+ for dir_name in ['tippy', 'core', 'fonts']:
240
+ source_dir = Path(__file__).parent / 'static' / dir_name
241
+ target_dir = site_dest_dir / dir_name
242
+ # shutil.copytree(source_dir, target_dir, dirs_exist_ok=True)
243
+ target_dir.mkdir(parents=True, exist_ok=True)
244
+ for item in source_dir.iterdir():
245
+ if item.is_file():
246
+ shutil.copy2(item, target_dir / item.name)
211
247
 
212
248
  def _extract_github_username(self, url):
213
249
  try:
@@ -348,9 +384,9 @@ class DocumentDatesPlugin(BasePlugin):
348
384
  if self.config['show_author'] and authors:
349
385
  def get_author_tooltip(author):
350
386
  if author.url:
351
- return f'&lt;a href="{author.url}" target="_blank"&gt;{author.name}&lt;/a&gt;'
387
+ return f'<a href="{author.url}" target="_blank">{author.name}</a>'
352
388
  elif author.email:
353
- return f'&lt;a href="mailto:{author.email}"&gt;{author.name}&lt;/a&gt;'
389
+ return f'<a href="mailto:{author.email}">{author.name}</a>'
354
390
  return author.name
355
391
 
356
392
  def get_avatar_img_url(author):
@@ -360,19 +396,32 @@ class DocumentDatesPlugin(BasePlugin):
360
396
  return f"https://avatars.githubusercontent.com/{self.github_username}"
361
397
  return ""
362
398
 
363
- icon = 'doc_author' if len(authors) == 1 else 'doc_authors'
364
- html_parts.append(f"<span class='material-icons' data-icon='{icon}'></span>")
365
- html_parts.append("<div class='avatar-group'>")
366
- for author in authors:
367
- tooltip = get_author_tooltip(author)
368
- img_url = get_avatar_img_url(author)
399
+ if self.config['show_author'] == 'text':
400
+ # 显示文本模式
401
+ tooltip_text = ',&nbsp;'.join(get_author_tooltip(author) for author in authors)
402
+ author_text = ', '.join(author.name for author in authors)
403
+ icon = 'doc_author' if len(authors) == 1 else 'doc_authors'
369
404
  html_parts.append(
370
- f"<div class='avatar-wrapper' data-name='{author.name}' data-tippy-content data-tippy-raw='{tooltip}'>"
371
- f"<span class='avatar-text'></span>"
372
- f"<img class='avatar' src='{img_url}' />"
373
- f"</div>"
405
+ f"<span data-tippy-content data-tippy-raw='{tooltip_text}'>"
406
+ f"<span class='material-icons' data-icon='{icon}'></span>"
407
+ f"{author_text}"
408
+ f"</span>"
374
409
  )
375
- html_parts.append("</div>")
410
+ else:
411
+ # 显示头像模式(默认)
412
+ icon = 'doc_author' if len(authors) == 1 else 'doc_authors'
413
+ html_parts.append(f"<span class='material-icons' data-icon='{icon}'></span>")
414
+ html_parts.append("<div class='avatar-group'>")
415
+ for author in authors:
416
+ tooltip = get_author_tooltip(author)
417
+ img_url = get_avatar_img_url(author)
418
+ html_parts.append(
419
+ f"<div class='avatar-wrapper' data-name='{author.name}' data-tippy-content data-tippy-raw='{tooltip}'>"
420
+ f"<span class='avatar-text'></span>"
421
+ f"<img class='avatar' src='{img_url}' />"
422
+ f"</div>"
423
+ )
424
+ html_parts.append("</div>")
376
425
 
377
426
  html_parts.append("</div></div>")
378
427
  return ''.join(html_parts)
@@ -33,7 +33,7 @@ TooltipConfig.setConfig({
33
33
 
34
34
  /*
35
35
  Part 2:
36
- Demonstrates how to register a local language when using 'timeago.js',
36
+ Demonstrates how to register a local language for 'timeago.js',
37
37
  then you can configure the localeStr you just registered anywhere!
38
38
  */
39
39
  /*
@@ -0,0 +1,42 @@
1
+ <style>
2
+ .recently-updated {
3
+ display: grid;
4
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
5
+ gap: 10px;
6
+ margin: 0;
7
+ padding: 16px;
8
+ border: 1px solid rgba(142, 142, 142, 0.15);
9
+ border-radius: 4px;
10
+ font-family: system-ui, sans-serif;
11
+ }
12
+ .recently-updated-item {
13
+ display: flex;
14
+ align-items: center;
15
+ }
16
+ .recently-updated-item span {
17
+ font-size: 0.85em;
18
+ color: rgba(142, 142, 142, 0.5);
19
+ margin-right: 8px;
20
+ flex-shrink: 0;
21
+ width: 90px;
22
+ }
23
+ .recently-updated-item a {
24
+ overflow: hidden;
25
+ text-overflow: ellipsis;
26
+ white-space: nowrap;
27
+ color: #0077cc;
28
+ text-decoration: none;
29
+ transition: color 0.2s ease;
30
+ }
31
+ .recently-updated-item a:hover {
32
+ text-decoration: underline;
33
+ }
34
+ </style>
35
+ <div class="recently-updated">
36
+ {%- for mtime, rel_path, title, url in recent_docs %}
37
+ <div class="recently-updated-item">
38
+ <span>{{ mtime[:10] }}</span>
39
+ <a href="{{ url }}" target="_blank">{{ title }}</a>
40
+ </div>
41
+ {%- endfor %}
42
+ </div>
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: mkdocs-document-dates
3
+ Version: 3.4.1
4
+ Summary: A new generation MkDocs plugin for displaying exact creation time, last update time, authors, email of documents
5
+ Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
+ Author: Aaron Wang
7
+ Author-email: aaronwqt@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: mkdocs>=1.1.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # mkdocs-document-dates
28
+
29
+ English | [简体中文](README_zh.md)
30
+
31
+ <br />
32
+
33
+ A new generation MkDocs plugin for displaying exact **creation time, last update time, authors, email** of documents
34
+
35
+ ![render](render.gif)
36
+
37
+ ## Features
38
+
39
+ - [x] Always display **exact** meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc.)
40
+ - [x] Support for manually specifying time and author in `Front Matter`
41
+ - [x] Support for multiple time formats (date, datetime, timeago)
42
+ - [x] Support for multiple author modes (avatar, text, hidden)
43
+ - [x] Flexible display position (top or bottom)
44
+ - [x] Elegant styling (fully customizable)
45
+ - [x] Smart Tooltip Hover Tips
46
+ - [x] Supports display of recently updated documents in an overall list
47
+ - [x] Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
48
+ - [x] Cross-platform support (Windows, macOS, Linux)
49
+ - [x] **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
50
+
51
+ | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
52
+ | --------------------------- | :-----: | :------: | :----------: |
53
+ | git-revision-date-localized | > 3 s | > 30 s | O(n) |
54
+ | document-dates | < 0.1 s | < 0.15 s | O(1) |
55
+
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install mkdocs-document-dates
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ Just add the plugin to your `mkdocs.yml`:
66
+
67
+ ```yaml
68
+ plugins:
69
+ - document-dates
70
+ ```
71
+
72
+ Or, full configuration:
73
+
74
+ ```yaml
75
+ plugins:
76
+ - document-dates:
77
+ position: top # Display position: top(after title) bottom(end of document)
78
+ type: date # Date type: date datetime timeago, default: date
79
+ exclude: # List of excluded files
80
+ - temp.md # Exclude specific file
81
+ - drafts/* # Exclude all files in drafts folder, including subfolders
82
+ date_format: '%Y-%m-%d' # Date format strings, e.g., %Y-%m-%d, %b %d, %Y
83
+ time_format: '%H:%M:%S' # Time format strings (valid only if type=datetime)
84
+ show_author: true # Author display mode: true(avatar) text(text) false(hidden)
85
+ recently-updated: true # Whether to turn on recently updated data, default: false
86
+ ```
87
+
88
+ ## Customization Settings
89
+
90
+ In addition to the above basic configuration, the plug-in also provides a wealth of customization options to meet a variety of individual needs:
91
+
92
+ - [Specify Datetime](https://jaywhj.netlify.app/document-dates-en#Specify-Datetime): You can manually specify the creation time and last update time for each document
93
+ - [Specify Author](https://jaywhj.netlify.app/document-dates-en#Specify-Author): You can manually specify the author information for each document
94
+ - [Specify Avatar](https://jaywhj.netlify.app/document-dates-en#Specify-Avatar): You can manually specify the avatar for each author
95
+ - [Set Plugin Style](https://jaywhj.netlify.app/document-dates-en#Set-Plugin-Style): Such as icons, themes, colors, fonts, animations, dividing line, etc.
96
+ - [Add Localization Language](https://jaywhj.netlify.app/document-dates-en#Add-Localization-Language): More localization languages for `timeago` and `tooltip`
97
+ - [Use Template Variables](https://jaywhj.netlify.app/document-dates-en#Use-Template-Variables): Can be used to optimize `sitemap.xml` for site SEO, can be used to re-customize plug-ins, etc.
98
+ - [Add Recently Updated Module](https://jaywhj.netlify.app/document-dates-en#Add-Recently-Updated-Module): Enable list of recently updated documents
99
+ - [Other Tips](https://jaywhj.netlify.app/document-dates-en#Other-Tips): Introduction to technical principles, caching mechanisms
100
+ - [Development Stories](https://jaywhj.netlify.app/document-dates-en#Development-Stories): Describes the origin of the plug-in, the difficulties and solutions encountered in development, and the principles and directions of product design
101
+
102
+ See the documentation for details: https://jaywhj.netlify.app/document-dates-en
@@ -1,6 +1,7 @@
1
1
  LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
+ pyproject.toml
4
5
  setup.py
5
6
  mkdocs_document_dates/__init__.py
6
7
  mkdocs_document_dates/cache_manager.py
@@ -24,6 +25,7 @@ mkdocs_document_dates/static/core/timeago.min.js
24
25
  mkdocs_document_dates/static/core/utils.js
25
26
  mkdocs_document_dates/static/fonts/material-icons.css
26
27
  mkdocs_document_dates/static/fonts/materialicons.woff2
28
+ mkdocs_document_dates/static/templates/recently_updated.html
27
29
  mkdocs_document_dates/static/tippy/backdrop.css
28
30
  mkdocs_document_dates/static/tippy/light.css
29
31
  mkdocs_document_dates/static/tippy/material.css
@@ -0,0 +1,4 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42"]
3
+ # 使用 legacy backend,继续执行 setup.py
4
+ build-backend = "setuptools.build_meta:__legacy__"
@@ -23,7 +23,7 @@ class CustomInstallCommand(install):
23
23
  install.run(self)
24
24
 
25
25
 
26
- VERSION = '3.4'
26
+ VERSION = '3.4.1'
27
27
 
28
28
  setup(
29
29
  name="mkdocs-document-dates",
@@ -58,6 +58,7 @@ setup(
58
58
  package_data={
59
59
  'mkdocs_document_dates': [
60
60
  'hooks/*',
61
+ 'static/templates/*',
61
62
  'static/fonts/*',
62
63
  'static/tippy/*',
63
64
  'static/core/*',