mkdocs-document-dates 1.9.9__tar.gz → 2.1.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 (30) hide show
  1. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/PKG-INFO +2 -2
  2. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/README.md +1 -1
  3. mkdocs_document_dates-2.1.0/mkdocs_document_dates/__init__.py +13 -0
  4. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/hooks/pre-commit +28 -15
  5. mkdocs_document_dates-2.1.0/mkdocs_document_dates/hooks_installer.py +77 -0
  6. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/PKG-INFO +2 -2
  7. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/entry_points.txt +1 -1
  8. mkdocs_document_dates-2.1.0/setup.py +42 -0
  9. mkdocs_document_dates-1.9.9/mkdocs_document_dates/__init__.py +0 -11
  10. mkdocs_document_dates-1.9.9/mkdocs_document_dates/hooks_installer.py +0 -49
  11. mkdocs_document_dates-1.9.9/setup.py +0 -129
  12. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/LICENSE +0 -0
  13. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/__init__.py +0 -0
  14. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ar.py +0 -0
  15. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/de.py +0 -0
  16. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/en.py +0 -0
  17. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/es.py +0 -0
  18. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/fr.py +0 -0
  19. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ja.py +0 -0
  20. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ko.py +0 -0
  21. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ru.py +0 -0
  22. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/zh.py +0 -0
  23. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
  24. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/plugin.py +0 -0
  25. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/styles.py +0 -0
  26. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  27. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  28. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  29. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  30. {mkdocs_document_dates-1.9.9 → mkdocs_document_dates-2.1.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.9.9
3
+ Version: 2.1.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
@@ -111,7 +111,7 @@ modified: 2023-12-31
111
111
  - macOS: Uses file creation time (birthtime)
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
- - Used a cache file `dates_cache.json` to solve this problem
114
+ - Used a cache file `.dates_cache.json` to solve this problem
115
115
  - You can configure it like this: `pip install --upgrade mkdocs-document-dates`
116
116
  ```
117
117
  ...
@@ -89,7 +89,7 @@ modified: 2023-12-31
89
89
  - macOS: Uses file creation time (birthtime)
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
- - Used a cache file `dates_cache.json` to solve this problem
92
+ - Used a cache file `.dates_cache.json` to solve this problem
93
93
  - You can configure it like this: `pip install --upgrade mkdocs-document-dates`
94
94
  ```
95
95
  ...
@@ -0,0 +1,13 @@
1
+ """MkDocs Document Dates Plugin."""
2
+
3
+ __version__ = '2.0.0'
4
+
5
+ from .hooks_installer import install
6
+
7
+ # 在包被导入时自动执行 hooks 安装
8
+ try:
9
+ result = install()
10
+ if not result:
11
+ print("提示: Git hooks 安装被跳过(可能是因为未检测到 Git 或不在 Git 仓库中)")
12
+ except Exception as e:
13
+ print(f"警告: Git hooks 安装失败: {e}")
@@ -13,16 +13,17 @@ def find_mkdocs_projects():
13
13
  try:
14
14
  git_root = Path(subprocess.check_output(
15
15
  ['git', 'rev-parse', '--show-toplevel'],
16
- text=True
16
+ text=True, encoding='utf-8'
17
17
  ).strip())
18
18
 
19
19
  projects = []
20
20
  for config_file in git_root.rglob('mkdocs.y*ml'):
21
- if config_file.name in ('mkdocs.yml', 'mkdocs.yaml'):
21
+ if config_file.name.lower() in ('mkdocs.yml', 'mkdocs.yaml'):
22
22
  projects.append(config_file.parent)
23
+
23
24
  return projects
24
25
  except subprocess.CalledProcessError as e:
25
- print(f"Error finding git root: {e}")
26
+ print(f"查找 Git 仓库根目录失败: {e}", file=sys.stderr)
26
27
  return []
27
28
 
28
29
  def get_file_dates(file_path):
@@ -32,13 +33,13 @@ def get_file_dates(file_path):
32
33
  modified = datetime.fromtimestamp(stat.st_mtime)
33
34
 
34
35
  system = platform.system().lower()
35
- if system == 'darwin': # macOS
36
+ if system.startswith('win'): # Windows
37
+ created = datetime.fromtimestamp(stat.st_ctime)
38
+ elif system == 'darwin': # macOS
36
39
  try:
37
40
  created = datetime.fromtimestamp(stat.st_birthtime)
38
41
  except AttributeError:
39
42
  created = datetime.fromtimestamp(stat.st_ctime)
40
- elif system == 'windows': # Windows
41
- created = datetime.fromtimestamp(stat.st_ctime)
42
43
  else: # Linux 和其他系统
43
44
  created = modified
44
45
 
@@ -49,32 +50,44 @@ def get_file_dates(file_path):
49
50
 
50
51
  def update_dates_cache():
51
52
  """更新文档时间缓存"""
53
+ print("开始更新文档时间缓存...")
52
54
  for project_dir in find_mkdocs_projects():
53
55
  docs_dir = project_dir / 'docs'
54
56
  if not docs_dir.exists():
57
+ print(f"文档目录不存在: {docs_dir}")
55
58
  continue
56
59
 
57
60
  dates_cache = {}
58
- for md_file in docs_dir.rglob("*.md"):
59
- rel_path = str(md_file.relative_to(docs_dir))
60
- created, modified = get_file_dates(md_file)
61
- dates_cache[rel_path] = {
62
- "created": created,
63
- "modified": modified
64
- }
61
+ md_files = list(docs_dir.rglob("*.md"))
62
+
63
+ for md_file in md_files:
64
+ try:
65
+ rel_path = str(md_file.relative_to(docs_dir))
66
+ created, modified = get_file_dates(md_file)
67
+ dates_cache[rel_path] = {
68
+ "created": created,
69
+ "modified": modified
70
+ }
71
+ except Exception as e:
72
+ print(f"处理文件 {md_file} 时出错: {e}")
73
+
74
+ if not dates_cache:
75
+ continue
65
76
 
66
77
  cache_file = docs_dir / '.dates_cache.json'
78
+ print(f"正在写入缓存文件: {cache_file}")
67
79
  try:
68
80
  with open(cache_file, "w") as f:
69
81
  json.dump(dates_cache, f, indent=2, ensure_ascii=False)
70
82
  subprocess.run(["git", "add", str(cache_file)], check=True)
83
+ print(f"缓存文件 {cache_file} 已更新.")
71
84
  except Exception as e:
72
- print(f"Error handling cache file: {e}", file=sys.stderr)
85
+ print(f"写入缓存文件时出错: {e}", file=sys.stderr)
73
86
  raise
74
87
 
75
88
  if __name__ == "__main__":
76
89
  try:
77
90
  update_dates_cache()
78
91
  except Exception as e:
79
- print(f"Hook error: {e}", file=sys.stderr)
92
+ print(f"Hook 执行出错: {e}", file=sys.stderr)
80
93
  sys.exit(1)
@@ -0,0 +1,77 @@
1
+ import os
2
+ import sys
3
+ import shutil
4
+ import subprocess
5
+ from pathlib import Path
6
+ import platform
7
+
8
+ def get_config_dir():
9
+ """获取用户配置目录"""
10
+ system = platform.system().lower()
11
+ if system.startswith('win'):
12
+ return Path(os.getenv('APPDATA', str(Path.home() / 'AppData' / 'Roaming')))
13
+ else: # macOS 和 Linux 统一使用 ~/.config
14
+ return Path.home() / '.config'
15
+
16
+ def install():
17
+ """安装 git hooks"""
18
+ try:
19
+ # 检查 git 是否可用
20
+ try:
21
+ subprocess.run(['git', '--version'], check=True, capture_output=True, encoding='utf-8')
22
+ except (subprocess.CalledProcessError, FileNotFoundError):
23
+ print("提示: 未检测到 Git,跳过 hooks 安装")
24
+ return False
25
+
26
+ # 准备配置目录
27
+ config_dir = get_config_dir() / 'mkdocs-document-dates' / 'hooks'
28
+ try:
29
+ config_dir.mkdir(parents=True, exist_ok=True)
30
+ except PermissionError:
31
+ print(f"错误: 无权限创建目录: {config_dir}")
32
+ return False
33
+ except Exception as e:
34
+ print(f"错误: 创建目录失败: {config_dir}, 原因: {e}")
35
+ return False
36
+
37
+ hook_path = config_dir / 'pre-commit'
38
+
39
+ # 复制 hook 文件
40
+ source_hook = Path(__file__).parent / 'hooks' / 'pre-commit'
41
+ if not source_hook.exists():
42
+ print(f"错误: 源 hook 文件不存在: {source_hook}")
43
+ return False
44
+
45
+ try:
46
+ shutil.copy2(source_hook, hook_path)
47
+ except PermissionError:
48
+ print(f"错误: 无权限复制文件到: {hook_path}")
49
+ return False
50
+ except Exception as e:
51
+ print(f"错误: 复制文件失败, 原因: {e}")
52
+ return False
53
+
54
+ # 设置文件权限(Unix-like 系统)
55
+ if not platform.system().lower().startswith('win'):
56
+ try:
57
+ os.chmod(config_dir, 0o755)
58
+ os.chmod(hook_path, 0o755)
59
+ except OSError as e:
60
+ print(f"警告: 设置权限时出错: {e}")
61
+
62
+ # 配置 git hooks 路径
63
+ try:
64
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath',
65
+ str(config_dir)], check=True, encoding='utf-8')
66
+ print(f"Git hooks 已安装到: {config_dir}")
67
+ return True
68
+ except subprocess.CalledProcessError as e:
69
+ print(f"错误: 设置 git hooks 路径失败: {e}")
70
+ return False
71
+
72
+ except Exception as e:
73
+ print(f"安装 hooks 时出错: {e}")
74
+ return False
75
+
76
+ if __name__ == '__main__':
77
+ install()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.9.9
3
+ Version: 2.1.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
@@ -111,7 +111,7 @@ modified: 2023-12-31
111
111
  - macOS: Uses file creation time (birthtime)
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
- - Used a cache file `dates_cache.json` to solve this problem
114
+ - Used a cache file `.dates_cache.json` to solve this problem
115
115
  - You can configure it like this: `pip install --upgrade mkdocs-document-dates`
