mkdocs-document-dates 3.3.5__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.
- mkdocs_document_dates-3.4.1/PKG-INFO +102 -0
- mkdocs_document_dates-3.4.1/README.md +76 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/plugin.py +130 -70
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/config/user.config.js +1 -1
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/default.config.js +13 -1
- mkdocs_document_dates-3.4.1/mkdocs_document_dates/static/templates/recently_updated.html +42 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/utils.py +63 -11
- mkdocs_document_dates-3.4.1/mkdocs_document_dates.egg-info/PKG-INFO +102 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/SOURCES.txt +2 -0
- mkdocs_document_dates-3.4.1/pyproject.toml +4 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/setup.py +3 -7
- mkdocs_document_dates-3.3.5/PKG-INFO +0 -225
- mkdocs_document_dates-3.3.5/README.md +0 -199
- mkdocs_document_dates-3.3.5/mkdocs_document_dates.egg-info/PKG-INFO +0 -225
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/LICENSE +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/MANIFEST.in +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/__init__.py +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/cache_manager.py +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/hooks/pre-commit +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/hooks_installer.py +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/config/user.config.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/core.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/core.js +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/core/utils.js +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/fonts/material-icons.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/fonts/materialicons.woff2 +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/light.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/material.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/scale.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/requires.txt +0 -0
- {mkdocs_document_dates-3.3.5 → mkdocs_document_dates-3.4.1}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
- {mkdocs_document_dates-3.3.5 → 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
|
+

|
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
|
+

|
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,13 +2,14 @@ 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
|
8
9
|
from mkdocs.config import config_options
|
9
10
|
from mkdocs.structure.pages import Page
|
10
11
|
from urllib.parse import urlparse
|
11
|
-
from .utils import get_file_creation_time, load_git_cache, read_jsonl_cache
|
12
|
+
from .utils import get_file_creation_time, load_git_cache, read_jsonl_cache,is_excluded, get_recently_modified_files
|
12
13
|
|
13
14
|
logger = logging.getLogger("mkdocs.plugins.document_dates")
|
14
15
|
logger.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, CRITICAL
|
@@ -42,7 +43,8 @@ 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.
|
46
|
+
('show_author', config_options.Choice((True, False, 'text'), default=True)),
|
47
|
+
('recently-updated', config_options.Type((dict, bool), default={}))
|
46
48
|
)
|
47
49
|
|
48
50
|
def __init__(self):
|
@@ -50,6 +52,8 @@ class DocumentDatesPlugin(BasePlugin):
|
|
50
52
|
self.dates_cache = {}
|
51
53
|
self.authors_yml = {}
|
52
54
|
self.github_username = None
|
55
|
+
self.recent_docs_html = None
|
56
|
+
self.recent_enable = False
|
53
57
|
|
54
58
|
def on_config(self, config):
|
55
59
|
docs_dir_path = Path(config['docs_dir'])
|
@@ -69,7 +73,7 @@ class DocumentDatesPlugin(BasePlugin):
|
|
69
73
|
|
70
74
|
# 加载 git 缓存
|
71
75
|
self.dates_cache = load_git_cache(docs_dir_path)
|
72
|
-
#
|
76
|
+
# 覆盖 jsonl 文件缓存
|
73
77
|
jsonl_cache_file = docs_dir_path / '.dates_cache.jsonl'
|
74
78
|
if jsonl_cache_file.exists():
|
75
79
|
jsonl_cache = read_jsonl_cache(jsonl_cache_file)
|
@@ -77,35 +81,9 @@ class DocumentDatesPlugin(BasePlugin):
|
|
77
81
|
if filename in self.dates_cache:
|
78
82
|
self.dates_cache[filename].update(new_info)
|
79
83
|
|
80
|
-
|
81
|
-
Tippy.js, for Tooltip
|
82
|
-
# core
|
83
|
-
https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js
|
84
|
-
https://unpkg.com/tippy.js@6/dist/tippy.umd.min.js
|
85
|
-
https://unpkg.com/tippy.js@6/dist/tippy.css
|
86
|
-
# animations
|
87
|
-
https://unpkg.com/tippy.js@6/animations/scale.css
|
88
|
-
# animations: Material filling effect
|
89
|
-
https://unpkg.com/tippy.js@6/dist/backdrop.css
|
90
|
-
https://unpkg.com/tippy.js@6/animations/shift-away.css
|
91
|
-
# themes
|
92
|
-
https://unpkg.com/tippy.js@6/themes/light.css
|
93
|
-
https://unpkg.com/tippy.js@6/themes/material.css
|
94
|
-
"""
|
95
|
-
# 复制静态资源到用户目录
|
84
|
+
# 复制配置文件到用户目录(如果不存在)
|
96
85
|
dest_dir = docs_dir_path / 'assets' / 'document_dates'
|
97
86
|
dest_dir.mkdir(parents=True, exist_ok=True)
|
98
|
-
|
99
|
-
for dir_name in ['tippy', 'core', 'fonts']:
|
100
|
-
source_dir = Path(__file__).parent / 'static' / dir_name
|
101
|
-
target_dir = dest_dir / dir_name
|
102
|
-
# shutil.copytree(source_dir, target_dir, dirs_exist_ok=True)
|
103
|
-
target_dir.mkdir(parents=True, exist_ok=True)
|
104
|
-
for item in source_dir.iterdir():
|
105
|
-
if item.is_file():
|
106
|
-
shutil.copy2(item, target_dir / item.name)
|
107
|
-
|
108
|
-
# 复制配置文件模板到用户目录(如果不存在)
|
109
87
|
config_files = ['user.config.css', 'user.config.js']
|
110
88
|
for config_file in config_files:
|
111
89
|
source_config = Path(__file__).parent / 'static' / 'config' / config_file
|
@@ -113,35 +91,49 @@ class DocumentDatesPlugin(BasePlugin):
|
|
113
91
|
if not target_config.exists():
|
114
92
|
shutil.copy2(source_config, target_config)
|
115
93
|
|
116
|
-
#
|
94
|
+
# 添加离线 Google Fonts Icons: https://fonts.google.com/icons
|
117
95
|
# material_icons_url = 'https://fonts.googleapis.com/icon?family=Material+Icons'
|
118
96
|
material_icons_url = 'assets/document_dates/fonts/material-icons.css'
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# 加载 timeago.js
|
97
|
+
config['extra_css'].append(material_icons_url)
|
98
|
+
|
99
|
+
# 添加 timeago.js
|
123
100
|
# https://cdn.jsdelivr.net/npm/timeago.js@4.0.2/dist/timeago.min.js
|
124
101
|
# https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.2/timeago.full.min.js
|
125
102
|
if self.config['type'] == 'timeago':
|
126
103
|
config['extra_javascript'].insert(0, 'assets/document_dates/core/timeago.min.js')
|
127
104
|
|
128
|
-
|
129
|
-
|
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'
|
130
122
|
for css_file in tippy_css_dir.glob('*.css'):
|
131
123
|
config['extra_css'].append(f'assets/document_dates/tippy/{css_file.name}')
|
132
124
|
|
133
|
-
#
|
125
|
+
# 添加自定义 CSS 文件
|
134
126
|
config['extra_css'].extend([
|
135
127
|
'assets/document_dates/core/core.css',
|
136
128
|
'assets/document_dates/user.config.css'
|
137
129
|
])
|
138
130
|
|
139
|
-
#
|
131
|
+
# 按顺序添加 Tippy JS 文件
|
140
132
|
js_core_files = ['popper.min.js', 'tippy.umd.min.js']
|
141
133
|
for js_file in js_core_files:
|
142
134
|
config['extra_javascript'].append(f'assets/document_dates/tippy/{js_file}')
|
143
135
|
|
144
|
-
#
|
136
|
+
# 添加自定义 JS 文件
|
145
137
|
config['extra_javascript'].extend([
|
146
138
|
'assets/document_dates/core/default.config.js',
|
147
139
|
'assets/document_dates/user.config.js',
|
@@ -151,13 +143,65 @@ class DocumentDatesPlugin(BasePlugin):
|
|
151
143
|
|
152
144
|
return config
|
153
145
|
|
146
|
+
def on_nav(self, nav, config, files):
|
147
|
+
recently_updated_config = self.config.get('recently-updated')
|
148
|
+
if not recently_updated_config:
|
149
|
+
return nav
|
150
|
+
|
151
|
+
self.recent_enable = True
|
152
|
+
# 兼容 true 配置
|
153
|
+
if recently_updated_config is True:
|
154
|
+
recently_updated_config = {}
|
155
|
+
|
156
|
+
# 获取配置
|
157
|
+
exclude_list = recently_updated_config.get('exclude', [])
|
158
|
+
limit = recently_updated_config.get('limit', 10)
|
159
|
+
template_path = recently_updated_config.get("template")
|
160
|
+
|
161
|
+
# 获取 docs 目录下最近更新的文档
|
162
|
+
recently_modified_files = get_recently_modified_files(files, exclude_list, limit)
|
163
|
+
|
164
|
+
# 将数据注入到 config['extra'] 中供全局访问
|
165
|
+
if 'extra' not in config:
|
166
|
+
config['extra'] = {}
|
167
|
+
config['extra']['recently_updated_docs'] = recently_modified_files
|
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
|
+
|
173
|
+
return nav
|
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
|
+
|
154
200
|
def on_page_markdown(self, markdown, page: Page, config, files):
|
155
201
|
# 获取相对路径,src_uri 总是以"/"分隔
|
156
|
-
rel_path = getattr(page.file, 'src_uri',
|
157
|
-
if
|
158
|
-
rel_path =
|
159
|
-
if os.sep != '/':
|
160
|
-
rel_path = rel_path.replace(os.sep, '/')
|
202
|
+
rel_path = getattr(page.file, 'src_uri', page.file.src_path)
|
203
|
+
if os.sep != '/':
|
204
|
+
rel_path = rel_path.replace(os.sep, '/')
|
161
205
|
file_path = page.file.abs_src_path
|
162
206
|
|
163
207
|
# 获取时间信息
|
@@ -176,8 +220,12 @@ class DocumentDatesPlugin(BasePlugin):
|
|
176
220
|
page.meta['document_dates_modified'] = modified.isoformat()
|
177
221
|
page.meta['document_dates_authors'] = authors
|
178
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
|
+
|
179
227
|
# 检查是否需要排除
|
180
|
-
if self.
|
228
|
+
if is_excluded(rel_path, self.config['exclude']):
|
181
229
|
return markdown
|
182
230
|
|
183
231
|
# 生成日期和作者信息 HTML
|
@@ -186,6 +234,16 @@ class DocumentDatesPlugin(BasePlugin):
|
|
186
234
|
# 将信息写入 markdown
|
187
235
|
return self._insert_date_info(markdown, info_html)
|
188
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)
|
189
247
|
|
190
248
|
def _extract_github_username(self, url):
|
191
249
|
try:
|
@@ -217,17 +275,6 @@ class DocumentDatesPlugin(BasePlugin):
|
|
217
275
|
logger.info(f"Error parsing .authors.yml: {e}")
|
218
276
|
|
219
277
|
|
220
|
-
def _is_excluded(self, rel_path):
|
221
|
-
for pattern in self.config['exclude']:
|
222
|
-
if pattern.endswith('*'):
|
223
|
-
if rel_path.startswith(pattern.partition('*')[0]):
|
224
|
-
return True
|
225
|
-
else:
|
226
|
-
if rel_path == pattern:
|
227
|
-
return True
|
228
|
-
return False
|
229
|
-
|
230
|
-
|
231
278
|
def _find_meta_date(self, meta, field_names):
|
232
279
|
for field in field_names:
|
233
280
|
if field in meta:
|
@@ -337,9 +384,9 @@ class DocumentDatesPlugin(BasePlugin):
|
|
337
384
|
if self.config['show_author'] and authors:
|
338
385
|
def get_author_tooltip(author):
|
339
386
|
if author.url:
|
340
|
-
return f'
|
387
|
+
return f'<a href="{author.url}" target="_blank">{author.name}</a>'
|
341
388
|
elif author.email:
|
342
|
-
return f'
|
389
|
+
return f'<a href="mailto:{author.email}">{author.name}</a>'
|
343
390
|
return author.name
|
344
391
|
|
345
392
|
def get_avatar_img_url(author):
|
@@ -349,19 +396,32 @@ class DocumentDatesPlugin(BasePlugin):
|
|
349
396
|
return f"https://avatars.githubusercontent.com/{self.github_username}"
|
350
397
|
return ""
|
351
398
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
img_url = get_avatar_img_url(author)
|
399
|
+
if self.config['show_author'] == 'text':
|
400
|
+
# 显示文本模式
|
401
|
+
tooltip_text = ', '.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'
|
358
404
|
html_parts.append(
|
359
|
-
f"<
|
360
|
-
f"<span class='
|
361
|
-
f"
|
362
|
-
f"</
|
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>"
|
363
409
|
)
|
364
|
-
|
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>")
|
365
425
|
|
366
426
|
html_parts.append("</div></div>")
|
367
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
|
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
|
/*
|
@@ -126,6 +126,18 @@ window.TooltipLanguage = (function () {
|
|
126
126
|
author: "작성자",
|
127
127
|
authors: "작성자"
|
128
128
|
},
|
129
|
+
nl: {
|
130
|
+
created_time: "Gecreëerd",
|
131
|
+
modified_time: "Laatst geüpdatet",
|
132
|
+
author: "Auteur",
|
133
|
+
authors: "Auteurs"
|
134
|
+
},
|
135
|
+
pt: {
|
136
|
+
created_time: "Criado em",
|
137
|
+
modified_time: "Última atualização",
|
138
|
+
author: "Autor",
|
139
|
+
authors: "Autores"
|
140
|
+
},
|
129
141
|
ru: {
|
130
142
|
created_time: "Дата создания",
|
131
143
|
modified_time: "Дата изменения",
|
@@ -150,4 +162,4 @@ window.TooltipLanguage = (function () {
|
|
150
162
|
Object.entries(defaultLanguages).forEach(([locale, data]) => {
|
151
163
|
TooltipLanguage.register(locale, data);
|
152
164
|
});
|
153
|
-
})();
|
165
|
+
})();
|
@@ -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>
|