mkdocs-document-dates 1.2.0__tar.gz → 1.4.0__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-1.2.0 → mkdocs_document_dates-1.4.0}/PKG-INFO +4 -2
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/README.md +3 -1
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/hooks/pre-commit +14 -54
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/plugin.py +12 -12
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/PKG-INFO +4 -2
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/setup.py +28 -5
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/LICENSE +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/__init__.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/__init__.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ar.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/de.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/en.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/es.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/fr.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ja.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ko.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ru.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/zh.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/styles.py +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
- {mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: mkdocs-document-dates
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.4.0
|
4
4
|
Summary: A MkDocs plugin for displaying accurate document creation and last modification dates.
|
5
5
|
Home-page: https://github.com/jaywhj/mkdocs-document-dates
|
6
6
|
Author: Aaron Wang
|
@@ -112,8 +112,10 @@ modified: 2023-12-31
|
|
112
112
|
- Linux: Uses modification time as creation time due to system limitations, if you need the exact creation time, you can manually specify it in Front Matter
|
113
113
|
- It still works when using CI/CD build systems (e.g. Github Actions)
|
114
114
|
- Used a cache file `dates_cache.json` to solve this problem
|
115
|
-
- You can configure it like this: `pip install --upgrade mkdocs-document-dates`
|
115
|
+
- You can configure it like this: `pip install --upgrade mkdocs-document-dates`
|
116
116
|
```
|
117
|
+
...
|
118
|
+
|
117
119
|
- run: pip install --upgrade mkdocs-document-dates
|
118
120
|
- run: mkdocs gh-deploy --force
|
119
121
|
```
|
@@ -90,8 +90,10 @@ modified: 2023-12-31
|
|
90
90
|
- Linux: Uses modification time as creation time due to system limitations, if you need the exact creation time, you can manually specify it in Front Matter
|
91
91
|
- It still works when using CI/CD build systems (e.g. Github Actions)
|
92
92
|
- Used a cache file `dates_cache.json` to solve this problem
|
93
|
-
- You can configure it like this: `pip install --upgrade mkdocs-document-dates`
|
93
|
+
- You can configure it like this: `pip install --upgrade mkdocs-document-dates`
|
94
94
|
```
|
95
|
+
...
|
96
|
+
|
95
97
|
- run: pip install --upgrade mkdocs-document-dates
|
96
98
|
- run: mkdocs gh-deploy --force
|
97
99
|
```
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/hooks/pre-commit
RENAMED
@@ -4,7 +4,6 @@ import sys
|
|
4
4
|
import json
|
5
5
|
import platform
|
6
6
|
import subprocess
|
7
|
-
import traceback
|
8
7
|
from datetime import datetime
|
9
8
|
from pathlib import Path
|
10
9
|
|
@@ -47,73 +46,34 @@ def get_file_dates(file_path):
|
|
47
46
|
current_time = datetime.now()
|
48
47
|
return current_time.isoformat(), current_time.isoformat()
|
49
48
|
|
49
|
+
|
50
50
|
def update_dates_cache():
|
51
51
|
"""更新文档时间缓存"""
|
52
|
-
|
53
|
-
if not projects:
|
54
|
-
print("No MkDocs projects found")
|
55
|
-
return
|
56
|
-
|
57
|
-
for project_dir in projects:
|
52
|
+
for project_dir in find_mkdocs_projects():
|
58
53
|
docs_dir = project_dir / 'docs'
|
59
54
|
if not docs_dir.exists():
|
60
55
|
continue
|
61
|
-
|
62
|
-
# 检查 assets 目录
|
63
|
-
assets_dir = docs_dir / 'assets'
|
64
|
-
if not assets_dir.exists():
|
65
|
-
assets_dir.mkdir(parents=True)
|
66
|
-
|
67
|
-
cache_file = assets_dir / 'dates_cache.json'
|
68
|
-
dates_cache = _load_cache(cache_file)
|
69
|
-
|
70
|
-
_update_cache(docs_dir, dates_cache)
|
71
|
-
_save_cache(cache_file, dates_cache)
|
72
56
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
with open(cache_file) as f:
|
78
|
-
return json.load(f)
|
79
|
-
except json.JSONDecodeError:
|
80
|
-
pass
|
81
|
-
return {}
|
82
|
-
|
83
|
-
def _update_cache(docs_dir, dates_cache):
|
84
|
-
"""更新缓存内容"""
|
85
|
-
# 记录当前所有的 markdown 文件
|
86
|
-
current_files = set()
|
87
|
-
|
88
|
-
# 处理新增和更新的文件
|
89
|
-
for md_file in docs_dir.rglob("*.md"):
|
90
|
-
rel_path = str(md_file.relative_to(docs_dir))
|
91
|
-
current_files.add(rel_path)
|
92
|
-
|
93
|
-
# 文件不在缓存中(新增)或文件修改时间变化(更新)
|
94
|
-
if rel_path not in dates_cache or os.path.getmtime(md_file) != dates_cache[rel_path].get("mtime", 0):
|
57
|
+
dates_cache = {}
|
58
|
+
# 获取所有 markdown 文件的时间信息
|
59
|
+
for md_file in docs_dir.rglob("*.md"):
|
60
|
+
rel_path = str(md_file.relative_to(docs_dir))
|
95
61
|
created, modified = get_file_dates(md_file)
|
96
62
|
dates_cache[rel_path] = {
|
97
63
|
"created": created,
|
98
|
-
"modified": modified
|
99
|
-
"mtime": os.path.getmtime(md_file)
|
64
|
+
"modified": modified
|
100
65
|
}
|
101
|
-
|
102
|
-
# 处理删除的文件
|
103
|
-
for cached_path in list(dates_cache.keys()):
|
104
|
-
if cached_path not in current_files:
|
105
|
-
del dates_cache[cached_path]
|
106
66
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
67
|
+
# 保存缓存文件
|
68
|
+
cache_file = docs_dir / '.dates_cache.json'
|
69
|
+
with open(cache_file, "w") as f:
|
70
|
+
json.dump(dates_cache, f, indent=2, ensure_ascii=False)
|
71
|
+
subprocess.run(["git", "add", str(cache_file)], check=True)
|
72
|
+
|
112
73
|
|
113
|
-
# 添加主入口
|
114
74
|
if __name__ == "__main__":
|
115
75
|
try:
|
116
76
|
update_dates_cache()
|
117
77
|
except Exception as e:
|
118
|
-
|
78
|
+
print(f"Error updating dates cache: {e}", file=sys.stderr)
|
119
79
|
sys.exit(1)
|
@@ -84,10 +84,16 @@ class DocumentDatesPlugin(BasePlugin):
|
|
84
84
|
if self._is_excluded(file_path, Path(config['docs_dir'])):
|
85
85
|
return markdown
|
86
86
|
|
87
|
+
# 获取文件时间
|
87
88
|
created, modified = self._get_file_dates(file_path)
|
89
|
+
|
90
|
+
# 处理 front matter 中的时间
|
88
91
|
created, modified = self._process_meta_dates(page.meta, created, modified)
|
89
92
|
|
93
|
+
# 生成日期信息 HTML
|
90
94
|
date_info = self._get_date_info(created, modified)
|
95
|
+
|
96
|
+
# 将日期信息写入 markdown
|
91
97
|
return self._insert_date_info(markdown, date_info)
|
92
98
|
|
93
99
|
def _is_excluded(self, file_path: Path, docs_dir: Path) -> bool:
|
@@ -148,21 +154,15 @@ class DocumentDatesPlugin(BasePlugin):
|
|
148
154
|
def _get_file_dates(self, file_path):
|
149
155
|
"""获取文件的创建时间和修改时间"""
|
150
156
|
try:
|
151
|
-
#
|
152
|
-
|
157
|
+
# 获取文件的相对路径(相对于 docs 目录)
|
158
|
+
docs_dir = Path(self.config['docs_dir'])
|
159
|
+
rel_path = str(Path(file_path).relative_to(docs_dir))
|
153
160
|
|
154
|
-
#
|
155
|
-
cache_file =
|
156
|
-
if not cache_file.exists():
|
157
|
-
# 如果不存在,尝试开发时的路径(docs/assets/dates_cache.json)
|
158
|
-
docs_dir = Path(file_path).parent.parent
|
159
|
-
cache_file = docs_dir / 'assets' / 'dates_cache.json'
|
160
|
-
|
161
|
+
# 尝试从缓存文件读取时间信息
|
162
|
+
cache_file = docs_dir / '.dates_cache.json'
|
161
163
|
if cache_file.exists():
|
162
164
|
with open(cache_file) as f:
|
163
165
|
dates_cache = json.load(f)
|
164
|
-
# 获取相对于 docs 目录的路径
|
165
|
-
rel_path = str(Path(file_path).name) # 只使用文件名,因为发布后目录结构已改变
|
166
166
|
if rel_path in dates_cache:
|
167
167
|
return (
|
168
168
|
datetime.fromisoformat(dates_cache[rel_path]['created']),
|
@@ -185,7 +185,7 @@ class DocumentDatesPlugin(BasePlugin):
|
|
185
185
|
created = modified
|
186
186
|
|
187
187
|
return created, modified
|
188
|
-
|
188
|
+
|
189
189
|
except (OSError, ValueError, json.JSONDecodeError) as e:
|
190
190
|
current_time = datetime.now()
|
191
191
|
return current_time, current_time
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: mkdocs-document-dates
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.4.0
|
4
4
|
Summary: A MkDocs plugin for displaying accurate document creation and last modification dates.
|
5
5
|
Home-page: https://github.com/jaywhj/mkdocs-document-dates
|
6
6
|
Author: Aaron Wang
|
@@ -112,8 +112,10 @@ modified: 2023-12-31
|
|
112
112
|
- Linux: Uses modification time as creation time due to system limitations, if you need the exact creation time, you can manually specify it in Front Matter
|
113
113
|
- It still works when using CI/CD build systems (e.g. Github Actions)
|
114
114
|
- Used a cache file `dates_cache.json` to solve this problem
|
115
|
-
- You can configure it like this: `pip install --upgrade mkdocs-document-dates`
|
115
|
+
- You can configure it like this: `pip install --upgrade mkdocs-document-dates`
|
116
116
|
```
|
117
|
+
...
|
118
|
+
|
117
119
|
- run: pip install --upgrade mkdocs-document-dates
|
118
120
|
- run: mkdocs gh-deploy --force
|
119
121
|
```
|
@@ -1,4 +1,6 @@
|
|
1
1
|
from setuptools import setup, find_packages
|
2
|
+
from setuptools.command.install import install
|
3
|
+
from setuptools.command.develop import develop
|
2
4
|
from setuptools.command.build_py import build_py
|
3
5
|
import os
|
4
6
|
import subprocess
|
@@ -10,19 +12,38 @@ def install_git_hooks():
|
|
10
12
|
hooks_dir = project_dir / 'mkdocs_document_dates' / 'hooks'
|
11
13
|
|
12
14
|
if not hooks_dir.exists():
|
15
|
+
print("Warning: Hooks directory not found")
|
13
16
|
return
|
14
17
|
|
15
|
-
#
|
18
|
+
# 确保 hooks 目录存在且有执行权限
|
19
|
+
subprocess.run(['chmod', '-R', '755', str(hooks_dir)], check=True)
|
20
|
+
|
21
|
+
# 设置全局 hooks 路径
|
16
22
|
subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
|
17
23
|
check=True)
|
18
24
|
|
25
|
+
# 验证 hook 是否正确安装
|
19
26
|
hook_path = hooks_dir / 'pre-commit'
|
20
|
-
if hook_path.exists():
|
21
|
-
|
27
|
+
if not hook_path.exists():
|
28
|
+
print("Warning: pre-commit hook not found")
|
29
|
+
return
|
30
|
+
|
31
|
+
os.chmod(hook_path, 0o755)
|
32
|
+
print(f"Git hooks installed successfully at: {hooks_dir}")
|
22
33
|
|
23
34
|
except Exception as e:
|
24
35
|
print(f"Warning: Failed to install git hooks: {e}")
|
25
36
|
|
37
|
+
class CustomInstall(install):
|
38
|
+
def run(self):
|
39
|
+
install.run(self)
|
40
|
+
install_git_hooks()
|
41
|
+
|
42
|
+
class CustomDevelop(develop):
|
43
|
+
def run(self):
|
44
|
+
develop.run(self)
|
45
|
+
install_git_hooks()
|
46
|
+
|
26
47
|
class CustomBuildPy(build_py):
|
27
48
|
def run(self):
|
28
49
|
build_py.run(self)
|
@@ -34,7 +55,7 @@ try:
|
|
34
55
|
except FileNotFoundError:
|
35
56
|
long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
|
36
57
|
|
37
|
-
VERSION = '1.
|
58
|
+
VERSION = '1.4.0'
|
38
59
|
|
39
60
|
setup(
|
40
61
|
name="mkdocs-document-dates",
|
@@ -59,7 +80,9 @@ setup(
|
|
59
80
|
]
|
60
81
|
},
|
61
82
|
cmdclass={
|
62
|
-
'build_py': CustomBuildPy,
|
83
|
+
'build_py': CustomBuildPy,
|
84
|
+
'install': CustomInstall,
|
85
|
+
'develop': CustomDevelop,
|
63
86
|
},
|
64
87
|
package_data={
|
65
88
|
'mkdocs_document_dates': ['hooks/*'],
|
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/__init__.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/__init__.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ar.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/de.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/en.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/es.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/fr.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ja.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ko.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ru.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/zh.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.2.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/zh_tw.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|