mkdocs-document-dates 1.2.0__py3-none-any.whl → 1.3.0__py3-none-any.whl

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.
@@ -148,26 +148,27 @@ class DocumentDatesPlugin(BasePlugin):
148
148
  def _get_file_dates(self, file_path):
149
149
  """获取文件的创建时间和修改时间"""
150
150
  try:
151
+ # 获取文件的相对路径(相对于 docs 目录)
152
+ docs_dir = Path(self.config['docs_dir'])
153
+ rel_path = str(Path(file_path).relative_to(docs_dir))
154
+
151
155
  # 尝试从缓存读取时间信息
152
- file_dir = Path(file_path).parent
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
+ ]
153
162
 
154
- # 首先尝试发布后的路径(assets/dates_cache.json)
155
- cache_file = file_dir / 'assets' / 'dates_cache.json'
156
- if not cache_file.exists():
157
- # 如果不存在,尝试开发时的路径(docs/assets/dates_cache.json)
158
- docs_dir = Path(file_path).parent.parent
159
- cache_file = docs_dir / 'assets' / 'dates_cache.json'
160
-
161
- if cache_file.exists():
162
- with open(cache_file) as f:
163
- dates_cache = json.load(f)
164
- # 获取相对于 docs 目录的路径
165
- rel_path = str(Path(file_path).name) # 只使用文件名,因为发布后目录结构已改变
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
- )
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
+ )
171
172
 
172
173
  # 如果缓存不存在或文件不在缓存中,使用文件系统时间
173
174
  stat = os.stat(file_path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.2.0
3
+ Version: 1.3.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
@@ -1,5 +1,5 @@
1
1
  mkdocs_document_dates/__init__.py,sha256=CZ37u8DC6kbkupKFk-VKyfKZZFAJ4rOD0aPzOzVoATc,58
2
- mkdocs_document_dates/plugin.py,sha256=-WNp-kn-qUjYWpEkGWpYN-1tCRyCD9GwDIxcwV1JU9k,9976
2
+ mkdocs_document_dates/plugin.py,sha256=_L4h7WYNAYWkzOLc4EAUAxpPAoO27eOc5GAMbutgGjA,9879
3
3
  mkdocs_document_dates/styles.py,sha256=ujhlKgDWsOo5sHiYtf3XekuGg4C5Yjol8RzP3W9Wzjo,578
4
4
  mkdocs_document_dates/hooks/pre-commit,sha256=gZNpQ2_l5ETAo_c1T2oOzkZ3JohSRb2CepWZg2ukqSg,3807
5
5
  mkdocs_document_dates/lang/__init__.py,sha256=M1BLjCOA3HHKeAitk45YAgzxxNpnxFUvVAk6-FO_QSA,690
@@ -13,9 +13,9 @@ mkdocs_document_dates/lang/ko.py,sha256=GwY6yrKYAOj6S6feq9yqNxr2XpyGHC0XeenO541v
13
13
  mkdocs_document_dates/lang/ru.py,sha256=fK5s4mQKCoP6KI3jf6eqqmqB3YVn39q81U7Cw1QWNNg,721
14
14
  mkdocs_document_dates/lang/zh.py,sha256=OrLElrSTZhHSwxBzuUtUj7NpQb7wm0s83viimpk2ynM,519
15
15
  mkdocs_document_dates/lang/zh_tw.py,sha256=t3qu-a7UOzgcmYDkLFiosJZCcpfMU4xiKTJfu1ZHoHA,519
16
- mkdocs_document_dates-1.2.0.dist-info/LICENSE,sha256=1YKfCs5WKSk-bON8a68WZE5to1B2klCrHBYiuaVCThM,514
17
- mkdocs_document_dates-1.2.0.dist-info/METADATA,sha256=8eHBtz_irMTHQURmEkNtOqAmjcZUHUZ7eScm49kryU8,3941
18
- mkdocs_document_dates-1.2.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
19
- mkdocs_document_dates-1.2.0.dist-info/entry_points.txt,sha256=gI-OFLGjDG6-oLEfyevl3Gwwj2GcqVFQeX3bvL1IF8o,83
20
- mkdocs_document_dates-1.2.0.dist-info/top_level.txt,sha256=yWkKQdNuAJJVqUQ9uLa5xD4x_Gux4IfOUpy8Ryagdwc,22
21
- mkdocs_document_dates-1.2.0.dist-info/RECORD,,
16
+ mkdocs_document_dates-1.3.0.dist-info/LICENSE,sha256=1YKfCs5WKSk-bON8a68WZE5to1B2klCrHBYiuaVCThM,514
17
+ mkdocs_document_dates-1.3.0.dist-info/METADATA,sha256=ZWYtaew6x56ReiQn8RYcGaqNldu-slQnA13nv47T9ek,3941
18
+ mkdocs_document_dates-1.3.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
19
+ mkdocs_document_dates-1.3.0.dist-info/entry_points.txt,sha256=gI-OFLGjDG6-oLEfyevl3Gwwj2GcqVFQeX3bvL1IF8o,83
20
+ mkdocs_document_dates-1.3.0.dist-info/top_level.txt,sha256=yWkKQdNuAJJVqUQ9uLa5xD4x_Gux4IfOUpy8Ryagdwc,22
21
+ mkdocs_document_dates-1.3.0.dist-info/RECORD,,