mkdocs-document-dates 1.9.8__tar.gz → 2.0.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.8 → mkdocs_document_dates-2.0.0}/PKG-INFO +2 -2
  2. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/README.md +1 -1
  3. mkdocs_document_dates-2.0.0/mkdocs_document_dates/__init__.py +11 -0
  4. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/hooks/pre-commit +24 -11
  5. mkdocs_document_dates-2.0.0/mkdocs_document_dates/hooks_installer.py +87 -0
  6. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates.egg-info/PKG-INFO +2 -2
  7. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates.egg-info/SOURCES.txt +1 -0
  8. mkdocs_document_dates-2.0.0/mkdocs_document_dates.egg-info/entry_points.txt +5 -0
  9. mkdocs_document_dates-2.0.0/setup.py +52 -0
  10. mkdocs_document_dates-1.9.8/mkdocs_document_dates/__init__.py +0 -3
  11. mkdocs_document_dates-1.9.8/mkdocs_document_dates.egg-info/entry_points.txt +0 -2
  12. mkdocs_document_dates-1.9.8/setup.py +0 -106
  13. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/LICENSE +0 -0
  14. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/__init__.py +0 -0
  15. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/ar.py +0 -0
  16. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/de.py +0 -0
  17. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/en.py +0 -0
  18. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/es.py +0 -0
  19. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/fr.py +0 -0
  20. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/ja.py +0 -0
  21. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/ko.py +0 -0
  22. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/ru.py +0 -0
  23. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/zh.py +0 -0
  24. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
  25. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/plugin.py +0 -0
  26. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates/styles.py +0 -0
  27. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  28. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  29. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  30. {mkdocs_document_dates-1.9.8 → mkdocs_document_dates-2.0.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.8
3
+ Version: 2.0.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,11 @@
1
+ """MkDocs Document Dates Plugin."""
2
+
3
+ __version__ = '2.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}")
@@ -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"Error finding git root: {e}", file=sys.stderr)
26
27
  return []
27
28
 
28
29
  def get_file_dates(file_path):
@@ -48,28 +49,40 @@ def get_file_dates(file_path):
48
49
  return current_time.isoformat(), current_time.isoformat()
49
50
 
50
51
  def update_dates_cache():
