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.
Files changed (26) hide show
  1. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/PKG-INFO +1 -1
  2. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/hooks/pre-commit +49 -21
  3. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/PKG-INFO +1 -1
  4. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/setup.py +1 -1
  5. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/LICENSE +0 -0
  6. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/README.md +0 -0
  7. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/__init__.py +0 -0
  8. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/__init__.py +0 -0
  9. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ar.py +0 -0
  10. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/de.py +0 -0
  11. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/en.py +0 -0
  12. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/es.py +0 -0
  13. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/fr.py +0 -0
  14. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ja.py +0 -0
  15. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ko.py +0 -0
  16. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/ru.py +0 -0
  17. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/zh.py +0 -0
  18. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
  19. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/plugin.py +0 -0
  20. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates/styles.py +0 -0
  21. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  22. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  23. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  24. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  25. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  26. {mkdocs_document_dates-1.7.0 → mkdocs_document_dates-1.9.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.7.0
3
+ Version: 1.9.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
@@ -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
- print(f"Processing MkDocs project: {project_dir}")
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
- print(f"Processing file: {rel_path}")
107
+ logging.info(f"Processing file: {rel_path}")
71
108
 
72
- # 保存缓存文件
73
109
  cache_file = docs_dir / '.dates_cache.json'
74
- print(f"Saving cache to: {cache_file}")
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
- print(f"Added cache file to git: {cache_file}")
81
- except subprocess.CalledProcessError as e:
82
- print(f"Error adding cache file to git: {e}")
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.7.0
3
+ Version: 1.9.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
@@ -67,7 +67,7 @@ try:
67
67
  except FileNotFoundError:
68
68
  long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
69
69
 
70
- VERSION = '1.7.0'
70
+ VERSION = '1.9.0'
71
71
 
72
72
  setup(
73
73
  name="mkdocs-document-dates",