mkdocs-document-dates 3.3__tar.gz → 3.3.2__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 (47) hide show
  1. {mkdocs_document_dates-3.3/mkdocs_document_dates.egg-info → mkdocs_document_dates-3.3.2}/PKG-INFO +31 -31
  2. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/README.md +30 -30
  3. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/cache_manager.py +5 -1
  4. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/plugin.py +33 -81
  5. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/config/user.config.css +0 -7
  6. mkdocs_document_dates-3.3.2/mkdocs_document_dates/static/config/user.config.js +96 -0
  7. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/core/core.css +0 -2
  8. mkdocs_document_dates-3.3.2/mkdocs_document_dates/static/core/core.js +199 -0
  9. mkdocs_document_dates-3.3.2/mkdocs_document_dates/static/core/default.config.js +153 -0
  10. mkdocs_document_dates-3.3.2/mkdocs_document_dates/static/core/utils.js +55 -0
  11. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/utils.py +12 -0
  12. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2/mkdocs_document_dates.egg-info}/PKG-INFO +31 -31
  13. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates.egg-info/SOURCES.txt +2 -11
  14. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/setup.py +1 -1
  15. mkdocs_document_dates-3.3/mkdocs_document_dates/static/config/user.config.js +0 -93
  16. mkdocs_document_dates-3.3/mkdocs_document_dates/static/core/core.js +0 -210
  17. mkdocs_document_dates-3.3/mkdocs_document_dates/static/core/timeago-load.js +0 -18
  18. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/ar.json +0 -6
  19. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/de.json +0 -6
  20. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/en.json +0 -6
  21. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/es.json +0 -6
  22. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/fr.json +0 -6
  23. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/ja.json +0 -6
  24. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/ko.json +0 -6
  25. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/ru.json +0 -6
  26. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/zh.json +0 -6
  27. mkdocs_document_dates-3.3/mkdocs_document_dates/static/languages/zh_TW.json +0 -6
  28. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/LICENSE +0 -0
  29. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/MANIFEST.in +0 -0
  30. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/__init__.py +0 -0
  31. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/hooks/pre-commit +0 -0
  32. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/hooks_installer.py +0 -0
  33. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
  34. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
  35. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
  36. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/light.css +0 -0
  37. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/material.css +0 -0
  38. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
  39. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/scale.css +0 -0
  40. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
  41. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
  42. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
  43. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  44. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  45. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  46. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  47. {mkdocs_document_dates-3.3 → mkdocs_document_dates-3.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-document-dates
3
- Version: 3.3
3
+ Version: 3.3.2
4
4
  Summary: A new generation MkDocs plugin for displaying exact meta-info, such as creation time, last update time, authors, email, etc
5
5
  Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
6
  Author: Aaron Wang
@@ -30,20 +30,21 @@ English | [简体中文](README_zh.md)
30
30
 
31
31
 
32
32
 
33
- A new generation MkDocs plugin for displaying exact meta-info of documents, such as **creation time, last update time, authors, email**, etc
33
+ A new generation MkDocs plugin for displaying exact **creation time, last update time, authors, email** of documents
34
34
 
35
35
  ## Features
36
36
 
37
- - Always display exact meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc)
37
+ - Always display **exact** meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc)
38
38
  - Support for manually specifying time and author in `Front Matter`
39
39
  - Support for multiple time formats (date, datetime, timeago)
40
40
  - Flexible display position (top or bottom)
41
41
  - Elegant styling (fully customizable)
42
42
  - Supports Tooltip Hover Tips
43
- - Intelligent dynamic positioning, always floating optimally in view
44
- - Supports automatic theme switching following Material's light/dark color scheme
45
- - Multi-language support, cross-platform support (Windows, macOS, Linux)
46
- - **Ultimate build efficiency**: O(1), typically less than 0.2 seconds
43
+ - Intelligent dynamic positioning, always floating optimally in view
44
+ - Supports automatic theme switching following Material's light/dark color scheme
45
+ - Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
46
+ - Cross-platform support (Windows, macOS, Linux)
47
+ - **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
47
48
 
48
49
  | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
49
50
  | --------------------------- | :-----: | :------: | :----------: |
@@ -80,10 +81,8 @@ plugins:
80
81
  exclude: # List of excluded files
81
82
  - temp.md # Exclude specific file