52
+ print("开始更新文档时间缓存...")
51
53
  """更新文档时间缓存"""
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__":
@@ -0,0 +1,87 @@
1
+ import os
2
+ import sys
3
+ import subprocess
4
+ from pathlib import Path
5
+ import site
6
+ import platform
7
+
8
+ def install():
9
+ """安装 git hooks"""
10
+ try:
11
+ # 检查 git 是否可用
12
+ try:
13
+ subprocess.run(['git', '--version'], check=True, capture_output=True, encoding='utf-8')
14
+ except (subprocess.CalledProcessError, FileNotFoundError):
15
+ # 静默失败,因为用户可能在非 git 环境下安装
16
+ return False
17
+
18
+ # 检查是否在 git 仓库中
19
+ try:
20
+ subprocess.run(['git', 'rev-parse', '--git-dir'], check=True, capture_output=True, encoding='utf-8')
21
+ except subprocess.CalledProcessError:
22
+ # 静默失败,用户可能不在 git 仓库中
23
+ return False
24
+
25
+ # 检查是否是开发模式安装
26
+ def is_dev_install():
27
+ try:
28
+ import mkdocs_document_dates
29
+ pkg_path = Path(mkdocs_document_dates.__file__).resolve().parent
30
+ current_path = Path(__file__).resolve().parent
31
+ # 检查是否在开发目录中
32
+ if current_path == pkg_path:
33
+ return True
34
+ # 检查是否是 egg-link 安装
35
+ site_packages = [Path(p) for p in site.getsitepackages()]
36
+ for p in site_packages:
37
+ if (p / 'mkdocs_document_dates.egg-link').exists():
38
+ return True
39
+ return False
40
+ except (ImportError, AttributeError) as e:
41
+ print(f"开发模式检查失败: {e}")
42
+ return False
43
+
44
+ is_dev_mode = is_dev_install()
45
+ hook_path = None
46
+
47
+ if is_dev_mode:
48
+ hooks_dir = Path(__file__).parent.resolve() / 'hooks'
49
+ if hooks_dir.exists():
50
+ hook_path = hooks_dir / 'pre-commit'
51
+ else:
52
+ for site_dir in site.getsitepackages():
53
+ hooks_dir = Path(site_dir) / 'mkdocs_document_dates' / 'hooks'
54
+ if hooks_dir.exists():
55
+ hook_path = hooks_dir / 'pre-commit'
56
+ break
57
+
58
+
59
+ if not hook_path or not hook_path.exists():
60
+ print("错误: 未找到 hooks 目录或 hook 文件")
61
+ return False
62
+
63
+ # 设置文件权限(Unix-like 系统)
64
+ if platform.system() != 'Windows':
65
+ try:
66
+ os.chmod(hook_path.parent, 0o755)
67
+ os.chmod(hook_path, 0o755)
68
+ except OSError as e:
69
+ print(f"警告: 设置权限时出错: {e}")
70
+
71
+ # 配置 git hooks 路径
72
+ try:
73
+ hooks_dir = hook_path.parent
74
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath',
75
+ str(hooks_dir)], check=True, encoding='utf-8')
76
+ print(f"Git hooks 已安装到: {hooks_dir}")
77
+ return True
78
+ except subprocess.CalledProcessError as e:
79
+ print(f"错误: 设置 git hooks 路径失败: {e}")
80
+ return False
81
+
82
+ except Exception as e:
83
+ print(f"安装 hooks 时出错: {e}")
84
+ return False
85
+
86
+ if __name__ == '__main__':
87
+ install()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.9.8
3
+ Version: 2.0.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
  ...
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  mkdocs_document_dates/__init__.py
5
+ mkdocs_document_dates/hooks_installer.py
5
6
  mkdocs_document_dates/plugin.py
6
7
  mkdocs_document_dates/styles.py