116
116
  ```
117
117
  ...
@@ -1,5 +1,5 @@
1
1
  [console_scripts]
2
- install-mkdocs-hooks = mkdocs_document_dates.hooks_installer:install
2
+ mkdocs-document-dates-hooks = mkdocs_document_dates.hooks_installer:install
3
3
 
4
4
  [mkdocs.plugins]
5
5
  document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin
@@ -0,0 +1,42 @@
1
+ from setuptools import setup, find_packages
2
+ import mkdocs_document_dates
3
+
4
+ try:
5
+ with open("README.md", "r", encoding="utf-8") as fh:
6
+ long_description = fh.read()
7
+ except FileNotFoundError:
8
+ long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
9
+
10
+ VERSION = '2.1.0'
11
+
12
+ setup(
13
+ name="mkdocs-document-dates",
14
+ version=VERSION,
15
+ author="Aaron Wang",
16
+ description="A MkDocs plugin for displaying accurate document creation and last modification dates.",
17
+ long_description=long_description,
18
+ long_description_content_type="text/markdown",
19
+ url="https://github.com/jaywhj/mkdocs-document-dates",
20
+ packages=find_packages(),
21
+ install_requires=[
22
+ 'mkdocs>=1.0.0',
23
+ ],
24
+ classifiers=[
25
+ "Programming Language :: Python :: 3",
26
+ "License :: OSI Approved :: MIT License",
27
+ "Operating System :: OS Independent",
28
+ ],
29
+ entry_points={
30
+ 'mkdocs.plugins': [
31
+ 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
32
+ ],
33
+ 'console_scripts': [
34
+ # 提供命令行工具,允许用户手动执行 hooks 安装
35
+ 'mkdocs-document-dates-hooks=mkdocs_document_dates.hooks_installer:install'
36
+ ],
37
+ },
38
+ package_data={
39
+ 'mkdocs_document_dates': ['hooks/*'],
40
+ },
41
+ python_requires=">=3.6",
42
+ )
@@ -1,11 +0,0 @@
1
- """MkDocs Document Dates Plugin."""
2
-
3
- __version__ = '1.0.0'
4
-
5
- from .hooks_installer import install
6
-
7
- # 当包被导入时自动安装 hooks
8
- try:
9
- install()
10
- except Exception as e:
11
- print(f"自动安装 git hooks 失败: {e}")
@@ -1,49 +0,0 @@
1
- import os
2
- import sys
3
- import subprocess
4
- from pathlib import Path
5
- import site
6
-
7
- def install():
8
- """安装 git hooks 的入口点函数"""
9
- print("\n正在安装 git hooks...\n")
10
- try:
11
- # 先清除旧的配置
12
- subprocess.run(['git', 'config', '--global', '--unset', 'core.hooksPath'],
13
- check=False)
14
-
15
- # 优先使用开发目录
16
- dev_hooks_dir = Path(__file__).parent.resolve() / 'hooks'
17
- if dev_hooks_dir.exists():
18
- hook_path = dev_hooks_dir / 'pre-commit'
19
- if hook_path.exists():
20
- if os.name != 'nt':
21
- os.chmod(dev_hooks_dir, 0o755)
22
- os.chmod(hook_path, 0o755)
23
- subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(dev_hooks_dir)],
24
- check=True)
25
- print(f"Hooks 已安装到 (开发模式): {dev_hooks_dir}")
26
- return True
27
-
28
- # 如果开发目录不存在,再尝试 site-packages
29
- for site_dir in site.getsitepackages():
30
- hooks_dir = Path(site_dir) / 'mkdocs_document_dates' / 'hooks'
31
- if hooks_dir.exists():
32
- hook_path = hooks_dir / 'pre-commit'
33
- if hook_path.exists():
34
- if os.name != 'nt':
35
- os.chmod(hooks_dir, 0o755)
36
- os.chmod(hook_path, 0o755)
37
- subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
38
- check=True)
39
- print(f"Hooks 已安装到: {hooks_dir}")
40
- return True
41
-
42
- print("错误: 未找到 hooks 目录")
43
- return False
44
- except Exception as e:
45
- print(f"安装 hooks 时出错: {e}")
46
- return False
47
-
48
- if __name__ == '__main__':
49
- install()
@@ -1,129 +0,0 @@
1
- from setuptools import setup, find_packages
2
- from setuptools.command.install_egg_info import install_egg_info
3
- from setuptools.command.develop import develop
4
- from setuptools.command.install import install
5
- from setuptools.command.build_py import build_py
6
- import os
7
- import sys
8
- import subprocess
9
- from pathlib import Path
10
- import site
11
-
12
- def install_git_hooks():
13
- print("\n...Starting hooks installation...\n")
14
- try:
15
- # 先清除旧的配置
16
- subprocess.run(['git', 'config', '--global', '--unset', 'core.hooksPath'],
17
- check=False)
18
-
19
- # 使用 site-packages 路径
20
- for site_dir in site.getsitepackages():
21
- hooks_dir = Path(site_dir) / 'mkdocs_document_dates' / 'hooks'
22
- print(f"Checking hooks in: {hooks_dir}")
23
- if hooks_dir.exists():
24
- hook_path = hooks_dir / 'pre-commit'
25
- if hook_path.exists():
26
- if os.name != 'nt':
27
- os.chmod(hooks_dir, 0o755)
28
- os.chmod(hook_path, 0o755)
29
- subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
30
- check=True)
31
- print(f"Hooks installed at: {hooks_dir}")
32
-
33
- # 验证配置
34
- result = subprocess.run(['git', 'config', '--global', 'core.hooksPath'],
35
- capture_output=True, text=True)
36
- print(f"Verified hooks path: {result.stdout.strip()}")
37
- return True
38
-
39
- # 如果在 site-packages 中没找到,尝试开发目录
40
- dev_hooks_dir = Path(__file__).parent.resolve() / 'mkdocs_document_dates' / 'hooks'
41
- if dev_hooks_dir.exists():
42
- hook_path = dev_hooks_dir / 'pre-commit'
43
- if hook_path.exists():
44
- if os.name != 'nt':
45
- os.chmod(dev_hooks_dir, 0o755)
46
- os.chmod(hook_path, 0o755)
47
- subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(dev_hooks_dir)],
48
- check=True)
49
- print(f"Hooks installed at (dev mode): {dev_hooks_dir}")
50
- return True
51
-
52
- print("Error: Hooks directory not found in any location")
53
- return False
54
- except Exception as e:
55
- print(f"Error installing hooks: {e}")
56
- return False
57
-
58
- class CustomInstallEggInfo(install_egg_info):
59
-
60
- def run(self):
61
- print("\n=== Starting CustomInstallEggInfo run ===\n")
62
- print(f"Installation mode: {'Development' if '-e' in sys.argv else 'Production'}")
63
- print(f"Current directory: {os.getcwd()}")
64
- print(f"Setup file location: {__file__}")
65
- print(f"Command line args: {sys.argv}")
66
-
67
- install_egg_info.run(self)
68
- install_git_hooks()
69
-
70
- class CustomInstall(install):
71
- def run(self):
72
- print("\n=== Starting CustomInstall run ===\n")
73
- print(f"Current directory: {os.getcwd()}")
74
- install.run(self)
75
- install_git_hooks()
76
-
77
- class CustomDevelop(develop):
78
- def run(self):
79
- print("\n=== Starting CustomDevelop run ===\n")
80
- develop.run(self)
81
- install_git_hooks()
82
-
83
- class CustomBuildPy(build_py):
84
- def run(self):
85
- print("\n=== Starting CustomBuildPy run ===\n")
86
- print(f"Current directory: {os.getcwd()}")
87
- print(f"Build lib dir: {self.build_lib}")
88
- build_py.run(self)
89
- install_git_hooks()
90
-
91
- try:
92
- with open("README.md", "r", encoding="utf-8") as fh:
93
- long_description = fh.read()
94
- except FileNotFoundError:
95
- long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
96
-
97
- VERSION = '1.9.9'
98
-
99
- setup(
100
- name="mkdocs-document-dates",
101
- version=VERSION,
102
- author="Aaron Wang",
103
- description="A MkDocs plugin for displaying accurate document creation and last modification dates.",
104
- long_description=long_description,
105
- long_description_content_type="text/markdown",
106
- url="https://github.com/jaywhj/mkdocs-document-dates",
107
- packages=find_packages(),
108
- install_requires=[
109
- 'mkdocs>=1.0.0',
110
- ],
111
- classifiers=[
112
- "Programming Language :: Python :: 3",
113
- "License :: OSI Approved :: MIT License",
114
- "Operating System :: OS Independent",
115
- ],
116
- entry_points={
117
- 'mkdocs.plugins': [
118
- 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
119
- ],
120
- 'console_scripts': [
121
- 'install-mkdocs-hooks=mkdocs_document_dates.hooks_installer:install'
122
- ]
123
- },
124
-
125
- package_data={
126
- 'mkdocs_document_dates': ['hooks/*'],
127
- },
128
- python_requires=">=3.6",
129
- )