mkdocs-document-dates 1.6.0__tar.gz → 1.8.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.6.0 → mkdocs_document_dates-1.8.0}/PKG-INFO +1 -1
  2. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/hooks/pre-commit +31 -7
  3. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates.egg-info/PKG-INFO +1 -1
  4. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/setup.py +15 -13
  5. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/LICENSE +0 -0
  6. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/README.md +0 -0
  7. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/__init__.py +0 -0
  8. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/__init__.py +0 -0
  9. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/ar.py +0 -0
  10. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/de.py +0 -0
  11. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/en.py +0 -0
  12. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/es.py +0 -0
  13. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/fr.py +0 -0
  14. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/ja.py +0 -0
  15. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/ko.py +0 -0
  16. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/ru.py +0 -0
  17. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/zh.py +0 -0
  18. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
  19. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/plugin.py +0 -0
  20. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates/styles.py +0 -0
  21. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  22. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  23. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  24. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  25. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  26. {mkdocs_document_dates-1.6.0 → mkdocs_document_dates-1.8.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.6.0
3
+ Version: 1.8.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,23 @@ 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
+ log_file = Path.home() / '.mkdocs_document_dates' / 'hooks.log'
13
+ log_file.parent.mkdir(parents=True, exist_ok=True)
14
+
15
+ logging.basicConfig(
16
+ level=logging.INFO,
17
+ format='%(asctime)s - %(levelname)s - %(message)s',
18
+ handlers=[
19
+ logging.FileHandler(log_file),
20
+ logging.StreamHandler(sys.stderr) # 同时输出到stderr,方便调试
21
+ ]
22
+ )
23
+
10
24
  def find_mkdocs_projects():
11
25
  """查找当前 git 仓库中的所有 MkDocs 项目"""
12
26
  try:
@@ -54,8 +68,10 @@ def update_dates_cache():
54
68
  if not docs_dir.exists():
55
69
  continue
56
70
 
71
+ logging.info(f"Processing MkDocs project: {project_dir}")
72
+ logging.info(f"Docs directory: {docs_dir}")
73
+
57
74
  dates_cache = {}
58
- # 获取所有 markdown 文件的时间信息
59
75
  for md_file in docs_dir.rglob("*.md"):
60
76
  rel_path = str(md_file.relative_to(docs_dir))
61
77
  created, modified = get_file_dates(md_file)
@@ -63,17 +79,25 @@ def update_dates_cache():
63
79
  "created": created,
64
80
  "modified": modified
65
81
  }
82
+ logging.info(f"Processing file: {rel_path}")
66
83
 
67
- # 保存缓存文件
68
84
  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
-
85
+ logging.info(f"Saving cache to: {cache_file}")
86
+
87
+ try:
88
+ with open(cache_file, "w") as f:
89
+ json.dump(dates_cache, f, indent=2, ensure_ascii=False)
90
+ subprocess.run(["git", "add", str(cache_file)], check=True)
91
+ logging.info(f"Added cache file to git: {cache_file}")
92
+ except Exception as e:
93
+ logging.error(f"Error handling cache file: {e}")
94
+ raise
73
95
 
74
96
  if __name__ == "__main__":
75
97
  try:
98
+ logging.info("Starting pre-commit hook...")
76
99
  update_dates_cache()
100
+ logging.info("Pre-commit hook completed successfully")
77
101
  except Exception as e:
78
- print(f"Error updating dates cache: {e}", file=sys.stderr)
102
+ logging.error(f"Error in pre-commit hook: {e}")
79
103
  sys.exit(1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.6.0
3
+ Version: 1.8.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
@@ -12,33 +12,35 @@ def install_git_hooks():
12
12
  # 获取当前执行的 Python 解释器路径
13
13
  python_path = sys.executable
14
14
 
15
- # 获取包的安装路径
15
+ # 获取包的安装路径(使用 -c 参数在所有平台都有效)
16
16
  result = subprocess.check_output(
17
17
  [python_path, '-c', 'import mkdocs_document_dates; print(mkdocs_document_dates.__file__)'],
18
- text=True
18
+ text=True,
19
+ shell=True if os.name == 'nt' else False # Windows 需要 shell=True
19
20
  ).strip()
20
21
 
21
- install_dir = Path(result).parent
22
+ install_dir = Path(result).parent # Path 自动处理不同系统的路径分隔符
22
23
  hooks_dir = install_dir / 'hooks'
23
24
 
24
25
  if not hooks_dir.exists():
25
26
  print("Warning: Hooks directory not found")
26
27
  return
27
28
 
28
- # 确保 hooks 目录存在且有执行权限
29
- subprocess.run(['chmod', '-R', '755', str(hooks_dir)], check=True)
30
-
31
- # 设置全局 hooks 路径
32
- subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
33
- check=True)
34
-
35
- # 验证 hook 是否正确安装
29
+ # 跨平台设置文件权限
36
30
  hook_path = hooks_dir / 'pre-commit'
37
31
  if not hook_path.exists():
38
32
  print("Warning: pre-commit hook not found")
39
33
  return
40
34
 
41
- os.chmod(hook_path, 0o755)
35
+ # 使用 os.chmod 代替 chmod 命令
36
+ if os.name != 'nt': # 非 Windows 系统才设置权限
37
+ os.chmod(hooks_dir, 0o755)
38
+ os.chmod(hook_path, 0o755)
39
+
40
+ # 设置全局 hooks 路径(git 命令在所有平台都一样)
41
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
42
+ check=True)
43
+
42
44
  print(f"Git hooks installed successfully at: {hooks_dir}")
43
45
 
44
46
  except Exception as e:
@@ -65,7 +67,7 @@ try:
65
67
  except FileNotFoundError:
66
68
  long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
67
69
 
68
- VERSION = '1.6.0'
70
+ VERSION = '1.8.0'
69
71
 
70
72
  setup(
71
73
  name="mkdocs-document-dates",