7
8
  mkdocs_document_dates.egg-info/PKG-INFO
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ mkdocs-document-dates-hooks = mkdocs_document_dates.hooks_installer:install
3
+
4
+ [mkdocs.plugins]
5
+ document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin
@@ -0,0 +1,52 @@
1
+ from setuptools import setup, find_packages
2
+ from setuptools.command.install import install
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.0.0'
11
+
12
+ class PostInstallCommand(install):
13
+ """第一个入口:通过 setuptools 的 post_install 机制,在包安装完成后自动执行 hooks 安装"""
14
+ def run(self):
15
+ install.run(self)
16
+ from mkdocs_document_dates.hooks_installer import install as install_hooks # 重命名避免冲突
17
+ result = install_hooks()
18
+
19
+ setup(
20
+ name="mkdocs-document-dates",
21
+ version=VERSION,
22
+ author="Aaron Wang",
23
+ description="A MkDocs plugin for displaying accurate document creation and last modification dates.",
24
+ long_description=long_description,
25
+ long_description_content_type="text/markdown",
26
+ url="https://github.com/jaywhj/mkdocs-document-dates",
27
+ packages=find_packages(),
28
+ install_requires=[
29
+ 'mkdocs>=1.0.0',
30
+ ],
31
+ classifiers=[
32
+ "Programming Language :: Python :: 3",
33
+ "License :: OSI Approved :: MIT License",
34
+ "Operating System :: OS Independent",
35
+ ],
36
+ entry_points={
37
+ 'mkdocs.plugins': [
38
+ 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
39
+ ],
40
+ 'console_scripts': [
41
+ # 第二个入口:提供命令行工具,允许用户手动执行 hooks 安装
42
+ 'mkdocs-document-dates-hooks=mkdocs_document_dates.hooks_installer:install'
43
+ ]
44
+ },
45
+ package_data={
46
+ 'mkdocs_document_dates': ['hooks/*'],
47
+ },
48
+ python_requires=">=3.6",
49
+ cmdclass={
50
+ 'install': PostInstallCommand,
51
+ },
52
+ )
@@ -1,3 +0,0 @@
1
- """MkDocs Document Dates Plugin."""
2
-
3
- __version__ = '1.0.0'
@@ -1,2 +0,0 @@
1
- [mkdocs.plugins]
2
- document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin
@@ -1,106 +0,0 @@
1
- from setuptools import setup, find_packages
2
- from setuptools.command.install import install
3
- from setuptools.command.develop import develop
4
- from setuptools.command.build_py import build_py
5
- import os
6
- import sys
7
- import subprocess
8
- from pathlib import Path
9
-
10
- def install_git_hooks():
11
- try:
12
- print("Starting hooks installation...")
13
-
14
- # 直接使用系统 Python 路径
15
- python_path = sys.prefix
16
- hooks_dir = Path(python_path) / 'lib' / f'python{sys.version_info.major}.{sys.version_info.minor}' / 'site-packages' / 'mkdocs_document_dates' / 'hooks'
17
-
18
- print(f"Looking for hooks in: {hooks_dir}")
19
-
20
- if not hooks_dir.exists():
21
- print(f"Error: Hooks directory not found at {hooks_dir}")
22
- return
23
-
24
- hook_path = hooks_dir / 'pre-commit'
25
- if not hook_path.exists():
26
- print(f"Error: pre-commit hook not found at {hook_path}")
27
- return
28
-
29
- # 设置权限
30
- if os.name != 'nt':
31
- print(f"Setting permissions for {hooks_dir}")
32
- os.chmod(hooks_dir, 0o755)
33
- os.chmod(hook_path, 0o755)
34
-
35
- # 设置 git hooks 路径
36
- print(f"Configuring git hooks path to: {hooks_dir}")
37
- result = subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
38
- capture_output=True,
39
- text=True)
40
-
41
- if result.returncode != 0:
42
- print(f"Error setting git hooks path: {result.stderr}")
43
- return
44
-
45
- print(f"Git hooks installed successfully at: {hooks_dir}")
46
-
47
- except Exception as e:
48
- print(f"Error installing git hooks: {e}")
49
- import traceback
50
- print(traceback.format_exc())
51
-
52
- class CustomInstall(install):
53
- def run(self):
54
- install.run(self)
55
- install_git_hooks()
56
-
57
- class CustomDevelop(develop):
58
- def run(self):
59
- develop.run(self)
60
- install_git_hooks()
61
-
62
- class CustomBuildPy(build_py):
63
- def run(self):
64
- build_py.run(self)
65
- install_git_hooks()
66
-
67
- try:
68
- with open("README.md", "r", encoding="utf-8") as fh:
69
- long_description = fh.read()
70
- except FileNotFoundError:
71
- long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
72
-
73
- VERSION = '1.9.8'
74
-
75
- setup(
76
- name="mkdocs-document-dates",
77
- version=VERSION,
78
- author="Aaron Wang",
79
- description="A MkDocs plugin for displaying accurate document creation and last modification dates.",
80
- long_description=long_description,
81
- long_description_content_type="text/markdown",
82
- url="https://github.com/jaywhj/mkdocs-document-dates",
83
- packages=find_packages(),
84
- install_requires=[
85
- 'mkdocs>=1.0.0',
86
- ],
87
- classifiers=[
88
- "Programming Language :: Python :: 3",
89
- "License :: OSI Approved :: MIT License",
90
- "Operating System :: OS Independent",
91
- ],
92
- entry_points={
93
- 'mkdocs.plugins': [
94
- 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
95
- ]
96
- },
97
- cmdclass={
98
- 'install': CustomInstall,
99
- 'develop': CustomDevelop,
100
- 'build_py': CustomBuildPy,
101
- },
102
- package_data={
103
- 'mkdocs_document_dates': ['hooks/*'],
104
- },
105
- python_requires=">=3.6",
106
- )