mkdocs-document-dates 0.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.
@@ -0,0 +1,12 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Aaron Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ [... 后续 MIT 许可证内容 ...]
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.2
2
+ Name: mkdocs-document-dates
3
+ Version: 0.1.0
4
+ Summary: 一个用于显示文档创建日期和最后修改日期的 MkDocs 插件
5
+ Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
+ Author: Aaron Wang
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: mkdocs>=1.0.0
14
+ Dynamic: author
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ # mkdocs-document-dates
24
+
25
+ [English](README_en.md) | 简体中文
26
+
27
+
28
+
29
+ 一个用于显示准确的文档创建日期和最后修改日期的 MkDocs 插件。
30
+
31
+ ## 特性
32
+
33
+ - 自动显示文档的创建时间和最后修改时间
34
+ - 支持在 `Front Matter` 中手动指定日期
35
+ - 不依赖 Git,直接使用文件系统的时间戳
36
+ - 跨平台支持(Windows、macOS、Linux)
37
+ - 可配置的日期和时间格式
38
+ - 灵活的显示位置(顶部或底部)
39
+ - 支持文件排除规则
40
+ - Material Design 风格的图标
41
+ - 优雅的样式设计
42
+ - 轻量级,无额外依赖
43
+
44
+ ## 安装
45
+
46
+ ```bash
47
+ pip install mkdocs-document-dates
48
+ ```
49
+
50
+ ## 配置
51
+
52
+ 在你的 mkdocs.yml 中添加插件即可:
53
+
54
+ ```yaml
55
+ plugins:
56
+ - document-dates
57
+ ```
58
+
59
+ 或者,你要自定义配置:
60
+
61
+ ```yaml
62
+ plugins:
63
+ - document-dates:
64
+ date_format: '%Y-%m-%d' # 日期格式
65
+ show_time: false # 是否显示时间
66
+ time_format: '%H:%M:%S' # 时间格式
67
+ position: bottom # 显示位置:top(标题后)或 bottom(文档末尾)
68
+ exclude: # 排除的文件模式列表
69
+ - "private/*" # 排除 private 目录下的所有文件
70
+ - "drafts/*.md" # 排除 drafts 目录下的所有 markdown 文件
71
+ - "temp.md" # 排除特定文件
72
+ - "*.tmp" # 排除所有 .tmp 后缀的文件
73
+ ```
74
+
75
+ ## 手动指定日期
76
+
77
+ 你也可以为 Markdown 文档手动指定日期,在 Markdown 文档的 `Front Matter` 中设置:
78
+
79
+ ```yaml
80
+ ---
81
+ created_date: '2023-01-01'
82
+ modified_date: '2023-12-31'
83
+ ---
84
+
85
+ # 文档标题
86
+ ```
87
+
88
+ ## 配置选项
89
+
90
+ - date_format: 日期格式(默认:%Y-%m-%d)
91
+ - 支持所有 Python datetime 格式化字符串,例如:%Y年%m月%d日、%b %d, %Y 等
92
+ - show_time: 是否显示时间(默认:false)
93
+ - true: 同时显示日期和时间
94
+ - false: 仅显示日期
95
+ - time_format: 时间格式(默认:%H:%M:%S)
96
+ - 仅在 show_time 为 true 时生效
97
+ - position: 显示位置(默认:bottom)
98
+ - top: 在文档第一个标题后显示
99
+ - bottom: 在文档末尾显示
100
+ - exclude: 排除文件列表(默认:[])
101
+ - 支持 glob 模式,例如:["private/*", "temp.md"]
102
+
103
+ ## 注意事项
104
+
105
+ - 创建时间在不同操作系统上的行为可能不同:
106
+ - Windows: 使用文件创建时间
107
+ - macOS: 使用文件创建时间(birthtime)
108
+ - Linux: 由于系统限制,使用修改时间作为创建时间
109
+ - 如果需要准确的创建时间,建议使用 Front Matter 手动指定
110
+
@@ -0,0 +1,88 @@
1
+ # mkdocs-document-dates
2
+
3
+ [English](README_en.md) | 简体中文
4
+
5
+
6
+
7
+ 一个用于显示准确的文档创建日期和最后修改日期的 MkDocs 插件。
8
+
9
+ ## 特性
10
+
11
+ - 自动显示文档的创建时间和最后修改时间
12
+ - 支持在 `Front Matter` 中手动指定日期
13
+ - 不依赖 Git,直接使用文件系统的时间戳
14
+ - 跨平台支持(Windows、macOS、Linux)
15
+ - 可配置的日期和时间格式
16
+ - 灵活的显示位置(顶部或底部)
17
+ - 支持文件排除规则
18
+ - Material Design 风格的图标
19
+ - 优雅的样式设计
20
+ - 轻量级,无额外依赖
21
+
22
+ ## 安装
23
+
24
+ ```bash
25
+ pip install mkdocs-document-dates
26
+ ```
27
+
28
+ ## 配置
29
+
30
+ 在你的 mkdocs.yml 中添加插件即可:
31
+
32
+ ```yaml
33
+ plugins:
34
+ - document-dates
35
+ ```
36
+
37
+ 或者,你要自定义配置:
38
+
39
+ ```yaml
40
+ plugins:
41
+ - document-dates:
42
+ date_format: '%Y-%m-%d' # 日期格式
43
+ show_time: false # 是否显示时间
44
+ time_format: '%H:%M:%S' # 时间格式
45
+ position: bottom # 显示位置:top(标题后)或 bottom(文档末尾)
46
+ exclude: # 排除的文件模式列表
47
+ - "private/*" # 排除 private 目录下的所有文件
48
+ - "drafts/*.md" # 排除 drafts 目录下的所有 markdown 文件
49
+ - "temp.md" # 排除特定文件
50
+ - "*.tmp" # 排除所有 .tmp 后缀的文件
51
+ ```
52
+
53
+ ## 手动指定日期
54
+
55
+ 你也可以为 Markdown 文档手动指定日期,在 Markdown 文档的 `Front Matter` 中设置:
56
+
57
+ ```yaml
58
+ ---
59
+ created_date: '2023-01-01'
60
+ modified_date: '2023-12-31'
61
+ ---
62
+
63
+ # 文档标题
64
+ ```
65
+
66
+ ## 配置选项
67
+
68
+ - date_format: 日期格式(默认:%Y-%m-%d)
69
+ - 支持所有 Python datetime 格式化字符串,例如:%Y年%m月%d日、%b %d, %Y 等
70
+ - show_time: 是否显示时间(默认:false)
71
+ - true: 同时显示日期和时间
72
+ - false: 仅显示日期
73
+ - time_format: 时间格式(默认:%H:%M:%S)
74
+ - 仅在 show_time 为 true 时生效
75
+ - position: 显示位置(默认:bottom)
76
+ - top: 在文档第一个标题后显示
77
+ - bottom: 在文档末尾显示
78
+ - exclude: 排除文件列表(默认:[])
79
+ - 支持 glob 模式,例如:["private/*", "temp.md"]
80
+
81
+ ## 注意事项
82
+
83
+ - 创建时间在不同操作系统上的行为可能不同:
84
+ - Windows: 使用文件创建时间
85
+ - macOS: 使用文件创建时间(birthtime)
86
+ - Linux: 由于系统限制,使用修改时间作为创建时间
87
+ - 如果需要准确的创建时间,建议使用 Front Matter 手动指定
88
+
@@ -0,0 +1,3 @@
1
+ """MkDocs Document Dates Plugin."""
2
+
3
+ __version__ = '0.1.0'
@@ -0,0 +1,139 @@
1
+ import os
2
+ from datetime import datetime
3
+ from pathlib import Path
4
+ from mkdocs.plugins import BasePlugin
5
+ from mkdocs.config import config_options
6
+
7
+ class DocumentDatesPlugin(BasePlugin):
8
+ config_scheme = (
9
+ ('date_format', config_options.Type(str, default='%Y-%m-%d')),
10
+ ('show_time', config_options.Type(bool, default=False)),
11
+ ('time_format', config_options.Type(str, default='%H:%M:%S')),
12
+ ('position', config_options.Type(str, default='bottom')),
13
+ ('exclude', config_options.Type(list, default=[])),
14
+ )
15
+
16
+ def __init__(self):
17
+ super().__init__()
18
+
19
+ def get_css_content(self):
20
+ """返回插件的 CSS 样式"""
21
+ return """
22
+ .document-dates-plugin {
23
+ color: #8e8e8e;
24
+ font-size: 0.75rem;
25
+ padding: 0.2rem 0;
26
+ opacity: 0.8;
27
+ display: flex;
28
+ gap: 1.5rem;
29
+ align-items: center;
30
+ margin-bottom: 0.3rem;
31
+ }
32
+ .document-dates-plugin span {
33
+ display: inline-flex;
34
+ align-items: center;
35
+ gap: 0.3rem;
36
+ }
37
+ .document-dates-plugin .material-icons {
38
+ font-size: 0.9rem;
39
+ opacity: 0.7;
40
+ }
41
+ .document-dates-plugin-wrapper {
42
+ margin: 0.3rem 0 1rem 0;
43
+ border-bottom: 1px solid rgba(0, 0, 0, 0.07);
44
+ padding-bottom: 0.5rem;
45
+ }
46
+ """
47
+
48
+ def on_config(self, config):
49
+ """配置插件并添加必要的 CSS"""
50
+ if 'extra_css' not in config:
51
+ config['extra_css'] = []
52
+
53
+ # 添加 Material Icons
54
+ material_icons_url = 'https://fonts.googleapis.com/icon?family=Material+Icons'
55
+ if material_icons_url not in config['extra_css']:
56
+ config['extra_css'].append(material_icons_url)
57
+
58
+ # 添加自定义 CSS
59
+ css_file = Path(config['docs_dir']) / 'assets' / 'document_dates.css'
60
+ css_file.parent.mkdir(parents=True, exist_ok=True)
61
+ css_file.write_text(self.get_css_content())
62
+ config['extra_css'].append('assets/document_dates.css')
63
+
64
+ return config
65
+
66
+ def format_date_info(self, created, modified):
67
+ """格式化日期信息的 HTML"""
68
+ return (
69
+ f"\n\n"
70
+ f"<div class='document-dates-plugin-wrapper'>"
71
+ f"<div class='document-dates-plugin'>"
72
+ f"<span><span class='material-icons'>add_circle</span>"
73
+ f"{self.format_date(created)}</span>"
74
+ f"<span><span class='material-icons'>update</span>"
75
+ f"{self.format_date(modified)}</span>"
76
+ f"</div>"
77
+ f"</div>\n"
78
+ )
79
+
80
+ def insert_date_info(self, markdown, date_info):
81
+ """根据配置将日期信息插入到合适的位置"""
82
+ if self.config['position'] == 'top':
83
+ lines = markdown.split('\n')
84
+ for i, line in enumerate(lines):
85
+ if line.startswith('#'):
86
+ lines.insert(i + 1, date_info)
87
+ return '\n'.join(lines)
88
+ return date_info + markdown
89
+ return markdown + "\n\n" + date_info
90
+
91
+ def on_page_markdown(self, markdown, page, config, files):
92
+ """处理页面内容,添加日期信息"""
93
+ file_path = page.file.abs_src_path
94
+
95
+ # 检查是否在排除列表中
96
+ for exclude_pattern in self.config['exclude']:
97
+ if Path(file_path).match(exclude_pattern):
98
+ return markdown
99
+
100
+ # 直接获取日期信息
101
+ created, modified = self.get_file_dates(file_path)
102
+
103
+ # 检查 frontmatter 中的日期
104
+ meta = getattr(page, 'meta', {})
105
+ if 'created_date' in meta:
106
+ created = datetime.fromisoformat(meta['created_date'])
107
+ if 'modified_date' in meta:
108
+ modified = datetime.fromisoformat(meta['modified_date'])
109
+
110
+ # 格式化并插入日期信息
111
+ date_info = self.format_date_info(created, modified)
112
+ return self.insert_date_info(markdown, date_info)
113
+
114
+ def get_file_dates(self, file_path):
115
+ """获取文件的创建时间和修改时间"""
116
+ import platform
117
+
118
+ stat = os.stat(file_path)
119
+ modified = datetime.fromtimestamp(stat.st_mtime)
120
+
121
+ system = platform.system().lower()
122
+ if system == 'darwin': # macOS
123
+ try:
124
+ created = datetime.fromtimestamp(stat.st_birthtime)
125
+ except AttributeError:
126
+ created = datetime.fromtimestamp(stat.st_ctime)
127
+ elif system == 'windows': # Windows
128
+ created = datetime.fromtimestamp(stat.st_ctime)
129
+ else: # Linux 和其他系统
130
+ # Linux 没有可靠的创建时间,使用修改时间作为创建时间
131
+ created = modified
132
+
133
+ return created, modified
134
+
135
+ def format_date(self, date):
136
+ if self.config['show_time']:
137
+ return date.strftime(f"{self.config['date_format']} {self.config['time_format']}")
138
+ return date.strftime(self.config['date_format'])
139
+
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.2
2
+ Name: mkdocs-document-dates
3
+ Version: 0.1.0
4
+ Summary: 一个用于显示文档创建日期和最后修改日期的 MkDocs 插件
5
+ Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
+ Author: Aaron Wang
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: mkdocs>=1.0.0
14
+ Dynamic: author
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ # mkdocs-document-dates
24
+
25
+ [English](README_en.md) | 简体中文
26
+
27
+
28
+
29
+ 一个用于显示准确的文档创建日期和最后修改日期的 MkDocs 插件。
30
+
31
+ ## 特性
32
+
33
+ - 自动显示文档的创建时间和最后修改时间
34
+ - 支持在 `Front Matter` 中手动指定日期
35
+ - 不依赖 Git,直接使用文件系统的时间戳
36
+ - 跨平台支持(Windows、macOS、Linux)
37
+ - 可配置的日期和时间格式
38
+ - 灵活的显示位置(顶部或底部)
39
+ - 支持文件排除规则
40
+ - Material Design 风格的图标
41
+ - 优雅的样式设计
42
+ - 轻量级,无额外依赖
43
+
44
+ ## 安装
45
+
46
+ ```bash
47
+ pip install mkdocs-document-dates
48
+ ```
49
+
50
+ ## 配置
51
+
52
+ 在你的 mkdocs.yml 中添加插件即可:
53
+
54
+ ```yaml
55
+ plugins:
56
+ - document-dates
57
+ ```
58
+
59
+ 或者,你要自定义配置:
60
+
61
+ ```yaml
62
+ plugins:
63
+ - document-dates:
64
+ date_format: '%Y-%m-%d' # 日期格式
65
+ show_time: false # 是否显示时间
66
+ time_format: '%H:%M:%S' # 时间格式
67
+ position: bottom # 显示位置:top(标题后)或 bottom(文档末尾)
68
+ exclude: # 排除的文件模式列表
69
+ - "private/*" # 排除 private 目录下的所有文件
70
+ - "drafts/*.md" # 排除 drafts 目录下的所有 markdown 文件
71
+ - "temp.md" # 排除特定文件
72
+ - "*.tmp" # 排除所有 .tmp 后缀的文件
73
+ ```
74
+
75
+ ## 手动指定日期
76
+
77
+ 你也可以为 Markdown 文档手动指定日期,在 Markdown 文档的 `Front Matter` 中设置:
78
+
79
+ ```yaml
80
+ ---
81
+ created_date: '2023-01-01'
82
+ modified_date: '2023-12-31'
83
+ ---
84
+
85
+ # 文档标题
86
+ ```
87
+
88
+ ## 配置选项
89
+
90
+ - date_format: 日期格式(默认:%Y-%m-%d)
91
+ - 支持所有 Python datetime 格式化字符串,例如:%Y年%m月%d日、%b %d, %Y 等
92
+ - show_time: 是否显示时间(默认:false)
93
+ - true: 同时显示日期和时间
94
+ - false: 仅显示日期
95
+ - time_format: 时间格式(默认:%H:%M:%S)
96
+ - 仅在 show_time 为 true 时生效
97
+ - position: 显示位置(默认:bottom)
98
+ - top: 在文档第一个标题后显示
99
+ - bottom: 在文档末尾显示
100
+ - exclude: 排除文件列表(默认:[])
101
+ - 支持 glob 模式,例如:["private/*", "temp.md"]
102
+
103
+ ## 注意事项
104
+
105
+ - 创建时间在不同操作系统上的行为可能不同:
106
+ - Windows: 使用文件创建时间
107
+ - macOS: 使用文件创建时间(birthtime)
108
+ - Linux: 由于系统限制,使用修改时间作为创建时间
109
+ - 如果需要准确的创建时间,建议使用 Front Matter 手动指定
110
+
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ mkdocs_document_dates/__init__.py
5
+ mkdocs_document_dates/plugin.py
6
+ mkdocs_document_dates.egg-info/PKG-INFO
7
+ mkdocs_document_dates.egg-info/SOURCES.txt
8
+ mkdocs_document_dates.egg-info/dependency_links.txt
9
+ mkdocs_document_dates.egg-info/entry_points.txt
10
+ mkdocs_document_dates.egg-info/requires.txt
11
+ mkdocs_document_dates.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [mkdocs.plugins]
2
+ document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin
@@ -0,0 +1 @@
1
+ mkdocs_document_dates
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,29 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="mkdocs-document-dates",
8
+ version="0.1.0",
9
+ author="Aaron Wang",
10
+ description="一个用于显示文档创建日期和最后修改日期的 MkDocs 插件",
11
+ long_description=long_description,
12
+ long_description_content_type="text/markdown",
13
+ url="https://github.com/jaywhj/mkdocs-document-dates",
14
+ packages=find_packages(),
15
+ install_requires=[
16
+ 'mkdocs>=1.0.0',
17
+ ],
18
+ classifiers=[
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ ],
23
+ entry_points={
24
+ 'mkdocs.plugins': [
25
+ 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
26
+ ]
27
+ },
28
+ python_requires=">=3.6",
29
+ )