mkdocs-document-dates 1.7.0__tar.gz → 1.9.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.7.0 → mkdocs_document_dates-1.9.0}/PKG-INFO +1 -1
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/hooks/pre-commit +49 -21
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/PKG-INFO +1 -1
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/setup.py +1 -1
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/LICENSE +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/README.md +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/__init__.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/__init__.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ar.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/de.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/en.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/es.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/fr.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ja.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ko.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ru.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/zh.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/plugin.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/styles.py +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
- {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/setup.cfg +0 -0
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/hooks/pre-commit
RENAMED
@@ -4,9 +4,48 @@ import sys
|
|
4
4
|
import json
|
5
5
|
import platform
|
6
6
|
import subprocess
|
7
|
+
import logging
|
7
8
|
from datetime import datetime
|
8
9
|
from pathlib import Path
|
9
10
|
|
11
|
+
# 配置日志
|
12
|
+
def setup_logging():
|
13
|
+
"""设置日志"""
|
14
|
+
try:
|
15
|
+
# 获取当前 git 仓库根目录
|
16
|
+
git_root = Path(subprocess.check_output(
|
17
|
+
['git', 'rev-parse', '--show-toplevel'],
|
18
|
+
text=True
|
19
|
+
).strip())
|
20
|
+
|
21
|
+
# 在 git 仓库根目录下创建日志目录
|
22
|
+
log_dir = git_root / '.mkdocs_dates'
|
23
|
+
log_dir.mkdir(exist_ok=True)
|
24
|
+
log_file = log_dir / 'hook.log'
|
25
|
+
|
26
|
+
logging.basicConfig(
|
27
|
+
level=logging.INFO,
|
28
|
+
format='%(asctime)s - %(levelname)s - %(message)s',
|
29
|
+
handlers=[
|
30
|
+
logging.FileHandler(log_file),
|
31
|
+
logging.StreamHandler(sys.stderr)
|
32
|
+
]
|
33
|
+
)
|
34
|
+
return True
|
35
|
+
except Exception as e:
|
36
|
+
print(f"Failed to setup logging: {e}", file=sys.stderr)
|
37
|
+
return False
|
38
|
+
|
39
|
+
if __name__ == "__main__":
|
40
|
+
try:
|
41
|
+
if setup_logging():
|
42
|
+
logging.info("Starting pre-commit hook...")
|
43
|
+
update_dates_cache()
|
44
|
+
logging.info("Pre-commit hook completed successfully")
|
45
|
+
except Exception as e:
|
46
|
+
print(f"Error in pre-commit hook: {e}", file=sys.stderr)
|
47
|
+
sys.exit(1)
|
48
|
+
|
10
49
|
def find_mkdocs_projects():
|
11
50
|
"""查找当前 git 仓库中的所有 MkDocs 项目"""
|
12
51
|
try:
|
@@ -54,12 +93,10 @@ def update_dates_cache():
|
|
54
93
|
if not docs_dir.exists():
|
55
94
|
continue
|
56
95
|
|
57
|
-
|
58
|
-
|
59
|
-
print(f"Docs directory: {docs_dir}")
|
96
|
+
logging.info(f"Processing MkDocs project: {project_dir}")
|
97
|
+
logging.info(f"Docs directory: {docs_dir}")
|
60
98
|
|
61
99
|
dates_cache = {}
|
62
|
-
# 获取所有 markdown 文件的时间信息
|
63
100
|
for md_file in docs_dir.rglob("*.md"):
|
64
101
|
rel_path = str(md_file.relative_to(docs_dir))
|
65
102
|
created, modified = get_file_dates(md_file)
|
@@ -67,25 +104,16 @@ def update_dates_cache():
|
|
67
104
|
"created": created,
|
68
105
|
"modified": modified
|
69
106
|
}
|
70
|
-
|
107
|
+
logging.info(f"Processing file: {rel_path}")
|
71
108
|
|
72
|
-
# 保存缓存文件
|
73
109
|
cache_file = docs_dir / '.dates_cache.json'
|
74
|
-
|
75
|
-
with open(cache_file, "w") as f:
|
76
|
-
json.dump(dates_cache, f, indent=2, ensure_ascii=False)
|
110
|
+
logging.info(f"Saving cache to: {cache_file}")
|
77
111
|
|
78
112
|
try:
|
113
|
+
with open(cache_file, "w") as f:
|
114
|
+
json.dump(dates_cache, f, indent=2, ensure_ascii=False)
|
79
115
|
subprocess.run(["git", "add", str(cache_file)], check=True)
|
80
|
-
|
81
|
-
except
|
82
|
-
|
83
|
-
|
84
|
-
if __name__ == "__main__":
|
85
|
-
try:
|
86
|
-
print("Starting pre-commit hook...")
|
87
|
-
update_dates_cache()
|
88
|
-
print("Pre-commit hook completed successfully")
|
89
|
-
except Exception as e:
|
90
|
-
print(f"Error in pre-commit hook: {e}", file=sys.stderr)
|
91
|
-
sys.exit(1)
|
116
|
+
logging.info(f"Added cache file to git: {cache_file}")
|
117
|
+
except Exception as e:
|
118
|
+
logging.error(f"Error handling cache file: {e}")
|
119
|
+
raise
|
File without changes
|
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/__init__.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/__init__.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ar.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/de.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/en.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/es.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/fr.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ja.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ko.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ru.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/zh.py
RENAMED
File without changes
|
{mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.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
|
File without changes
|