mkdocs-document-dates 1.3.0__tar.gz → 1.4.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.3.0 → mkdocs_document_dates-1.4.0}/PKG-INFO +4 -2
  2. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/README.md +3 -1
  3. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/hooks/pre-commit +14 -54
  4. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/plugin.py +17 -18
  5. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/PKG-INFO +4 -2
  6. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/setup.py +16 -2
  7. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/LICENSE +0 -0
  8. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/__init__.py +0 -0
  9. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/__init__.py +0 -0
  10. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ar.py +0 -0
  11. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/de.py +0 -0
  12. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/en.py +0 -0
  13. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/es.py +0 -0
  14. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/fr.py +0 -0
  15. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ja.py +0 -0
  16. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ko.py +0 -0
  17. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/ru.py +0 -0
  18. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/zh.py +0 -0
  19. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
  20. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates/styles.py +0 -0
  21. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
  22. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  23. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
  24. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  25. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  26. {mkdocs_document_dates-1.3.0 → mkdocs_document_dates-1.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.3.0
3
+ Version: 1.4.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
@@ -112,8 +112,10 @@ modified: 2023-12-31
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
114
  - Used a cache file `dates_cache.json` to solve this problem
115
- - You can configure it like this: `pip install --upgrade mkdocs-document-dates` or `pip install mkdocs-document-dates==1.2.0`
115
+ - You can configure it like this: `pip install --upgrade mkdocs-document-dates`
116
116
  ```
117
+ ...
118
+
117
119
  - run: pip install --upgrade mkdocs-document-dates
118
120
  - run: mkdocs gh-deploy --force
119
121
  ```
@@ -90,8 +90,10 @@ modified: 2023-12-31
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
92
  - Used a cache file `dates_cache.json` to solve this problem
93
- - You can configure it like this: `pip install --upgrade mkdocs-document-dates` or `pip install mkdocs-document-dates==1.2.0`
93
+ - You can configure it like this: `pip install --upgrade mkdocs-document-dates`
94
94
  ```
95
+ ...
96
+
95
97
  - run: pip install --upgrade mkdocs-document-dates
96
98
  - run: mkdocs gh-deploy --force
97
99
  ```
@@ -4,7 +4,6 @@ import sys
4
4
  import json
5
5
  import platform
6
6
  import subprocess
7
- import traceback
8
7
  from datetime import datetime
9
8
  from pathlib import Path
10
9
 
@@ -47,73 +46,34 @@ def get_file_dates(file_path):
47
46
  current_time = datetime.now()
48
47
  return current_time.isoformat(), current_time.isoformat()
49
48
 
49
+
50
50
  def update_dates_cache():
51
51
  """更新文档时间缓存"""
52
- projects = find_mkdocs_projects()
53
- if not projects:
54
- print("No MkDocs projects found")
55
- return
56
-
57
- for project_dir in projects:
52
+ for project_dir in find_mkdocs_projects():
58
53
  docs_dir = project_dir / 'docs'
59
54
  if not docs_dir.exists():
60
55
  continue
61
-
62
- # 检查 assets 目录
63
- assets_dir = docs_dir / 'assets'
64
- if not assets_dir.exists():
65
- assets_dir.mkdir(parents=True)
66
-
67
- cache_file = assets_dir / 'dates_cache.json'
68
- dates_cache = _load_cache(cache_file)
69
-
70
- _update_cache(docs_dir, dates_cache)
71
- _save_cache(cache_file, dates_cache)
72
56
 
73
- def _load_cache(cache_file):
74
- """加载缓存文件"""
75
- if cache_file.exists():
76
- try:
77
- with open(cache_file) as f:
78
- return json.load(f)
79
- except json.JSONDecodeError:
80
- pass
81
- return {}
82
-
83
- def _update_cache(docs_dir, dates_cache):
84
- """更新缓存内容"""
85
- # 记录当前所有的 markdown 文件
86
- current_files = set()
87
-
88
- # 处理新增和更新的文件
89
- for md_file in docs_dir.rglob("*.md"):
90
- rel_path = str(md_file.relative_to(docs_dir))
91
- current_files.add(rel_path)
92
-
93
- # 文件不在缓存中(新增)或文件修改时间变化(更新)
94
- if rel_path not in dates_cache or os.path.getmtime(md_file) != dates_cache[rel_path].get("mtime", 0):
57
+ dates_cache = {}
58
+ # 获取所有 markdown 文件的时间信息
59
+ for md_file in docs_dir.rglob("*.md"):
60
+ rel_path = str(md_file.relative_to(docs_dir))
95
61
  created, modified = get_file_dates(md_file)
96
62
  dates_cache[rel_path] = {
97
63
  "created": created,
98
- "modified": modified,
99
- "mtime": os.path.getmtime(md_file)
64
+ "modified": modified
100
65
  }
101
-
102
- # 处理删除的文件
103
- for cached_path in list(dates_cache.keys()):
104
- if cached_path not in current_files:
105
- del dates_cache[cached_path]
106
66
 
107
- def _save_cache(cache_file, dates_cache):
108
- """保存缓存文件"""
109
- with open(cache_file, "w") as f:
110
- json.dump(dates_cache, f, indent=2, ensure_ascii=False)
111
- subprocess.run(["git", "add", str(cache_file)], check=True)
67
+ # 保存缓存文件
68
+ 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
+
112
73
 
113
- # 添加主入口
114
74
  if __name__ == "__main__":
115
75
  try:
116
76
  update_dates_cache()
117
77
  except Exception as e:
118
- traceback.print_exc()
78
+ print(f"Error updating dates cache: {e}", file=sys.stderr)
119
79
  sys.exit(1)
@@ -84,10 +84,16 @@ class DocumentDatesPlugin(BasePlugin):
84
84
  if self._is_excluded(file_path, Path(config['docs_dir'])):
85
85
  return markdown
86
86
 
87
+ # 获取文件时间
87
88
  created, modified = self._get_file_dates(file_path)
89
+
90
+ # 处理 front matter 中的时间
88
91
  created, modified = self._process_meta_dates(page.meta, created, modified)
89
92
 
93
+ # 生成日期信息 HTML
90
94
  date_info = self._get_date_info(created, modified)
95
+
96
+ # 将日期信息写入 markdown
91
97
  return self._insert_date_info(markdown, date_info)
92
98
 
93
99
  def _is_excluded(self, file_path: Path, docs_dir: Path) -> bool:
@@ -152,23 +158,16 @@ class DocumentDatesPlugin(BasePlugin):
152
158
  docs_dir = Path(self.config['docs_dir'])
153
159
  rel_path = str(Path(file_path).relative_to(docs_dir))
154
160
 
155
- # 尝试从缓存读取时间信息
156
- cache_paths = [
157
- # 部署环境路径(gh-pages)
158
- Path(file_path).parent / 'assets' / 'dates_cache.json',
159
- # 开发环境路径(main)
160
- docs_dir / 'assets' / 'dates_cache.json'
161
- ]
162
-
163
- for cache_file in cache_paths:
164
- if cache_file.exists():
165
- with open(cache_file) as f:
166
- dates_cache = json.load(f)
167
- if rel_path in dates_cache:
168
- return (
169
- datetime.fromisoformat(dates_cache[rel_path]['created']),
170
- datetime.fromisoformat(dates_cache[rel_path]['modified'])
171
- )
161
+ # 尝试从缓存文件读取时间信息
162
+ cache_file = docs_dir / '.dates_cache.json'
163
+ if cache_file.exists():
164
+ with open(cache_file) as f:
165
+ dates_cache = json.load(f)
166
+ if rel_path in dates_cache:
167
+ return (
168
+ datetime.fromisoformat(dates_cache[rel_path]['created']),
169
+ datetime.fromisoformat(dates_cache[rel_path]['modified'])
170
+ )
172
171
 
173
172
  # 如果缓存不存在或文件不在缓存中,使用文件系统时间
174
173
  stat = os.stat(file_path)
@@ -186,7 +185,7 @@ class DocumentDatesPlugin(BasePlugin):
186
185
  created = modified
187
186
 
188
187
  return created, modified
189
-
188
+
190
189
  except (OSError, ValueError, json.JSONDecodeError) as e:
191
190
  current_time = datetime.now()
192
191
  return current_time, current_time
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.3.0
3
+ Version: 1.4.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
@@ -112,8 +112,10 @@ modified: 2023-12-31
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
114
  - Used a cache file `dates_cache.json` to solve this problem
115
- - You can configure it like this: `pip install --upgrade mkdocs-document-dates` or `pip install mkdocs-document-dates==1.2.0`
115
+ - You can configure it like this: `pip install --upgrade mkdocs-document-dates`
116
116
  ```
117
+ ...
118
+
117
119
  - run: pip install --upgrade mkdocs-document-dates
118
120
  - run: mkdocs gh-deploy --force
119
121
  ```
@@ -1,4 +1,6 @@
1
1
  from setuptools import setup, find_packages
2
+ from setuptools.command.install import install
3
+ from setuptools.command.develop import develop
2
4
  from setuptools.command.build_py import build_py
3
5
  import os
4
6
  import subprocess
@@ -32,6 +34,16 @@ def install_git_hooks():
32
34
  except Exception as e:
33
35
  print(f"Warning: Failed to install git hooks: {e}")
34
36
 
37
+ class CustomInstall(install):
38
+ def run(self):
39
+ install.run(self)
40
+ install_git_hooks()
41
+
42
+ class CustomDevelop(develop):
43
+ def run(self):
44
+ develop.run(self)
45
+ install_git_hooks()
46
+
35
47
  class CustomBuildPy(build_py):
36
48
  def run(self):
37
49
  build_py.run(self)
@@ -43,7 +55,7 @@ try:
43
55
  except FileNotFoundError:
44
56
  long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
45
57
 
46
- VERSION = '1.3.0'
58
+ VERSION = '1.4.0'
47
59
 
48
60
  setup(
49
61
  name="mkdocs-document-dates",
@@ -68,7 +80,9 @@ setup(
68
80
  ]
69
81
  },
70
82
  cmdclass={
71
- 'build_py': CustomBuildPy, # 在构建时安装 hooks,无论是正式安装还是开发模式安装,都会经过构建阶段
83
+ 'build_py': CustomBuildPy,
84
+ 'install': CustomInstall,
85
+ 'develop': CustomDevelop,
72
86
  },
73
87
  package_data={
74
88
  'mkdocs_document_dates': ['hooks/*'],