82
83
  - drafts/* # Exclude all files in drafts folder, including subfolders
83
- locale: en # Localization: en zh zh_TW es fr de ar ja ko ru, default: en
84
84
  date_format: '%Y-%m-%d' # Date format strings, e.g., %Y-%m-%d, %b %d, %Y, etc
85
85
  time_format: '%H:%M:%S' # Time format strings (valid only if type=datetime)
86
- show_author: true # Show author or not, default: true
87
86
  ```
88
87
 
89
88
  ## Specify time manually
@@ -129,7 +128,7 @@ By default, the plugin will **automatically** loads the author avatar, without m
129
128
  3. Custom avatar: can be customized by customizing the author's `avatar` field in Front Matter
130
129
  ```markdown
131
130
  ---
132
- # Way 1: Configure a full author
131
+ # Way 1: Configure a full author (fields optional)
133
132
  author:
134
133
  name: jay
135
134
  email: jay@qq.com
@@ -140,35 +139,37 @@ By default, the plugin will **automatically** loads the author avatar, without m
140
139
  # Way 2: Configure multiple authors
141
140
  authors:
142
141
  - jaywhj
143
- - squidfunk
142
+ - dawang
144
143
  - sunny
145
144
 
146
145
  ---
147
146
  ```
148
- - If you want to configure complete information for multiple authors, you can create a separate configuration file `.authors.yml` in the `docs/` or `docs/blog/` directory, see the [.authors.yml](https://github.com/jaywhj/mkdocs-document-dates/blob/main/templates/.authors.yml) for its format
149
- - If the URL avatar fails to load, it falls back to the character avatar
147
+ - If you want to configure complete information for multiple authors, you can create a separate configuration file `authors.yml` in the `docs/` directory, see the [authors.yml](https://github.com/jaywhj/mkdocs-document-dates/blob/main/templates/authors.yml) for its format
148
+ - If the URL avatar fails to load, it automatically falls back to the character avatar
150
149
 
151
150
  ## Customization
152
151
 
153
- The plugin supports deep customization, such as **icon style, theme color, font, animation, dividing line**, etc. Everything is customizable (Find the file below and turn on the uncomment switch):
152
+ The plugin supports full customization, such as **icon style, theme color, font, animation, dividing line** etc, and the entrance has been preset, you just need to find the file below and uncomment it:
154
153
 
155
154
  | Category: | Location: |
156
155
  | :----------------------: | ---------------------------------------- |
157
156
  | **Style & Theme** | `docs/assets/document_dates/user.config.css` |
158
157
  | **Properties & Functions** | `docs/assets/document_dates/user.config.js` |
159
- | **Localized languages** | `docs/assets/document_dates/languages/` <br />refer to the template file `en.json` for any additions or modifications |
160
158
 
161
- **Tip**: when `type: timeago` is set, timeago.js is enabled to render dynamic time, `timeago.min.js` only contains English and Chinese by default, if you need to load other languages, you can configure it as below (choose one):
159
+ ![customization](customization.gif)
162
160
 
163
- - In `user.config.js`, refer to [the demo commented out](https://github.com/jaywhj/mkdocs-document-dates/blob/main/mkdocs_document_dates/static/config/user.config.js) at the bottom, translate it into your local language
164
- - In `mkdocs.yml`, configure the full version of `timeago.full.min.js` to load all languages at once
165
- ```yaml
166
- extra_javascript:
167
- - assets/document_dates/core/timeago.full.min.js
168
- - assets/document_dates/core/timeago-load.js
169
- ```
161
+ ## Localization
170
162
 
171
- ![customization](customization.gif)
163
+ - **tooltip**: the plugin has 10 built-in languages: `en zh zh_TW es fr de ar ja ko ru`, **no need for manual configuration**, intelligent recognition, automatic switching
164
+ - If the language is missing or the built-in language is inaccurate, you can refer to [Part 3](https://github.com/jaywhj/mkdocs-document-dates/blob/main/mkdocs_document_dates/static/config/user.config.js) in `user.config.js` to register and add it yourself, or submit an issue
165
+ - The original configuration option `locale` is retained, but manual configuration is no longer recommended
166
+ - **timeago**: when `type: timeago` is set, timeago.js is enabled to render dynamic time, `timeago.min.js` only contains English and Chinese by default, if need to load other languages, you can configure it as below (choose one):
167
+ - In `user.config.js`, refer to [Part 2](https://github.com/jaywhj/mkdocs-document-dates/blob/main/mkdocs_document_dates/static/config/user.config.js), register and add it yourself
168
+ - In `mkdocs.yml`, configure the full version of `timeago.full.min.js` to reload all languages at once
169
+ ```yaml
170
+ extra_javascript:
171
+ - assets/document_dates/core/timeago.full.min.js
172
+ ```
172
173
 
173
174
  ## Template Variables
174
175
 
@@ -177,8 +178,6 @@ You can access the meta-info of a document in a template using the following var
177
178
  - page.meta.document_dates_created
178
179
  - page.meta.document_dates_modified
179
180
  - page.meta.document_dates_authors
180
- - page.meta.document_dates_locale
181
- - page.meta.document_dates_translation
182
181
 
183
182
  Usage examples:
184
183
 
@@ -206,7 +205,7 @@ A dispensable, insignificant little plug-in, friends who have time can take a lo
206
205
  - Method 2: Cache the original time in advance, and then read the cache subsequently (The time is exact and no dependency on any environment). The cache can be in Front Matter of the source document or in a separate file, I chose the latter. Storing in Front Matter makes sense and is easier, but this will modify the source content of the document, although it doesn't have any impact on the body, but I still want to ensure the originality of the data!
207
206
  - **Difficulty**:
208
207
  1. When to read and store original time? This is just a plugin for mkdocs, with very limited access and permissions, mkdocs provides only build and serve, so in case a user commits directly without executing build or serve (e.g., when using a CI/CD build system), then you won't be able to retrieve the time information of the file, not to mention caching it!
209
- - Let's take a straight shot: the Git Hooks mechanism was found, prompted by the AI, which can trigger a custom script when a specific git action occurs, such as every time commit is performed
208
+ - Straight to the bottom line: Git Hooks can be used to trigger custom scripts when specific git actions occur, such as every time a commit occurs
210
209
  2. How to install Git Hooks automatically? When and how are they triggered? Installing packages from PyPI via pip doesn't have a standard post-install hook mechanism
211
210
  - Workaround: After analyzing the flow of pip installing packages from PyPI, I found that when compiling and installing through the source package (sdist), setuptools will be called to handle it, so we can find a way to implant the installation script in the process of setuptools, i.e., we can add a custom script in setup.py
212
211
  3. How to design a cross-platform hook? To execute a python script, we need to explicitly specify the python interpreter, and the user's python environment varies depending on the operating system, the way python is installed, and the configuration, so how can we ensure that it works properly in all environments?
@@ -216,10 +215,11 @@ A dispensable, insignificant little plug-in, friends who have time can take a lo
216
215
  5. How to reduce build time when there are a lot of documents ( >1000 )? Getting git information about a document is usually a file I/O operation, and if there are a lot of files, the efficiency of the operation will plummet. 1,000 documents can be expected to take more than 30 seconds, which is intolerable to the user
217
216
  - Solution: Reduce the number of I/Os + Use caching + Replace less efficient system functions
218
217
  - **Improve**:
219
- - Since it's a newly developed plugin, it will be designed in the direction of **excellent products**, and the pursuit of the ultimate **ease of use, simplicity and personalization**
220
- - **Ease of use**: don't let users do things manually if you can, e.g., auto-install Git Hooks, auto-cache, auto-commit, provide customized templates, etc
218
+ - Since it's a newly developed plugin, it will be designed in the direction of **excellent products**, and the pursuit of the ultimate **ease of use, simplicity, compatibility, personalization, intelligence**
219
+ - **Ease of use**: there are no complex configurations, only 2-3 commonly used configuration options, in addition, a template is provided for personalized configurations
221
220
  - **Simplicity**: no unnecessary configuration, no Git dependencies, no CI/CD configuration dependencies, no other package dependencies
222
- - **Personalization**: almost everything can be customized, whether it's icons, styles, themes, or features, it's all fully customizable
223
- - In addition, it has good compatibility and extensibility, and works well in WIN7, mobile devices, old Safari, etc
221
+ - **Compatibility**: works well on older operating systems and browsers, such as WIN7, MacOS 10.11, iOS 12, Chrome 63.0.3239
222
+ - **Personalization**: fully customizable and full control over the rendering logic, the plugin is only responsible for providing the data
223
+ - **Intelligence**: intelligently parse document time, author, avatar, intelligent recognition of user language and automatic adaptation, in addition, there are auto-install Git Hooks, auto-cache, auto-commit
224
224
  - **The Last Secret**:
225
225
  - Programming is a hobby, and I'm a marketer of 8 years (Feel free to leave a comment)
@@ -4,20 +4,21 @@ English | [简体中文](README_zh.md)
4
4
 
5
5
 
6
6
 
7
- A new generation MkDocs plugin for displaying exact meta-info of documents, such as **creation time, last update time, authors, email**, etc
7
+ A new generation MkDocs plugin for displaying exact **creation time, last update time, authors, email** of documents
8
8
 
9
9
  ## Features
10
10
 
11
- - Always display exact meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc)
11
+ - Always display **exact** meta-info of the document for any environment (no-Git, Git, all CI/CD build systems, etc)
12
12
  - Support for manually specifying time and author in `Front Matter`
13
13
  - Support for multiple time formats (date, datetime, timeago)
14
14
  - Flexible display position (top or bottom)
15
15
  - Elegant styling (fully customizable)
16
16
  - Supports Tooltip Hover Tips
17
- - Intelligent dynamic positioning, always floating optimally in view
18
- - Supports automatic theme switching following Material's light/dark color scheme
19
- - Multi-language support, cross-platform support (Windows, macOS, Linux)
20
- - **Ultimate build efficiency**: O(1), typically less than 0.2 seconds
17
+ - Intelligent dynamic positioning, always floating optimally in view
18
+ - Supports automatic theme switching following Material's light/dark color scheme
19
+ - Multi-language support, localization support, intelligent recognition of user language, automatic adaptation
20
+ - Cross-platform support (Windows, macOS, Linux)
21
+ - **Ultimate build efficiency**: O(1), no need to set env vars to distinguish runs
21
22
 
22
23
  | PK of Build Efficiency: | 100 md: | 1000 md: | Time Complexity: |
23
24
  | --------------------------- | :-----: | :------: | :----------: |
@@ -54,10 +55,8 @@ plugins:
54
55
  exclude: # List of excluded files
55
56
  - temp.md # Exclude specific file
56
57
  - drafts/* # Exclude all files in drafts folder, including subfolders
57
- locale: en # Localization: en zh zh_TW es fr de ar ja ko ru, default: en
58
58
  date_format: '%Y-%m-%d' # Date format strings, e.g., %Y-%m-%d, %b %d, %Y, etc
59
59
  time_format: '%H:%M:%S' # Time format strings (valid only if type=datetime)
60
- show_author: true # Show author or not, default: true
61
60
  ```
62
61
 
63
62
  ## Specify time manually
@@ -103,7 +102,7 @@ By default, the plugin will **automatically** loads the author avatar, without m
103
102
  3. Custom avatar: can be customized by customizing the author's `avatar` field in Front Matter
104
103
  ```markdown
105
104
  ---
106
- # Way 1: Configure a full author
105
+ # Way 1: Configure a full author (fields optional)
107
106
  author:
108
107
  name: jay
109
108
  email: jay@qq.com
@@ -114,35 +113,37 @@ By default, the plugin will **automatically** loads the author avatar, without m
114
113
  # Way 2: Configure multiple authors
115
114
  authors:
116
115
  - jaywhj
117
- - squidfunk
116
+ - dawang
118
117
  - sunny
119
118
 
120
119
  ---
121
120
  ```
122
- - If you want to configure complete information for multiple authors, you can create a separate configuration file `.authors.yml` in the `docs/` or `docs/blog/` directory, see the [.authors.yml](https://github.com/jaywhj/mkdocs-document-dates/blob/main/templates/.authors.yml) for its format
123
- - If the URL avatar fails to load, it falls back to the character avatar
121
+ - If you want to configure complete information for multiple authors, you can create a separate configuration file `authors.yml` in the `docs/` directory, see the [authors.yml](https://github.com/jaywhj/mkdocs-document-dates/blob/main/templates/authors.yml) for its format
122
+ - If the URL avatar fails to load, it automatically falls back to the character avatar
124
123
 
125
124
  ## Customization
126
125
 
127
- The plugin supports deep customization, such as **icon style, theme color, font, animation, dividing line**, etc. Everything is customizable (Find the file below and turn on the uncomment switch):
126
+ The plugin supports full customization, such as **icon style, theme color, font, animation, dividing line** etc, and the entrance has been preset, you just need to find the file below and uncomment it:
128
127
 
129
128
  | Category: | Location: |
130
129
  | :----------------------: | ---------------------------------------- |
131
130
  | **Style & Theme** | `docs/assets/document_dates/user.config.css` |
132
131
  | **Properties & Functions** | `docs/assets/document_dates/user.config.js` |
133
- | **Localized languages** | `docs/assets/document_dates/languages/` <br />refer to the template file `en.json` for any additions or modifications |
134
132
 
135
- **Tip**: when `type: timeago` is set, timeago.js is enabled to render dynamic time, `timeago.min.js` only contains English and Chinese by default, if you need to load other languages, you can configure it as below (choose one):
133
+ ![customization](customization.gif)
136
134
 
137
- - In `user.config.js`, refer to [the demo commented out](https://github.com/jaywhj/mkdocs-document-dates/blob/main/mkdocs_document_dates/static/config/user.config.js) at the bottom, translate it into your local language
138
- - In `mkdocs.yml`, configure the full version of `timeago.full.min.js` to load all languages at once
139
- ```yaml
140
- extra_javascript:
141
- - assets/document_dates/core/timeago.full.min.js
142
- - assets/document_dates/core/timeago-load.js
143
- ```
135
+ ## Localization
144
136
 
145
- ![customization](customization.gif)
137
+ - **tooltip**: the plugin has 10 built-in languages: `en zh zh_TW es fr de ar ja ko ru`, **no need for manual configuration**, intelligent recognition, automatic switching
138
+ - If the language is missing or the built-in language is inaccurate, you can refer to [Part 3](https://github.com/jaywhj/mkdocs-document-dates/blob/main/mkdocs_document_dates/static/config/user.config.js) in `user.config.js` to register and add it yourself, or submit an issue
139
+ - The original configuration option `locale` is retained, but manual configuration is no longer recommended
140
+ - **timeago**: when `type: timeago` is set, timeago.js is enabled to render dynamic time, `timeago.min.js` only contains English and Chinese by default, if need to load other languages, you can configure it as below (choose one):
141
+ - In `user.config.js`, refer to [Part 2](https://github.com/jaywhj/mkdocs-document-dates/blob/main/mkdocs_document_dates/static/config/user.config.js), register and add it yourself
142
+ - In `mkdocs.yml`, configure the full version of `timeago.full.min.js` to reload all languages at once
143
+ ```yaml
144
+ extra_javascript:
145
+ - assets/document_dates/core/timeago.full.min.js
146
+ ```
146
147
 
147
148
  ## Template Variables
148
149
 
@@ -151,8 +152,6 @@ You can access the meta-info of a document in a template using the following var
151
152
  - page.meta.document_dates_created
152
153
  - page.meta.document_dates_modified
153
154
  - page.meta.document_dates_authors
154
- - page.meta.document_dates_locale
155
- - page.meta.document_dates_translation
156
155
 
157
156
  Usage examples:
158
157
 
@@ -180,7 +179,7 @@ A dispensable, insignificant little plug-in, friends who have time can take a lo
180
179
  - Method 2: Cache the original time in advance, and then read the cache subsequently (The time is exact and no dependency on any environment). The cache can be in Front Matter of the source document or in a separate file, I chose the latter. Storing in Front Matter makes sense and is easier, but this will modify the source content of the document, although it doesn't have any impact on the body, but I still want to ensure the originality of the data!
181
180
  - **Difficulty**:
182
181
  1. When to read and store original time? This is just a plugin for mkdocs, with very limited access and permissions, mkdocs provides only build and serve, so in case a user commits directly without executing build or serve (e.g., when using a CI/CD build system), then you won't be able to retrieve the time information of the file, not to mention caching it!
183
- - Let's take a straight shot: the Git Hooks mechanism was found, prompted by the AI, which can trigger a custom script when a specific git action occurs, such as every time commit is performed
182
+ - Straight to the bottom line: Git Hooks can be used to trigger custom scripts when specific git actions occur, such as every time a commit occurs
184
183
  2. How to install Git Hooks automatically? When and how are they triggered? Installing packages from PyPI via pip doesn't have a standard post-install hook mechanism
185
184
  - Workaround: After analyzing the flow of pip installing packages from PyPI, I found that when compiling and installing through the source package (sdist), setuptools will be called to handle it, so we can find a way to implant the installation script in the process of setuptools, i.e., we can add a custom script in setup.py
186
185
  3. How to design a cross-platform hook? To execute a python script, we need to explicitly specify the python interpreter, and the user's python environment varies depending on the operating system, the way python is installed, and the configuration, so how can we ensure that it works properly in all environments?
@@ -190,10 +189,11 @@ A dispensable, insignificant little plug-in, friends who have time can take a lo
190
189
  5. How to reduce build time when there are a lot of documents ( >1000 )? Getting git information about a document is usually a file I/O operation, and if there are a lot of files, the efficiency of the operation will plummet. 1,000 documents can be expected to take more than 30 seconds, which is intolerable to the user
191
190
  - Solution: Reduce the number of I/Os + Use caching + Replace less efficient system functions
192
191
  - **Improve**:
193
- - Since it's a newly developed plugin, it will be designed in the direction of **excellent products**, and the pursuit of the ultimate **ease of use, simplicity and personalization**
194
- - **Ease of use**: don't let users do things manually if you can, e.g., auto-install Git Hooks, auto-cache, auto-commit, provide customized templates, etc
192
+ - Since it's a newly developed plugin, it will be designed in the direction of **excellent products**, and the pursuit of the ultimate **ease of use, simplicity, compatibility, personalization, intelligence**
193
+ - **Ease of use**: there are no complex configurations, only 2-3 commonly used configuration options, in addition, a template is provided for personalized configurations
195
194
  - **Simplicity**: no unnecessary configuration, no Git dependencies, no CI/CD configuration dependencies, no other package dependencies
196
- - **Personalization**: almost everything can be customized, whether it's icons, styles, themes, or features, it's all fully customizable
197
- - In addition, it has good compatibility and extensibility, and works well in WIN7, mobile devices, old Safari, etc
195
+ - **Compatibility**: works well on older operating systems and browsers, such as WIN7, MacOS 10.11, iOS 12, Chrome 63.0.3239
196
+ - **Personalization**: fully customizable and full control over the rendering logic, the plugin is only responsible for providing the data
197
+ - **Intelligence**: intelligently parse document time, author, avatar, intelligent recognition of user language and automatic adaptation, in addition, there are auto-install Git Hooks, auto-cache, auto-commit
198
198
  - **The Last Secret**:
199
199
  - Programming is a hobby, and I'm a marketer of 8 years (Feel free to leave a comment)
@@ -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
4
+ from .utils import read_json_cache, 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
@@ -94,6 +94,10 @@ def update_cache():
94
94
  project_updated = True
95
95
  elif full_path.exists():
96
96
  created_time = get_file_creation_time(full_path).astimezone()
97
+ if not jsonl_cache_file.exists() and not json_cache_file.exists():
98
+ git_time = get_git_first_commit_time(full_path)
99
+ if git_time:
100
+ created_time = min(created_time, git_time)
97
101
  jsonl_dates_cache[rel_path] = {
98
102
  "created": created_time.isoformat()
99
103
  }
@@ -1,5 +1,4 @@
1
1
  import os
2
- import json
3
2
  import yaml
4
3
  import shutil
5
4
  import logging
@@ -36,7 +35,7 @@ class Author:
36
35
  class DocumentDatesPlugin(BasePlugin):
37
36
  config_scheme = (
38
37
  ('type', config_options.Type(str, default='date')),
39
- ('locale', config_options.Type(str, default=None)),
38
+ ('locale', config_options.Type(str, default='')),
40
39
  ('date_format', config_options.Type(str, default='%Y-%m-%d')),
41
40
  ('time_format', config_options.Type(str, default='%H:%M:%S')),
42
41
  ('position', config_options.Type(str, default='top')),
@@ -48,35 +47,26 @@ class DocumentDatesPlugin(BasePlugin):
48
47
 
49
48
  def __init__(self):
50
49
  super().__init__()
51
- self.translation = {}
52
50
  self.dates_cache = {}
53
51
  self.authors_yml = {}
54
52
  self.github_username = None
55
53
 
56
54
  def on_config(self, config):
57
- try:
58
- # 设置 locale 在无配置时跟随主题语言
59
- if not self.config['locale']:
60
- self.config['locale'] = config['theme']['language']
61
- except Exception:
62
- self.config['locale'] = 'en'
63
-
64
55
  docs_dir_path = Path(config['docs_dir'])
65
56
 
66
57
  # 加载 author 配置
67
58
  if self.config['show_author']:
68
59
  self._extract_github_username(config.get('repo_url'))
69
- try:
70
- blog_config = config['plugins']['material/blog'].config
71
- authors_file_resolved = blog_config.authors_file.format(blog=blog_config.blog_dir)
72
- authors_file = docs_dir_path / authors_file_resolved
73
- except Exception:
74
- authors_file = docs_dir_path / '.authors.yml'
60
+ authors_file = docs_dir_path / 'authors.yml'
61
+ if not authors_file.exists():
62
+ try:
63
+ blog_config = config['plugins']['material/blog'].config
64
+ authors_file_resolved = blog_config.authors_file.format(blog=blog_config.blog_dir)
65
+ authors_file = docs_dir_path / authors_file_resolved
66
+ except Exception:
67
+ pass
75
68
  self._load_authors_from_yaml(authors_file)
76
69
 
77
- # 加载 json 语言文件
78
- self._load_translation(docs_dir_path)
79
-
80
70
  # 加载 git 缓存
81
71
  self.dates_cache = load_git_cache(docs_dir_path)
82
72
  # 加载 jsonl 缓存覆盖
@@ -106,7 +96,7 @@ class DocumentDatesPlugin(BasePlugin):
106
96
  dest_dir = docs_dir_path / 'assets' / 'document_dates'
107
97
  dest_dir.mkdir(parents=True, exist_ok=True)
108
98
 
109
- for dir_name in ['tippy', 'core']:
99
+ for dir_name in ['tippy', 'core', 'fonts']:
110
100
  source_dir = Path(__file__).parent / 'static' / dir_name
111
101
  target_dir = dest_dir / dir_name
112
102
  # shutil.copytree(source_dir, target_dir, dirs_exist_ok=True)
@@ -123,9 +113,9 @@ class DocumentDatesPlugin(BasePlugin):
123
113
  if not target_config.exists():
124
114
  shutil.copy2(source_config, target_config)
125
115
 
126
-
127
- # 加载图标 Google Fonts Icons: https://fonts.google.com/icons
128
- material_icons_url = 'https://fonts.googleapis.com/icon?family=Material+Icons'
116
+ # 加载离线 Google Fonts Icons: https://fonts.google.com/icons
117
+ # material_icons_url = 'https://fonts.googleapis.com/icon?family=Material+Icons'
118
+ material_icons_url = 'assets/document_dates/fonts/material-icons.css'
129
119
  if material_icons_url not in config['extra_css']:
130
120
  config['extra_css'].append(material_icons_url)
131
121
 
@@ -133,10 +123,7 @@ class DocumentDatesPlugin(BasePlugin):
133
123
  # https://cdn.jsdelivr.net/npm/timeago.js@4.0.2/dist/timeago.min.js
134
124
  # https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.2/timeago.full.min.js
135
125
  if self.config['type'] == 'timeago':
136
- config['extra_javascript'][0:0] = [
137
- 'assets/document_dates/core/timeago.min.js',
138
- 'assets/document_dates/core/timeago-load.js'
139
- ]
126
+ config['extra_javascript'].insert(0, 'assets/document_dates/core/timeago.min.js')
140
127
 
141
128
  # 加载 Tippy CSS 文件
142
129
  tippy_css_dir = dest_dir / 'tippy'
@@ -156,13 +143,12 @@ class DocumentDatesPlugin(BasePlugin):
156
143
 
157
144
  # 加载自定义 JS 文件
158
145
  config['extra_javascript'].extend([
159
- 'assets/document_dates/core/core.js',
160
- 'assets/document_dates/user.config.js'
146
+ 'assets/document_dates/core/default.config.js',
147
+ 'assets/document_dates/user.config.js',
148
+ 'assets/document_dates/core/utils.js',
149
+ 'assets/document_dates/core/core.js'
161
150
  ])
162
151
 
163
- if self.config['locale'] == 'zh':
164
- self.config['locale'] = 'zh_CN'
165
-
166
152
  return config
167
153
 
168
154
  def on_page_markdown(self, markdown, page: Page, config, files):
@@ -189,8 +175,6 @@ class DocumentDatesPlugin(BasePlugin):
189
175
  page.meta['document_dates_created'] = created.isoformat()
190
176
  page.meta['document_dates_modified'] = modified.isoformat()
191
177
  page.meta['document_dates_authors'] = authors
192
- page.meta['document_dates_locale'] = self.config['locale']
193
- page.meta['document_dates_translation'] = self.translation
194
178
 
195
179
  # 检查是否需要排除
196
180
  if self._is_excluded(rel_path):
@@ -232,37 +216,6 @@ class DocumentDatesPlugin(BasePlugin):
232
216
  except Exception as e:
233
217
  logger.info(f"Error parsing .authors.yml: {e}")
234
218
 
235
- def _load_translation(self, docs_dir_path: Path):
236
- # 内置语言文件目录
237
- builtin_dir = Path(__file__).parent / 'static' / 'languages'
238
- # 用户自定义语言文件目录
239
- custom_dir = docs_dir_path / 'assets' / 'document_dates' / 'languages'
240
-
241
- # 加载语言文件
242
- self._load_lang_file(builtin_dir)
243
- self._load_lang_file(custom_dir)
244
- if not self.translation:
245
- self.config['locale'] = 'en'
246
- self._load_lang_file(builtin_dir)
247
-
248
- # 复制 en.json 到用户目录作为自定义参考
249
- custom_en_json = custom_dir / 'en.json'
250
- if not custom_en_json.exists():
251
- custom_dir.mkdir(parents=True, exist_ok=True)
252
- en_json = builtin_dir / 'en.json'
253
- shutil.copy2(en_json, custom_en_json)
254
-
255
- def _load_lang_file(self, lang_dir: Path):
256
- try:
257
- locale_file = lang_dir / f"{self.config['locale']}.json"
258
- if locale_file.exists():
259
- with locale_file.open('r', encoding='utf-8') as f:
260
- self.translation = json.load(f)
261
- except json.JSONDecodeError as e:
262
- logger.error(f"Invalid JSON format in language file {locale_file}: {str(e)}")
263
- except Exception as e:
264
- logger.error(f"Error loading language file {locale_file}: {str(e)}")
265
-
266
219
 
267
220
  def _is_excluded(self, rel_path):
268
221
  for pattern in self.config['exclude']:
@@ -366,20 +319,19 @@ class DocumentDatesPlugin(BasePlugin):
366
319
  html_parts = []
367
320
  position_class = 'document-dates-top' if self.config['position'] == 'top' else 'document-dates-bottom'
368
321
  html_parts.append(f"<div class='document-dates-plugin-wrapper {position_class}'>")
369
- html_parts.append(f"<div class='document-dates-plugin'>")
322
+ html_parts.append(f"<div class='document-dates-plugin' locale='{self.config['locale']}'>")
370
323
 
371
- def build_time_icon(time_obj: datetime, icon: str, label_key: str, default_label:str):
324
+ def build_time_icon(time_obj: datetime, icon: str):
372
325
  formatted = time_obj.strftime(self.config['date_format'])
373
- tooltip = f"{self.translation.get(label_key, default_label)}: {formatted}"
374
326
  return (
375
- f"<span data-tippy-content='{tooltip}'>"
327
+ f"<span data-tippy-content data-tippy-raw='{formatted}'>"
376
328
  f"<span class='material-icons' data-icon='{icon}'></span>"
377
- f"<time datetime='{time_obj.isoformat()}' locale='{self.config['locale']}'>"
329
+ f"<time datetime='{time_obj.isoformat()}'>"
378
330
  f"{self._get_formatted_date(time_obj)}</time></span>"
379
331
  )
380
332
 
381
- html_parts.append(build_time_icon(created, 'doc_created', 'created_time', 'Created'))
382
- html_parts.append(build_time_icon(modified, 'doc_modified', 'modified_time', 'Last Update'))
333
+ html_parts.append(build_time_icon(created, 'doc_created'))
334
+ html_parts.append(build_time_icon(modified, 'doc_modified'))
383
335
 
384
336
  # 添加作者信息
385
337
  if self.config['show_author'] and authors:
@@ -388,14 +340,13 @@ class DocumentDatesPlugin(BasePlugin):
388
340
  return f'&lt;a href="{author.url}" target="_blank"&gt;{author.name}&lt;/a&gt;'
389
341
  elif author.email:
390
342
  return f'&lt;a href="mailto:{author.email}"&gt;{author.name}&lt;/a&gt;'
391
- else:
392
- return author.name
343
+ return author.name
393
344
 
394
- def get_avatar_img(author):
345
+ def get_avatar_img_url(author):
395
346
  if author.avatar:
396
- return f"<img class='avatar' src='{author.avatar}' />"
347
+ return author.avatar
397
348
  elif self.github_username and len(authors) == 1:
398
- return f"<img class='avatar' src='https://avatars.githubusercontent.com/{self.github_username}' />"
349
+ return f"https://avatars.githubusercontent.com/{self.github_username}"
399
350
  return ""
400
351
 
401
352
  icon = 'doc_author' if len(authors) == 1 else 'doc_authors'
@@ -403,10 +354,11 @@ class DocumentDatesPlugin(BasePlugin):
403
354
  html_parts.append("<div class='avatar-group'>")
404
355
  for author in authors:
405
356
  tooltip = get_author_tooltip(author)
406
- img_ele = get_avatar_img(author)
357
+ img_url = get_avatar_img_url(author)
407
358
  html_parts.append(
408
- f"<div class='avatar-wrapper' data-name='{author.name}' data-tippy-content='{self.translation.get('author', 'Author')}: {tooltip}'>"
409
- f"{img_ele}<span class='avatar-text'></span>"
359
+ f"<div class='avatar-wrapper' data-name='{author.name}' data-tippy-content data-tippy-raw='{tooltip}'>"
360
+ f"<span class='avatar-text'></span>"
361
+ f"<img class='avatar' src='{img_url}' />"
410
362
  f"</div>"
411
363
  )
412
364
  html_parts.append("</div>")
@@ -423,7 +375,7 @@ class DocumentDatesPlugin(BasePlugin):
423
375
  if self.config['position'] == 'top':
424
376
  first_line, insert_pos = self.find_markdown_body_start(markdown)
425
377
  if first_line.startswith(('# ', '<h1')):
426
- return markdown[:insert_pos] + date_info + '\n' + markdown[insert_pos:]
378
+ return markdown[:insert_pos] + '\n' + date_info + '\n' + markdown[insert_pos:]
427
379
  else:
428
380
  return f"{date_info}\n{markdown}"
429
381
  return f"{markdown}\n\n{date_info}"
@@ -43,13 +43,6 @@
43
43
  border-bottom: none;
44
44
  } */
