mkdocs-document-dates 3.6.1__tar.gz → 3.7.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.
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/LICENSE +1 -1
- mkdocs_document_dates-3.7.0/MANIFEST.in +9 -0
- {mkdocs_document_dates-3.6.1/mkdocs_document_dates.egg-info → mkdocs_document_dates-3.7.0}/PKG-INFO +17 -26
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/README.md +11 -11
- mkdocs_document_dates-3.7.0/mkdocs_document_dates/__init__.py +1 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/cache_manager.py +85 -5
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/hooks/pre-commit +1 -1
- mkdocs_document_dates-3.7.0/mkdocs_document_dates/hooks_installer.py +98 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/plugin.py +30 -7
- mkdocs_document_dates-3.7.0/mkdocs_document_dates/static/.DS_Store +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/templates/recently_updated_group.html +6 -5
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/utils.py +1 -1
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0/mkdocs_document_dates.egg-info}/PKG-INFO +17 -26
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates.egg-info/SOURCES.txt +1 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates.egg-info/entry_points.txt +1 -0
- mkdocs_document_dates-3.7.0/pyproject.toml +48 -0
- mkdocs_document_dates-3.7.0/setup.py +50 -0
- mkdocs_document_dates-3.6.1/MANIFEST.in +0 -2
- mkdocs_document_dates-3.6.1/mkdocs_document_dates/__init__.py +0 -6
- mkdocs_document_dates-3.6.1/mkdocs_document_dates/hooks_installer.py +0 -120
- mkdocs_document_dates-3.6.1/pyproject.toml +0 -4
- mkdocs_document_dates-3.6.1/setup.py +0 -69
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/config/user.config.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/config/user.config.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/core.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/core.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/default.config.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/md5.min.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/timeago.full.min.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/timeago.min.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/core/utils.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/fonts/material-icons.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/fonts/materialicons.woff2 +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/templates/recently_updated_detail.html +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/templates/recently_updated_grid.html +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/templates/recently_updated_list.html +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/backdrop.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/light.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/material.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/popper.min.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/scale.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/shift-away.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/tippy.css +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/static/tippy/tippy.umd.min.js +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
- {mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/setup.cfg +0 -0
{mkdocs_document_dates-3.6.1/mkdocs_document_dates.egg-info → mkdocs_document_dates-3.7.0}/PKG-INFO
RENAMED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-document-dates
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.0
|
|
4
4
|
Summary: A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Author-email: Aaron Wang <aaronwqt@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jaywhj/mkdocs-document-dates
|
|
8
|
+
Project-URL: Repository, https://github.com/jaywhj/mkdocs-document-dates
|
|
9
|
+
Project-URL: Documentation, https://jaywhj.netlify.app/document-dates-en
|
|
9
10
|
Classifier: Programming Language :: Python :: 3
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
11
12
|
Requires-Python: >=3.7
|
|
12
13
|
Description-Content-Type: text/markdown
|
|
13
14
|
License-File: LICENSE
|
|
14
15
|
Requires-Dist: mkdocs>=1.1.0
|
|
15
|
-
Dynamic: author
|
|
16
|
-
Dynamic: author-email
|
|
17
|
-
Dynamic: classifier
|
|
18
|
-
Dynamic: description
|
|
19
|
-
Dynamic: description-content-type
|
|
20
|
-
Dynamic: home-page
|
|
21
|
-
Dynamic: license
|
|
22
16
|
Dynamic: license-file
|
|
23
|
-
Dynamic: requires-dist
|
|
24
|
-
Dynamic: requires-python
|
|
25
|
-
Dynamic: summary
|
|
26
17
|
|
|
27
18
|
# mkdocs-document-dates
|
|
28
19
|
|
|
@@ -36,7 +27,7 @@ A new generation MkDocs plugin for displaying exact **creation date, last update
|
|
|
36
27
|
|
|
37
28
|
## Features
|
|
38
29
|
|
|
39
|
-
- [x]
|
|
30
|
+
- [x] Works in any environment: no-Git, Git environments, Docker, all CI/CD build systems, etc.
|
|
40
31
|
- [x] Support list display of recently updated documents (in descending order of update date)
|
|
41
32
|
- [x] Support for manually specifying date and author in `Front Matter`
|
|
42
33
|
- [x] Support for multiple date formats (date, datetime, timeago)
|
|
@@ -74,23 +65,23 @@ plugins:
|
|
|
74
65
|
- document-dates:
|
|
75
66
|
position: top # Display position: top(after title) bottom(end of document), default: top
|
|
76
67
|
type: date # Date type: date datetime timeago, default: date
|
|
77
|
-
exclude: # List of excluded files
|
|
68
|
+
exclude: # List of excluded files (support unix shell-style wildcards)
|
|
78
69
|
- temp.md # Example: exclude the specified file
|
|
79
70
|
- blog/* # Example: exclude all files in blog folder, including subfolders
|
|
71
|
+
- '*/index.md' # Example: exclude all index.md files in any subfolders
|
|
80
72
|
```
|
|
81
73
|
|
|
82
74
|
## Customization Settings
|
|
83
75
|
|
|
84
76
|
In addition to the above basic configuration, the plug-in also provides a wealth of customization options to meet a variety of individual needs:
|
|
85
77
|
|
|
86
|
-
- [
|
|
87
|
-
- [
|
|
88
|
-
- [
|
|
89
|
-
- [
|
|
90
|
-
- [
|
|
91
|
-
- [
|
|
92
|
-
- [
|
|
93
|
-
- [Other Tips](https://jaywhj.netlify.app/document-dates-en#Other-Tips): Introducing the Do's of using plugin in Docker
|
|
78
|
+
- [Date & Time](https://jaywhj.netlify.app/document-dates-en#Date--Time): Introduces the mechanism for obtaining document dates and methods for personalized customization, support for manually specifying the creation date and last updated date for each document
|
|
79
|
+
- [Author](https://jaywhj.netlify.app/document-dates-en#Author): Introduces the mechanism for obtaining document authors and methods for personalized customization, support for manually specifying the author information for each document, such as name, link, avatar, email, etc.
|
|
80
|
+
- [Avatar](https://jaywhj.netlify.app/document-dates-en#Avatar): You can manually specify the avatar for each author, support local file path and URL path
|
|
81
|
+
- [Structure and Style](https://jaywhj.netlify.app/document-dates-en#Structure-and-Style): You can freely configure the plugin's display structure in mkdocs.yml or Front Matter. You can quickly set the plugin styles through preset entrances, such as icons, themes, colors, fonts, animations, dividing line and so on
|
|
82
|
+
- [Template Variables](https://jaywhj.netlify.app/document-dates-en#Template-Variables): Can be used to optimize `sitemap.xml` for site SEO
|
|
83
|
+
- [Recently Updated Module](https://jaywhj.netlify.app/document-dates-en#Recently-Updated-Module): Enable list of recently updated documents (in descending order of update date), this is ideal for sites with a large number of documents, so that readers can quickly see what's new
|
|
84
|
+
- [Localization Language](https://jaywhj.netlify.app/document-dates-en#Localization-Language): More localization languages for `timeago` and `tooltip`
|
|
94
85
|
- [Development Stories](https://jaywhj.netlify.app/document-dates-en#Development-Stories): Describes the origin of the plug-in, the difficulties and solutions encountered in development, and the principles and directions of product design
|
|
95
86
|
|
|
96
87
|
See the documentation for details: https://jaywhj.netlify.app/document-dates-en
|
|
@@ -99,7 +90,7 @@ See the documentation for details: https://jaywhj.netlify.app/document-dates-en
|
|
|
99
90
|
|
|
100
91
|
## Other Projects
|
|
101
92
|
|
|
102
|
-
- [**MaterialX**](https://github.com/jaywhj/mkdocs-materialx), the next generation of mkdocs-material
|
|
93
|
+
- [**MaterialX**](https://github.com/jaywhj/mkdocs-materialx), the next generation of mkdocs-material. Build beautiful sites the way you already know and love. Based on `mkdocs-material-9.7.1` and is named `X`, it provides ongoing maintenance and updates (since mkdocs-material will stop being maintained).
|
|
103
94
|
Updates have been released that refactor and add a lot of new features, see https://github.com/jaywhj/mkdocs-materialx/releases/
|
|
104
95
|
|
|
105
96
|
<br />
|
|
@@ -10,7 +10,7 @@ A new generation MkDocs plugin for displaying exact **creation date, last update
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
- [x]
|
|
13
|
+
- [x] Works in any environment: no-Git, Git environments, Docker, all CI/CD build systems, etc.
|
|
14
14
|
- [x] Support list display of recently updated documents (in descending order of update date)
|
|
15
15
|
- [x] Support for manually specifying date and author in `Front Matter`
|
|
16
16
|
- [x] Support for multiple date formats (date, datetime, timeago)
|
|
@@ -48,23 +48,23 @@ plugins:
|
|
|
48
48
|
- document-dates:
|
|
49
49
|
position: top # Display position: top(after title) bottom(end of document), default: top
|
|
50
50
|
type: date # Date type: date datetime timeago, default: date
|
|
51
|
-
exclude: # List of excluded files
|
|
51
|
+
exclude: # List of excluded files (support unix shell-style wildcards)
|
|
52
52
|
- temp.md # Example: exclude the specified file
|
|
53
53
|
- blog/* # Example: exclude all files in blog folder, including subfolders
|
|
54
|
+
- '*/index.md' # Example: exclude all index.md files in any subfolders
|
|
54
55
|
```
|
|
55
56
|
|
|
56
57
|
## Customization Settings
|
|
57
58
|
|
|
58
59
|
In addition to the above basic configuration, the plug-in also provides a wealth of customization options to meet a variety of individual needs:
|
|
59
60
|
|
|
60
|
-
- [
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
63
|
-
- [
|
|
64
|
-
- [
|
|
65
|
-
- [
|
|
66
|
-
- [
|
|
67
|
-
- [Other Tips](https://jaywhj.netlify.app/document-dates-en#Other-Tips): Introducing the Do's of using plugin in Docker
|
|
61
|
+
- [Date & Time](https://jaywhj.netlify.app/document-dates-en#Date--Time): Introduces the mechanism for obtaining document dates and methods for personalized customization, support for manually specifying the creation date and last updated date for each document
|
|
62
|
+
- [Author](https://jaywhj.netlify.app/document-dates-en#Author): Introduces the mechanism for obtaining document authors and methods for personalized customization, support for manually specifying the author information for each document, such as name, link, avatar, email, etc.
|
|
63
|
+
- [Avatar](https://jaywhj.netlify.app/document-dates-en#Avatar): You can manually specify the avatar for each author, support local file path and URL path
|
|
64
|
+
- [Structure and Style](https://jaywhj.netlify.app/document-dates-en#Structure-and-Style): You can freely configure the plugin's display structure in mkdocs.yml or Front Matter. You can quickly set the plugin styles through preset entrances, such as icons, themes, colors, fonts, animations, dividing line and so on
|
|
65
|
+
- [Template Variables](https://jaywhj.netlify.app/document-dates-en#Template-Variables): Can be used to optimize `sitemap.xml` for site SEO
|
|
66
|
+
- [Recently Updated Module](https://jaywhj.netlify.app/document-dates-en#Recently-Updated-Module): Enable list of recently updated documents (in descending order of update date), this is ideal for sites with a large number of documents, so that readers can quickly see what's new
|
|
67
|
+
- [Localization Language](https://jaywhj.netlify.app/document-dates-en#Localization-Language): More localization languages for `timeago` and `tooltip`
|
|
68
68
|
- [Development Stories](https://jaywhj.netlify.app/document-dates-en#Development-Stories): Describes the origin of the plug-in, the difficulties and solutions encountered in development, and the principles and directions of product design
|
|
69
69
|
|
|
70
70
|
See the documentation for details: https://jaywhj.netlify.app/document-dates-en
|
|
@@ -73,7 +73,7 @@ See the documentation for details: https://jaywhj.netlify.app/document-dates-en
|
|
|
73
73
|
|
|
74
74
|
## Other Projects
|
|
75
75
|
|
|
76
|
-
- [**MaterialX**](https://github.com/jaywhj/mkdocs-materialx), the next generation of mkdocs-material
|
|
76
|
+
- [**MaterialX**](https://github.com/jaywhj/mkdocs-materialx), the next generation of mkdocs-material. Build beautiful sites the way you already know and love. Based on `mkdocs-material-9.7.1` and is named `X`, it provides ongoing maintenance and updates (since mkdocs-material will stop being maintained).
|
|
77
77
|
Updates have been released that refactor and add a lot of new features, see https://github.com/jaywhj/mkdocs-materialx/releases/
|
|
78
78
|
|
|
79
79
|
<br />
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""MkDocs Document Dates Plugin."""
|
{mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0}/mkdocs_document_dates/cache_manager.py
RENAMED
|
@@ -1,16 +1,92 @@
|
|
|
1
1
|
import logging
|
|
2
|
+
import os
|
|
2
3
|
import subprocess
|
|
3
4
|
from pathlib import Path
|
|
5
|
+
from logging.handlers import RotatingFileHandler
|
|
6
|
+
from typing import Optional
|
|
4
7
|
from .utils import read_jsonl_cache, write_jsonl_cache, get_file_creation_time, get_git_first_commit_time
|
|
5
8
|
|
|
6
9
|
logger = logging.getLogger("mkdocs.plugins.document_dates")
|
|
7
|
-
|
|
10
|
+
_LOGGING_CONFIGURED = False
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _default_log_file() -> Path:
|
|
14
|
+
try:
|
|
15
|
+
git_root = Path(subprocess.check_output(
|
|
16
|
+
['git', 'rev-parse', '--show-toplevel'],
|
|
17
|
+
env=_clean_git_env(),
|
|
18
|
+
encoding='utf-8'
|
|
19
|
+
).strip())
|
|
20
|
+
base_dir = git_root
|
|
21
|
+
except Exception:
|
|
22
|
+
base_dir = Path.cwd()
|
|
23
|
+
return base_dir / "mkdocs_document_dates.log"
|
|
24
|
+
|
|
25
|
+
def configure_file_logging(log_file: Optional[Path] = None, level: int = logging.DEBUG) -> Optional[Path]:
|
|
26
|
+
global _LOGGING_CONFIGURED
|
|
27
|
+
if _LOGGING_CONFIGURED:
|
|
28
|
+
return log_file
|
|
29
|
+
|
|
30
|
+
env_log_file = os.getenv("MKDOCS_DOCUMENT_DATES_LOG_FILE")
|
|
31
|
+
if log_file is None and env_log_file:
|
|
32
|
+
log_file = Path(env_log_file).expanduser()
|
|
33
|
+
|
|
34
|
+
if log_file is None:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
log_file.parent.mkdir(parents=True, exist_ok=True)
|
|
38
|
+
|
|
39
|
+
handler = RotatingFileHandler(
|
|
40
|
+
log_file,
|
|
41
|
+
maxBytes=5 * 1024 * 1024,
|
|
42
|
+
backupCount=3,
|
|
43
|
+
encoding="utf-8",
|
|
44
|
+
)
|
|
45
|
+
handler.setLevel(level)
|
|
46
|
+
handler.setFormatter(logging.Formatter(
|
|
47
|
+
fmt="%(asctime)s [%(filename)s:%(lineno)d] %(message)s",
|
|
48
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
49
|
+
))
|
|
50
|
+
|
|
51
|
+
logger.setLevel(level)
|
|
52
|
+
logger.addHandler(handler)
|
|
53
|
+
logger.propagate = False
|
|
54
|
+
_LOGGING_CONFIGURED = True
|
|
55
|
+
logger.debug(f"File logging enabled: {log_file}")
|
|
56
|
+
return log_file
|
|
57
|
+
|
|
58
|
+
def _env_truthy(name: str) -> bool:
|
|
59
|
+
value = os.getenv(name)
|
|
60
|
+
if value is None:
|
|
61
|
+
return False
|
|
62
|
+
value = value.strip().lower()
|
|
63
|
+
return value not in ("", "0", "false", "no", "off")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _clean_git_env():
|
|
67
|
+
env = os.environ.copy()
|
|
68
|
+
|
|
69
|
+
for k in [
|
|
70
|
+
"GIT_DIR",
|
|
71
|
+
"GIT_WORK_TREE",
|
|
72
|
+
"GIT_COMMON_DIR",
|
|
73
|
+
"GIT_INDEX_FILE",
|
|
74
|
+
"GIT_PREFIX",
|
|
75
|
+
"GIT_SUPER_PREFIX",
|
|
76
|
+
"GIT_CEILING_DIRECTORIES",
|
|
77
|
+
]:
|
|
78
|
+
env.pop(k, None)
|
|
79
|
+
|
|
80
|
+
env["GIT_OPTIONAL_LOCKS"] = "0"
|
|
81
|
+
|
|
82
|
+
return env
|
|
8
83
|
|
|
9
84
|
def find_mkdocs_projects():
|
|
10
85
|
projects = []
|
|
11
86
|
try:
|
|
12
87
|
git_root = Path(subprocess.check_output(
|
|
13
88
|
['git', 'rev-parse', '--show-toplevel'],
|
|
89
|
+
env=_clean_git_env(),
|
|
14
90
|
encoding='utf-8'
|
|
15
91
|
).strip())
|
|
16
92
|
|
|
@@ -39,7 +115,7 @@ def setup_gitattributes(docs_dir: Path):
|
|
|
39
115
|
content += '\n'
|
|
40
116
|
content += f"{union_merge_line}\n"
|
|
41
117
|
gitattributes_path.write_text(content, encoding='utf-8')
|
|
42
|
-
subprocess.run(["git", "add", str(gitattributes_path)], check=True)
|
|
118
|
+
subprocess.run(["git", "add", str(gitattributes_path)], cwd=docs_dir, env=_clean_git_env(), check=True)
|
|
43
119
|
logger.info(f"Updated .gitattributes file: {gitattributes_path}")
|
|
44
120
|
return True
|
|
45
121
|
except (IOError, OSError) as e:
|
|
@@ -49,8 +125,12 @@ def setup_gitattributes(docs_dir: Path):
|
|
|
49
125
|
return False
|
|
50
126
|
|
|
51
127
|
def update_cache():
|
|
52
|
-
|
|
128
|
+
if os.getenv("MKDOCS_DOCUMENT_DATES_LOG_FILE"):
|
|
129
|
+
configure_file_logging()
|
|
130
|
+
elif _env_truthy("MKDOCS_DOCUMENT_DATES_DEBUG"):
|
|
131
|
+
configure_file_logging(_default_log_file())
|
|
53
132
|
|
|
133
|
+
global_updated = False
|
|
54
134
|
for project_dir in find_mkdocs_projects():
|
|
55
135
|
try:
|
|
56
136
|
project_updated = False
|
|
@@ -65,7 +145,7 @@ def update_cache():
|
|
|
65
145
|
|
|
66
146
|
# 获取docs目录下已跟踪(tracked)的markdown文件
|
|
67
147
|
cmd = ["git", "ls-files", "*.md"]
|
|
68
|
-
result = subprocess.run(cmd, cwd=docs_dir, capture_output=True, encoding='utf-8')
|
|
148
|
+
result = subprocess.run(cmd, cwd=docs_dir, env=_clean_git_env(), capture_output=True, encoding='utf-8')
|
|
69
149
|
tracked_files = result.stdout.splitlines() if result.stdout else []
|
|
70
150
|
|
|
71
151
|
if not tracked_files:
|
|
@@ -115,4 +195,4 @@ def update_cache():
|
|
|
115
195
|
|
|
116
196
|
|
|
117
197
|
if __name__ == "__main__":
|
|
118
|
-
update_cache()
|
|
198
|
+
update_cache()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import subprocess
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
DEFAULT_HOOKS_DIRNAME = ".githooks"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HookInstallError(Exception):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_repo_root() -> Path:
|
|
14
|
+
result = subprocess.run(
|
|
15
|
+
["git", "rev-parse", "--show-toplevel"],
|
|
16
|
+
capture_output=True,
|
|
17
|
+
text=True,
|
|
18
|
+
)
|
|
19
|
+
if result.returncode != 0 or not result.stdout.strip():
|
|
20
|
+
raise HookInstallError("This command must be run inside a Git repo. Please cd into your project directory and try again.")
|
|
21
|
+
return Path(result.stdout.strip())
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def ensure_hooks_dir(repo_root: Path) -> Path:
|
|
25
|
+
hooks_dir = repo_root / DEFAULT_HOOKS_DIRNAME
|
|
26
|
+
try:
|
|
27
|
+
hooks_dir.mkdir(parents=True, exist_ok=True)
|
|
28
|
+
os.chmod(hooks_dir, 0o755)
|
|
29
|
+
except Exception as e:
|
|
30
|
+
raise HookInstallError(f"Failed to create hooks directory: {hooks_dir} ({e})")
|
|
31
|
+
return hooks_dir
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def write_hooks(source_dir: Path, target_dir: Path):
|
|
35
|
+
if not source_dir.exists():
|
|
36
|
+
raise HookInstallError(f"Hooks source directory not found: {source_dir}")
|
|
37
|
+
|
|
38
|
+
shebang = f"#!{sys.executable}"
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
for file in source_dir.iterdir():
|
|
42
|
+
if file.name.startswith(".") or not file.is_file():
|
|
43
|
+
continue
|
|
44
|
+
|
|
45
|
+
content = file.read_text(encoding="utf-8")
|
|
46
|
+
|
|
47
|
+
if content.startswith("#!"):
|
|
48
|
+
os.linesep
|
|
49
|
+
content = shebang + "\n" + content.split("\n", 1)[1]
|
|
50
|
+
else:
|
|
51
|
+
content = shebang + "\n" + content
|
|
52
|
+
|
|
53
|
+
target = target_dir / file.name
|
|
54
|
+
target.write_text(content, encoding="utf-8")
|
|
55
|
+
os.chmod(target, 0o755)
|
|
56
|
+
|
|
57
|
+
except Exception as e:
|
|
58
|
+
raise HookInstallError(f"Failed to write hook files: {e}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def set_hooks_path(repo_root: Path, hooks_dir: Path):
|
|
62
|
+
rel_path = hooks_dir.relative_to(repo_root).as_posix()
|
|
63
|
+
|
|
64
|
+
# # 配置自定义合并驱动
|
|
65
|
+
# script_path = hooks_dir / 'json_merge_driver.py'
|
|
66
|
+
# subprocess.run(['git', 'config', 'merge.custom_json_merge.name', 'Custom JSON merge driver'], check=True)
|
|
67
|
+
# subprocess.run(['git', 'config', 'merge.custom_json_merge.driver', f'"{sys.executable}" "{script_path}" %O %A %B'], check=True)
|
|
68
|
+
|
|
69
|
+
result = subprocess.run(
|
|
70
|
+
["git", "config", "core.hooksPath", rel_path],
|
|
71
|
+
cwd=repo_root,
|
|
72
|
+
capture_output=True,
|
|
73
|
+
text=True,
|
|
74
|
+
)
|
|
75
|
+
if result.returncode != 0:
|
|
76
|
+
raise HookInstallError(result.stderr.strip() or "Failed to set hooksPath")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def install():
|
|
80
|
+
try:
|
|
81
|
+
repo_root = get_repo_root()
|
|
82
|
+
hooks_dir = ensure_hooks_dir(repo_root)
|
|
83
|
+
|
|
84
|
+
source_dir = Path(__file__).parent / "hooks"
|
|
85
|
+
|
|
86
|
+
write_hooks(source_dir, hooks_dir)
|
|
87
|
+
set_hooks_path(repo_root, hooks_dir)
|
|
88
|
+
|
|
89
|
+
print(f"✔ Hooks installed successfully: {hooks_dir}")
|
|
90
|
+
|
|
91
|
+
except HookInstallError as e:
|
|
92
|
+
print(f"✖ Installation failed: {e}", file=sys.stderr)
|
|
93
|
+
except Exception as e:
|
|
94
|
+
print(f"✖ Unexpected error: {e}", file=sys.stderr)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
install()
|
|
@@ -43,6 +43,7 @@ class DocumentDatesPlugin(BasePlugin):
|
|
|
43
43
|
|
|
44
44
|
def __init__(self):
|
|
45
45
|
super().__init__()
|
|
46
|
+
|
|
46
47
|
self.dates_cache = {}
|
|
47
48
|
self.last_updated_dates = {}
|
|
48
49
|
self.authors_yml = {}
|
|
@@ -97,7 +98,14 @@ class DocumentDatesPlugin(BasePlugin):
|
|
|
97
98
|
# https://cdn.jsdelivr.net/npm/timeago.js@4.0.2/dist/timeago.min.js
|
|
98
99
|
# https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.2/timeago.full.min.js
|
|
99
100
|
if self.config['type'] == 'timeago':
|
|
100
|
-
config
|
|
101
|
+
scripts = config.get('extra_javascript') or []
|
|
102
|
+
has_timeago = any(
|
|
103
|
+
str(item).endswith('timeago.min.js') or str(item).endswith('timeago.full.min.js')
|
|
104
|
+
for item in scripts
|
|
105
|
+
)
|
|
106
|
+
if not has_timeago:
|
|
107
|
+
scripts.insert(0, 'assets/document_dates/core/timeago.min.js')
|
|
108
|
+
config['extra_javascript'] = scripts
|
|
101
109
|
|
|
102
110
|
"""
|
|
103
111
|
Tippy.js, for Tooltip
|
|
@@ -160,12 +168,17 @@ class DocumentDatesPlugin(BasePlugin):
|
|
|
160
168
|
|
|
161
169
|
# 获取作者信息
|
|
162
170
|
authors = self._get_author_info(rel_path, page, config)
|
|
163
|
-
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
171
|
+
|
|
172
|
+
# 按 MaterialX 的数据规范给 meta 填充数据
|
|
173
|
+
mx = page.meta.setdefault("_mx", {})
|
|
174
|
+
mx["document_dates"] = {
|
|
175
|
+
"dates": {
|
|
176
|
+
"created": created.isoformat(),
|
|
177
|
+
"updated": updated.isoformat(),
|
|
178
|
+
},
|
|
179
|
+
"authors": authors
|
|
180
|
+
}
|
|
181
|
+
|
|
169
182
|
# 检查是否需要排除
|
|
170
183
|
if is_excluded(rel_path, self._exclude_patterns):
|
|
171
184
|
return markdown
|
|
@@ -202,6 +215,16 @@ class DocumentDatesPlugin(BasePlugin):
|
|
|
202
215
|
if self.recent_enable:
|
|
203
216
|
self.recent_docs_html = self._render_recently_updated_html(recently_updated_docs)
|
|
204
217
|
|
|
218
|
+
# # 便捷访问日期数据函数
|
|
219
|
+
# def mdd_access(page, domain):
|
|
220
|
+
# return (
|
|
221
|
+
# page.meta.get("_mx", {})
|
|
222
|
+
# .get("document_dates", {})
|
|
223
|
+
# .get(domain, {})
|
|
224
|
+
# )
|
|
225
|
+
|
|
226
|
+
# env.globals["mdd"] = mdd_access
|
|
227
|
+
|
|
205
228
|
return env
|
|
206
229
|
|
|
207
230
|
def on_post_page(self, output, page, config):
|
|
Binary file
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
border: 1px solid rgba(142, 142, 142, 0.2);
|
|
57
57
|
border-radius: 8px;
|
|
58
58
|
row-gap: 0;
|
|
59
|
-
padding:
|
|
59
|
+
padding: 12px;
|
|
60
60
|
}
|
|
61
61
|
.article-grid.is-list .card-body {
|
|
62
62
|
display: none;
|
|
@@ -109,7 +109,8 @@
|
|
|
109
109
|
white-space: nowrap;
|
|
110
110
|
margin-right: 10px;
|
|
111
111
|
}
|
|
112
|
-
.card-header:hover
|
|
112
|
+
.card-header:hover,
|
|
113
|
+
.card-header:focus {
|
|
113
114
|
text-decoration: none !important;
|
|
114
115
|
}
|
|
115
116
|
.card-header:hover .card-title {
|
|
@@ -151,9 +152,9 @@
|
|
|
151
152
|
transition: filter 0.3s ease;
|
|
152
153
|
|
|
153
154
|
/* Safari 圆角闪烁修复 */
|
|
154
|
-
transform: translateZ(0);
|
|
155
|
-
will-change: transform;
|
|
156
|
-
-webkit-mask-image: -webkit-radial-gradient(white, black);
|
|
155
|
+
transform: translateZ(0);
|
|
156
|
+
will-change: transform;
|
|
157
|
+
-webkit-mask-image: -webkit-radial-gradient(white, black);
|
|
157
158
|
isolation: isolate;
|
|
158
159
|
}
|
|
159
160
|
.card-cover:hover {
|
|
@@ -169,7 +169,7 @@ def get_recently_updated_files(existing_dates: dict, files: Files, exclude_list:
|
|
|
169
169
|
# authors = []
|
|
170
170
|
if file.page:
|
|
171
171
|
cover = file.page.meta.get('cover', '')
|
|
172
|
-
# authors = file.page.meta.
|
|
172
|
+
# authors = file.page.meta._mx.document_dates.authors
|
|
173
173
|
if file.page.file:
|
|
174
174
|
summary = extract_summary(file.page.file.content_string)
|
|
175
175
|
|
{mkdocs_document_dates-3.6.1 → mkdocs_document_dates-3.7.0/mkdocs_document_dates.egg-info}/PKG-INFO
RENAMED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-document-dates
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.0
|
|
4
4
|
Summary: A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Author-email: Aaron Wang <aaronwqt@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jaywhj/mkdocs-document-dates
|
|
8
|
+
Project-URL: Repository, https://github.com/jaywhj/mkdocs-document-dates
|
|
9
|
+
Project-URL: Documentation, https://jaywhj.netlify.app/document-dates-en
|
|
9
10
|
Classifier: Programming Language :: Python :: 3
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
11
12
|
Requires-Python: >=3.7
|
|
12
13
|
Description-Content-Type: text/markdown
|
|
13
14
|
License-File: LICENSE
|
|
14
15
|
Requires-Dist: mkdocs>=1.1.0
|
|
15
|
-
Dynamic: author
|
|
16
|
-
Dynamic: author-email
|
|
17
|
-
Dynamic: classifier
|
|
18
|
-
Dynamic: description
|
|
19
|
-
Dynamic: description-content-type
|
|
20
|
-
Dynamic: home-page
|
|
21
|
-
Dynamic: license
|
|
22
16
|
Dynamic: license-file
|
|
23
|
-
Dynamic: requires-dist
|
|
24
|
-
Dynamic: requires-python
|
|
25
|
-
Dynamic: summary
|
|
26
17
|
|
|
27
18
|
# mkdocs-document-dates
|
|
28
19
|
|
|
@@ -36,7 +27,7 @@ A new generation MkDocs plugin for displaying exact **creation date, last update
|
|
|
36
27
|
|
|
37
28
|
## Features
|
|
38
29
|
|
|
39
|
-
- [x]
|
|
30
|
+
- [x] Works in any environment: no-Git, Git environments, Docker, all CI/CD build systems, etc.
|
|
40
31
|
- [x] Support list display of recently updated documents (in descending order of update date)
|
|
41
32
|
- [x] Support for manually specifying date and author in `Front Matter`
|
|
42
33
|
- [x] Support for multiple date formats (date, datetime, timeago)
|
|
@@ -74,23 +65,23 @@ plugins:
|
|
|
74
65
|
- document-dates:
|
|
75
66
|
position: top # Display position: top(after title) bottom(end of document), default: top
|
|
76
67
|
type: date # Date type: date datetime timeago, default: date
|
|
77
|
-
exclude: # List of excluded files
|
|
68
|
+
exclude: # List of excluded files (support unix shell-style wildcards)
|
|
78
69
|
- temp.md # Example: exclude the specified file
|
|
79
70
|
- blog/* # Example: exclude all files in blog folder, including subfolders
|
|
71
|
+
- '*/index.md' # Example: exclude all index.md files in any subfolders
|
|
80
72
|
```
|
|
81
73
|
|
|
82
74
|
## Customization Settings
|
|
83
75
|
|
|
84
76
|
In addition to the above basic configuration, the plug-in also provides a wealth of customization options to meet a variety of individual needs:
|
|
85
77
|
|
|
86
|
-
- [
|
|
87
|
-
- [
|
|
88
|
-
- [
|
|
89
|
-
- [
|
|
90
|
-
- [
|
|
91
|
-
- [
|
|
92
|
-
- [
|
|
93
|
-
- [Other Tips](https://jaywhj.netlify.app/document-dates-en#Other-Tips): Introducing the Do's of using plugin in Docker
|
|
78
|
+
- [Date & Time](https://jaywhj.netlify.app/document-dates-en#Date--Time): Introduces the mechanism for obtaining document dates and methods for personalized customization, support for manually specifying the creation date and last updated date for each document
|
|
79
|
+
- [Author](https://jaywhj.netlify.app/document-dates-en#Author): Introduces the mechanism for obtaining document authors and methods for personalized customization, support for manually specifying the author information for each document, such as name, link, avatar, email, etc.
|
|
80
|
+
- [Avatar](https://jaywhj.netlify.app/document-dates-en#Avatar): You can manually specify the avatar for each author, support local file path and URL path
|
|
81
|
+
- [Structure and Style](https://jaywhj.netlify.app/document-dates-en#Structure-and-Style): You can freely configure the plugin's display structure in mkdocs.yml or Front Matter. You can quickly set the plugin styles through preset entrances, such as icons, themes, colors, fonts, animations, dividing line and so on
|
|
82
|
+
- [Template Variables](https://jaywhj.netlify.app/document-dates-en#Template-Variables): Can be used to optimize `sitemap.xml` for site SEO
|
|
83
|
+
- [Recently Updated Module](https://jaywhj.netlify.app/document-dates-en#Recently-Updated-Module): Enable list of recently updated documents (in descending order of update date), this is ideal for sites with a large number of documents, so that readers can quickly see what's new
|
|
84
|
+
- [Localization Language](https://jaywhj.netlify.app/document-dates-en#Localization-Language): More localization languages for `timeago` and `tooltip`
|
|
94
85
|
- [Development Stories](https://jaywhj.netlify.app/document-dates-en#Development-Stories): Describes the origin of the plug-in, the difficulties and solutions encountered in development, and the principles and directions of product design
|
|
95
86
|
|
|
96
87
|
See the documentation for details: https://jaywhj.netlify.app/document-dates-en
|
|
@@ -99,7 +90,7 @@ See the documentation for details: https://jaywhj.netlify.app/document-dates-en
|
|
|
99
90
|
|
|
100
91
|
## Other Projects
|
|
101
92
|
|
|
102
|
-
- [**MaterialX**](https://github.com/jaywhj/mkdocs-materialx), the next generation of mkdocs-material
|
|
93
|
+
- [**MaterialX**](https://github.com/jaywhj/mkdocs-materialx), the next generation of mkdocs-material. Build beautiful sites the way you already know and love. Based on `mkdocs-material-9.7.1` and is named `X`, it provides ongoing maintenance and updates (since mkdocs-material will stop being maintained).
|
|
103
94
|
Updates have been released that refactor and add a lot of new features, see https://github.com/jaywhj/mkdocs-materialx/releases/
|
|
104
95
|
|
|
105
96
|
<br />
|
|
@@ -15,6 +15,7 @@ mkdocs_document_dates.egg-info/entry_points.txt
|
|
|
15
15
|
mkdocs_document_dates.egg-info/requires.txt
|
|
16
16
|
mkdocs_document_dates.egg-info/top_level.txt
|
|
17
17
|
mkdocs_document_dates/hooks/pre-commit
|
|
18
|
+
mkdocs_document_dates/static/.DS_Store
|
|
18
19
|
mkdocs_document_dates/static/config/user.config.css
|
|
19
20
|
mkdocs_document_dates/static/config/user.config.js
|
|
20
21
|
mkdocs_document_dates/static/core/core.css
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mkdocs-document-dates"
|
|
7
|
+
version = "3.7.0"
|
|
8
|
+
description = "A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents"
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "Aaron Wang", email = "aaronwqt@gmail.com" }]
|
|
13
|
+
dependencies = ["mkdocs>=1.1.0"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/jaywhj/mkdocs-document-dates"
|
|
21
|
+
Repository = "https://github.com/jaywhj/mkdocs-document-dates"
|
|
22
|
+
Documentation = "https://jaywhj.netlify.app/document-dates-en"
|
|
23
|
+
|
|
24
|
+
[project.entry-points."mkdocs.plugins"]
|
|
25
|
+
document-dates = "mkdocs_document_dates.plugin:DocumentDatesPlugin"
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
mkdocs-document-dates-hooks = "mkdocs_document_dates.hooks_installer:install"
|
|
29
|
+
mdd-hooks = "mkdocs_document_dates.hooks_installer:install"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools]
|
|
32
|
+
include-package-data = true
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["."]
|
|
36
|
+
include = ["mkdocs_document_dates*"]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.package-data]
|
|
39
|
+
mkdocs_document_dates = [
|
|
40
|
+
"hooks/*",
|
|
41
|
+
"static/**/*",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.exclude-package-data]
|
|
45
|
+
"*" = [
|
|
46
|
+
".DS_Store",
|
|
47
|
+
"**/.DS_Store",
|
|
48
|
+
]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from setuptools import find_packages, setup
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def legacy_setup():
|
|
5
|
+
setup(
|
|
6
|
+
name="mkdocs-document-dates",
|
|
7
|
+
version="3.7.0",
|
|
8
|
+
author="Aaron Wang",
|
|
9
|
+
author_email="aaronwqt@gmail.com",
|
|
10
|
+
license="MIT",
|
|
11
|
+
description="A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents",
|
|
12
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url="https://github.com/jaywhj/mkdocs-document-dates",
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
include_package_data=True,
|
|
17
|
+
install_requires=[
|
|
18
|
+
"mkdocs>=1.1.0",
|
|
19
|
+
],
|
|
20
|
+
classifiers=[
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
],
|
|
24
|
+
entry_points={
|
|
25
|
+
"mkdocs.plugins": [
|
|
26
|
+
"document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin",
|
|
27
|
+
],
|
|
28
|
+
"console_scripts": [
|
|
29
|
+
"mkdocs-document-dates-hooks=mkdocs_document_dates.hooks_installer:install",
|
|
30
|
+
"mdd-hooks=mkdocs_document_dates.hooks_installer:install",
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
package_data={
|
|
34
|
+
"mkdocs_document_dates": [
|
|
35
|
+
"hooks/*",
|
|
36
|
+
"static/templates/*",
|
|
37
|
+
"static/fonts/*",
|
|
38
|
+
"static/tippy/*",
|
|
39
|
+
"static/core/*",
|
|
40
|
+
"static/config/*"
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
python_requires=">=3.7",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
setup()
|
|
49
|
+
except Exception:
|
|
50
|
+
legacy_setup()
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
import logging
|
|
4
|
-
import subprocess
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
import platform
|
|
7
|
-
|
|
8
|
-
logger = logging.getLogger("mkdocs.plugins.document_dates")
|
|
9
|
-
logger.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
10
|
-
|
|
11
|
-
def get_config_dir():
|
|
12
|
-
if platform.system().lower().startswith('win'):
|
|
13
|
-
return Path(os.getenv('APPDATA', str(Path.home() / 'AppData' / 'Roaming')))
|
|
14
|
-
else:
|
|
15
|
-
# 优先级:XDG_CONFIG_HOME > $HOME/.config > cwd/.config
|
|
16
|
-
xdg_config = os.getenv('XDG_CONFIG_HOME')
|
|
17
|
-
if xdg_config:
|
|
18
|
-
return Path(xdg_config)
|
|
19
|
-
home = os.getenv('HOME')
|
|
20
|
-
if home:
|
|
21
|
-
return Path(home) / '.config'
|
|
22
|
-
return Path.cwd() / '.config'
|
|
23
|
-
|
|
24
|
-
def check_python_version(interpreter):
|
|
25
|
-
try:
|
|
26
|
-
result = subprocess.run(
|
|
27
|
-
[interpreter, "-c", "import sys; print(sys.version_info >= (3, 7))"],
|
|
28
|
-
capture_output=True, encoding='utf-8')
|
|
29
|
-
if result.returncode == 0 and result.stdout.strip().lower() == 'true':
|
|
30
|
-
return True
|
|
31
|
-
else:
|
|
32
|
-
logger.warning(f"Low python version, requires python_requires >=3.7")
|
|
33
|
-
except Exception as e:
|
|
34
|
-
logger.info(f"Failed to check {interpreter}: {str(e)}")
|
|
35
|
-
return False
|
|
36
|
-
|
|
37
|
-
def detect_python_interpreter():
|
|
38
|
-
# 检查可能的Python解释器
|
|
39
|
-
python_interpreters = ['python3', 'python']
|
|
40
|
-
for interpreter in python_interpreters:
|
|
41
|
-
if check_python_version(interpreter):
|
|
42
|
-
return f'#!/usr/bin/env {interpreter}'
|
|
43
|
-
|
|
44
|
-
# 如果都失败了,使用当前运行的Python解释器
|
|
45
|
-
return f'#!{sys.executable}'
|
|
46
|
-
|
|
47
|
-
def setup_hooks_directory():
|
|
48
|
-
config_dir = get_config_dir() / 'mkdocs-document-dates' / 'hooks'
|
|
49
|
-
try:
|
|
50
|
-
config_dir.mkdir(parents=True, exist_ok=True)
|
|
51
|
-
os.chmod(config_dir, 0o755)
|
|
52
|
-
return config_dir
|
|
53
|
-
except PermissionError:
|
|
54
|
-
logger.error(
|
|
55
|
-
f"No permission to create directory: {config_dir}\n"
|
|
56
|
-
"If running inside Docker, please set environment variable HOME=/docs "
|
|
57
|
-
"or XDG_CONFIG_HOME to a writable path."
|
|
58
|
-
)
|
|
59
|
-
except Exception as e:
|
|
60
|
-
logger.error(f"Failed to create directory {config_dir}: {str(e)}")
|
|
61
|
-
return None
|
|
62
|
-
|
|
63
|
-
def install_hook_file(source_dir: Path, target_dir: Path):
|
|
64
|
-
try:
|
|
65
|
-
shebang = detect_python_interpreter()
|
|
66
|
-
for item in source_dir.iterdir():
|
|
67
|
-
# 跳过隐藏文件和目录
|
|
68
|
-
if item.name.startswith('.') or not item.is_file():
|
|
69
|
-
continue
|
|
70
|
-
# 添加 shebang 行
|
|
71
|
-
content = item.read_text(encoding='utf-8')
|
|
72
|
-
if content.startswith('#!'):
|
|
73
|
-
content = shebang + os.linesep + content[content.find('\n')+1:]
|
|
74
|
-
else:
|
|
75
|
-
content = shebang + os.linesep + content
|
|
76
|
-
|
|
77
|
-
target_hook_path = target_dir / item.name
|
|
78
|
-
target_hook_path.write_text(content, encoding='utf-8')
|
|
79
|
-
os.chmod(target_hook_path, 0o755)
|
|
80
|
-
|
|
81
|
-
return True
|
|
82
|
-
except Exception as e:
|
|
83
|
-
logger.error(f"Failed to create hook file {target_hook_path}: {str(e)}")
|
|
84
|
-
return False
|
|
85
|
-
|
|
86
|
-
def configure_git_hooks(hooks_dir):
|
|
87
|
-
try:
|
|
88
|
-
# 配置自定义合并驱动
|
|
89
|
-
# script_path = hooks_dir / 'json_merge_driver.py'
|
|
90
|
-
# subprocess.run(['git', 'config', '--global', 'merge.custom_json_merge.name', 'Custom JSON merge driver'], check=True)
|
|
91
|
-
# subprocess.run(['git', 'config', '--global', 'merge.custom_json_merge.driver', f'"{sys.executable}" "{script_path}" %O %A %B'], check=True)
|
|
92
|
-
|
|
93
|
-
subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)], check=True)
|
|
94
|
-
logger.info(f"Git hooks successfully installed in: {hooks_dir}")
|
|
95
|
-
return True
|
|
96
|
-
except Exception:
|
|
97
|
-
logger.warning("Git not detected, using plugin in a no-Git environment")
|
|
98
|
-
return False
|
|
99
|
-
|
|
100
|
-
def install():
|
|
101
|
-
try:
|
|
102
|
-
# 创建hooks目录
|
|
103
|
-
target_dir = setup_hooks_directory()
|
|
104
|
-
if not target_dir:
|
|
105
|
-
return False
|
|
106
|
-
|
|
107
|
-
# 安装hook文件
|
|
108
|
-
source_dir = Path(__file__).parent / 'hooks'
|
|
109
|
-
if not install_hook_file(source_dir, target_dir):
|
|
110
|
-
return False
|
|
111
|
-
|
|
112
|
-
# 配置git hooks路径
|
|
113
|
-
return configure_git_hooks(target_dir)
|
|
114
|
-
|
|
115
|
-
except Exception as e:
|
|
116
|
-
logger.error(f"Unexpected error during hooks installation: {str(e)}")
|
|
117
|
-
return False
|
|
118
|
-
|
|
119
|
-
if __name__ == '__main__':
|
|
120
|
-
install()
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
from setuptools.command.install import install
|
|
3
|
-
import atexit
|
|
4
|
-
|
|
5
|
-
def trigger_hook_install():
|
|
6
|
-
try:
|
|
7
|
-
import os
|
|
8
|
-
import sys
|
|
9
|
-
package_path = os.path.abspath(os.path.dirname(__file__))
|
|
10
|
-
if package_path not in sys.path:
|
|
11
|
-
sys.path.insert(0, package_path)
|
|
12
|
-
|
|
13
|
-
# from mkdocs_document_dates.hooks_installer import install
|
|
14
|
-
# install()
|
|
15
|
-
# import mkdocs_document_dates
|
|
16
|
-
__import__('mkdocs_document_dates')
|
|
17
|
-
except Exception as e:
|
|
18
|
-
print(f"Warning: Failed to install Git hooks: {e}")
|
|
19
|
-
|
|
20
|
-
class CustomInstallCommand(install):
|
|
21
|
-
def run(self):
|
|
22
|
-
atexit.register(trigger_hook_install)
|
|
23
|
-
install.run(self)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
VERSION = '3.6.1'
|
|
27
|
-
|
|
28
|
-
setup(
|
|
29
|
-
name="mkdocs-document-dates",
|
|
30
|
-
version=VERSION,
|
|
31
|
-
author="Aaron Wang",
|
|
32
|
-
author_email="aaronwqt@gmail.com",
|
|
33
|
-
license="MIT",
|
|
34
|
-
description="A new generation MkDocs plugin for displaying exact creation date, last updated date, authors, email of documents",
|
|
35
|
-
long_description=open("README.md", encoding="utf-8").read(),
|
|
36
|
-
long_description_content_type="text/markdown",
|
|
37
|
-
url="https://github.com/jaywhj/mkdocs-document-dates",
|
|
38
|
-
packages=find_packages(),
|
|
39
|
-
install_requires=[
|
|
40
|
-
'mkdocs>=1.1.0',
|
|
41
|
-
],
|
|
42
|
-
classifiers=[
|
|
43
|
-
"Programming Language :: Python :: 3",
|
|
44
|
-
"Operating System :: OS Independent",
|
|
45
|
-
],
|
|
46
|
-
cmdclass={
|
|
47
|
-
'install': CustomInstallCommand,
|
|
48
|
-
},
|
|
49
|
-
entry_points={
|
|
50
|
-
'mkdocs.plugins': [
|
|
51
|
-
'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
|
|
52
|
-
],
|
|
53
|
-
'console_scripts': [
|
|
54
|
-
# 提供手动安装 hooks 的入口
|
|
55
|
-
'mkdocs-document-dates-hooks=mkdocs_document_dates.hooks_installer:install'
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
package_data={
|
|
59
|
-
'mkdocs_document_dates': [
|
|
60
|
-
'hooks/*',
|
|
61
|
-
'static/templates/*',
|
|
62
|
-
'static/fonts/*',
|
|
63
|
-
'static/tippy/*',
|
|
64
|
-
'static/core/*',
|
|
65
|
-
'static/config/*'
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
python_requires=">=3.7",
|
|
69
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|