45
45
 
46
- /* Hide this plugin (default build version):
47
- and then you can reformulate the plugin's arbitrary display position and style based on template variables */
48
- /*
49
- .document-dates-plugin-wrapper {
50
- display: none;
51
- } */
52
-
53
46
 
54
47
 
55
48
  /* 3. Tooltip styles
@@ -0,0 +1,96 @@
1
+ /*
2
+ Part 1:
3
+ Configuration Overrides for Tooltip
4
+ see: https://atomiks.github.io/tippyjs/
5
+ */
6
+
7
+ /* Configure one by one: */
8
+ // tooltip_config.theme.light = 'tomato';
9
+ // tooltip_config.placement = 'top';
10
+ // tooltip_config.arrow = false;
11
+
12
+ /* Or, override all configuration items: */
13
+ /*
14
+ TooltipConfig.setConfig({
15
+ theme: {
16
+ // configurable: light material, or custom theme in user.config.css, for example: sorrel sublime tomato
17
+ light: 'light',
18
+ dark: 'material'
19
+ },
20
+ placement: 'bottom', // placement: top bottom left right auto
21
+ offset: [0, 12], // placement offset: [horizontal, vertical]
22
+ allowHTML: true, // whether to allow HTML in the tooltip content
23
+ interactive: true, // content in Tooltip is interactive
24
+ animation: 'scale', // animation type: scale shift-away
25
+ inertia: true, // animation inertia
26
+ // arrow: false, // whether to allow arrows
27
+ // animateFill: true, // determines if the background fill color should be animated
28
+ // delay: [400, null], // delay: [show, hide]: show is 400ms, and hide is null for the default value
29
+ });
30
+ */
31
+
32
+
33
+
34
+ /*
35
+ Part 2:
36
+ Demonstrates how to register a local language when using 'timeago.js',
37
+ then you can configure the localeStr you just registered anywhere!
38
+ */
39
+ /*
40
+ const localeFunc = (number, index) => {
41
+ return [
42
+ ['just now', 'right now'],
43
+ ['%s seconds ago', 'in %s seconds'],
44
+ ['1 minute ago', 'in 1 minute'],
45
+ ['%s minutes ago', 'in %s minutes'],
46
+ ['1 hour ago', 'in 1 hour'],
47
+ ['%s hours ago', 'in %s hours'],
48
+ ['1 day ago', 'in 1 day'],
49
+ ['%s days ago', 'in %s days'],
50
+ ['1 week ago', 'in 1 week'],
51
+ ['%s weeks ago', 'in %s weeks'],
52
+ ['1 month ago', 'in 1 month'],
53
+ ['%s months ago', 'in %s months'],
54
+ ['1 year ago', 'in 1 year'],
55
+ ['%s years ago', 'in %s years']
56
+ ][index];
57
+ };
58
+ const localeStr = 'any';
59
+ timeago.register(localeStr, localeFunc);
60
+ */
61
+
62
+
63
+
64
+ /*
65
+ Part 3:
66
+ Demonstrates how to register the local language for the plugin's tooltip,
67
+ when the local language is missing, or when the default language translation is inaccurate.
68
+ */
69
+ /*
70
+ // Way 1: User-defined one language
71
+ TooltipLanguage.register('en', {
72
+ created_time: "Custom Created",
73
+ modified_time: "Custom Last Update",
74
+ author: "Custom Author",
75
+ authors: "Custom Authors"
76
+ });
77
+
78
+ // Way 2: User-defined multiple languages
79
+ const userLanguages = {
80
+ en: {
81
+ created_time: "Created",
82
+ modified_time: "Last Update",
83
+ author: "Author",
84
+ authors: "Authors"
85
+ },
86
+ zh: {
87
+ created_time: "创建时间",
88
+ modified_time: "最后更新",
89
+ author: "作者",
90
+ authors: "作者"
91
+ }
92
+ };
93
+ Object.entries(userLanguages).forEach(([locale, data]) => {
94
+ TooltipLanguage.register(locale, data);
95
+ });
96
+ */