From c13d6b1161a6994201f0bf6f23eb7e26220918c6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:33:02 +0100 Subject: [PATCH 01/15] Default Author --- plugin/utils.py | 5 ++++- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/utils.py b/plugin/utils.py index 2100296..0f870f3 100644 --- a/plugin/utils.py +++ b/plugin/utils.py @@ -135,12 +135,13 @@ def get_github_username_from_email(email, cache, file_path="", verbose=True): return None, None -def get_github_usernames_from_file(file_path): +def get_github_usernames_from_file(file_path, default_user=None): """ Fetch GitHub usernames associated with a file using Git Log and Git Blame commands. Args: file_path (str): The path to the file for which GitHub usernames are to be retrieved. + default_user (str, optional): Default GitHub user email to use if no authors found. Defaults to None. Returns: (dict): A dictionary where keys are GitHub usernames or emails (if username is not found) and values are dictionaries containing: @@ -196,6 +197,8 @@ def get_github_usernames_from_file(file_path): info = {} for email, changes in emails.items(): + if not email and default_user: + email = default_user username, avatar = get_github_username_from_email(email, cache, file_path) # If we can't determine the user URL, revert to the GitHub file URL user_url = f"https://github.com/{username}" if username else github_repo_url diff --git a/pyproject.toml b/pyproject.toml index 23d6dc9..1fcba00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ build-backend = "setuptools.build_meta" [project] name = "mkdocs-ultralytics-plugin" -version = "0.1.15" +version = "0.1.16" description = "An MkDocs plugin that provides Ultralytics Docs customizations at https://docs.ultralytics.com." readme = "README.md" requires-python = ">=3.8" From 7a74c2be391b6edb0eeebb852dbef64fa9d9d12b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:34:25 +0100 Subject: [PATCH 02/15] Default Author --- plugin/main.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index f50595f..b4768e1 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -3,6 +3,7 @@ import json from pathlib import Path from subprocess import check_output +import datetime from bs4 import BeautifulSoup from mkdocs.config import config_options @@ -14,6 +15,8 @@ get_youtube_video_ids, ) +TODAY = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000') + class MetaPlugin(BasePlugin): """ @@ -36,6 +39,7 @@ class MetaPlugin(BasePlugin): ("verbose", config_options.Type(bool, default=True)), # Enable verbose output for debugging ("enabled", config_options.Type(bool, default=True)), # Enable or disable the plugin ("default_image", config_options.Type(str, default=None)), # Default image URL if none found in content + ("default_author", config_options.Type(str, default=None)), # Default GitHub author email if none found ("add_desc", config_options.Type(bool, default=True)), # Add meta description tags ("add_image", config_options.Type(bool, default=True)), # Add meta image tags ("add_keywords", config_options.Type(bool, default=True)), # Add meta keywords tags @@ -71,18 +75,19 @@ def get_git_info(self, file_path): """ file_path = str(Path(file_path).resolve()) - # Get the creation date + # Get the creation and last modified dates args = ["git", "log", "--reverse", "--pretty=format:%ai", file_path] creation_date = check_output(args).decode("utf-8").split("\n")[0] - git_info = {"creation_date": creation_date} - - # Get the last modification date last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") - git_info["last_modified_date"] = last_modified_date + git_info = { + "creation_date": creation_date or TODAY, + "last_modified_date": last_modified_date or TODAY + } + print(git_info) # Get the authors and their contributions count using get_github_usernames_from_file function if self.config["add_authors"]: - authors_info = get_github_usernames_from_file(file_path) + authors_info = get_github_usernames_from_file(file_path, default_user=self.config["default_author"]) git_info["authors"] = [ (author, info["url"], info["changes"], info["avatar"]) for author, info in authors_info.items() ] From 1db009dbdf8afbeb5a7783480e93f817bd5ef0e0 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Wed, 29 Jan 2025 18:35:25 +0000 Subject: [PATCH 03/15] Auto-format by https://ultralytics.com/actions --- plugin/main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index b4768e1..102ee42 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -1,9 +1,9 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license +import datetime import json from pathlib import Path from subprocess import check_output -import datetime from bs4 import BeautifulSoup from mkdocs.config import config_options @@ -15,7 +15,7 @@ get_youtube_video_ids, ) -TODAY = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000') +TODAY = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): @@ -79,10 +79,7 @@ def get_git_info(self, file_path): args = ["git", "log", "--reverse", "--pretty=format:%ai", file_path] creation_date = check_output(args).decode("utf-8").split("\n")[0] last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") - git_info = { - "creation_date": creation_date or TODAY, - "last_modified_date": last_modified_date or TODAY - } + git_info = {"creation_date": creation_date or TODAY, "last_modified_date": last_modified_date or TODAY} print(git_info) # Get the authors and their contributions count using get_github_usernames_from_file function From fc3c34621743ce6e1e60c843a4f3481aa9afae85 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:40:33 +0100 Subject: [PATCH 04/15] Default Author --- plugin/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index b4768e1..6ad62a2 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -3,7 +3,7 @@ import json from pathlib import Path from subprocess import check_output -import datetime +from datetime import datetime from bs4 import BeautifulSoup from mkdocs.config import config_options @@ -15,7 +15,10 @@ get_youtube_video_ids, ) -TODAY = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000') + +today = datetime.now() +TODAY = today.strftime('%Y-%m-%d %H:%M:%S +0000') +LAST_MONTH = today.replace(month=today.month-1 if today.month > 1 else 12).strftime('%Y-%m-%d %H:%M:%S +0000') class MetaPlugin(BasePlugin): @@ -80,7 +83,7 @@ def get_git_info(self, file_path): creation_date = check_output(args).decode("utf-8").split("\n")[0] last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") git_info = { - "creation_date": creation_date or TODAY, + "creation_date": creation_date or LAST_MONTH, "last_modified_date": last_modified_date or TODAY } print(git_info) From 518cec0b06d636fa0adfbd3e26cae8050a196010 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:40:45 +0100 Subject: [PATCH 05/15] Default Author --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9610bcf..31c4a9e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ The plugin supports several configuration arguments to tailor its behavior to yo - `verbose`: Toggles verbose output. Useful for debugging. (default: `True`) - `enabled`: Toggles plugin activation. (default: `True`) - `default_image`: Provides a fallback image URL if none is found in your content. (default: `None`) +- `default_author`: GitHub author email to use if no author is found for pages. (default: `None`) - `add_desc`: Controls the generation of meta description tags. (default: `True`) - `add_image`: Manages meta image tag generation. (default: `True`) - `add_keywords`: Allows meta keyword tag generation. (default: `True`) @@ -63,6 +64,7 @@ plugins: verbose: True enabled: True default_image: "https://example.com/default-image.png" + default_author: "you@company.com" add_desc: True add_image: True add_keywords: True From 810529e0b4d06a2dac3bd50ca3e78d1cdf42a078 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Wed, 29 Jan 2025 18:41:11 +0000 Subject: [PATCH 06/15] Auto-format by https://ultralytics.com/actions --- plugin/main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index 6ad62a2..ef585c9 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -1,9 +1,9 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license import json +from datetime import datetime from pathlib import Path from subprocess import check_output -from datetime import datetime from bs4 import BeautifulSoup from mkdocs.config import config_options @@ -15,10 +15,9 @@ get_youtube_video_ids, ) - today = datetime.now() -TODAY = today.strftime('%Y-%m-%d %H:%M:%S +0000') -LAST_MONTH = today.replace(month=today.month-1 if today.month > 1 else 12).strftime('%Y-%m-%d %H:%M:%S +0000') +TODAY = today.strftime("%Y-%m-%d %H:%M:%S +0000") +LAST_MONTH = today.replace(month=today.month - 1 if today.month > 1 else 12).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): @@ -82,10 +81,7 @@ def get_git_info(self, file_path): args = ["git", "log", "--reverse", "--pretty=format:%ai", file_path] creation_date = check_output(args).decode("utf-8").split("\n")[0] last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") - git_info = { - "creation_date": creation_date or LAST_MONTH, - "last_modified_date": last_modified_date or TODAY - } + git_info = {"creation_date": creation_date or LAST_MONTH, "last_modified_date": last_modified_date or TODAY} print(git_info) # Get the authors and their contributions count using get_github_usernames_from_file function From 7fd8a28004177e14c0284d49856a3473c276ebaa Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:41:22 +0100 Subject: [PATCH 07/15] Default Author --- plugin/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/main.py b/plugin/main.py index 6ad62a2..c4407e9 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -86,7 +86,6 @@ def get_git_info(self, file_path): "creation_date": creation_date or LAST_MONTH, "last_modified_date": last_modified_date or TODAY } - print(git_info) # Get the authors and their contributions count using get_github_usernames_from_file function if self.config["add_authors"]: From 3d634be8f0a36b31ff0675e6f1d7b33e662b83a1 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Wed, 29 Jan 2025 18:42:12 +0000 Subject: [PATCH 08/15] Auto-format by https://ultralytics.com/actions --- plugin/main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index c4407e9..9e83235 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -1,9 +1,9 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license import json +from datetime import datetime from pathlib import Path from subprocess import check_output -from datetime import datetime from bs4 import BeautifulSoup from mkdocs.config import config_options @@ -15,10 +15,9 @@ get_youtube_video_ids, ) - today = datetime.now() -TODAY = today.strftime('%Y-%m-%d %H:%M:%S +0000') -LAST_MONTH = today.replace(month=today.month-1 if today.month > 1 else 12).strftime('%Y-%m-%d %H:%M:%S +0000') +TODAY = today.strftime("%Y-%m-%d %H:%M:%S +0000") +LAST_MONTH = today.replace(month=today.month - 1 if today.month > 1 else 12).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): @@ -82,10 +81,7 @@ def get_git_info(self, file_path): args = ["git", "log", "--reverse", "--pretty=format:%ai", file_path] creation_date = check_output(args).decode("utf-8").split("\n")[0] last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") - git_info = { - "creation_date": creation_date or LAST_MONTH, - "last_modified_date": last_modified_date or TODAY - } + git_info = {"creation_date": creation_date or LAST_MONTH, "last_modified_date": last_modified_date or TODAY} # Get the authors and their contributions count using get_github_usernames_from_file function if self.config["add_authors"]: From 0d3c8c855e92eaaf0b0d09b66025ba9f030566f1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:45:26 +0100 Subject: [PATCH 09/15] Default Author --- plugin/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index 9e83235..fc85fd4 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -17,7 +17,7 @@ today = datetime.now() TODAY = today.strftime("%Y-%m-%d %H:%M:%S +0000") -LAST_MONTH = today.replace(month=today.month - 1 if today.month > 1 else 12).strftime("%Y-%m-%d %H:%M:%S +0000") +LAST_YEAR = today.replace(month=today.year - 1).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): @@ -81,7 +81,10 @@ def get_git_info(self, file_path): args = ["git", "log", "--reverse", "--pretty=format:%ai", file_path] creation_date = check_output(args).decode("utf-8").split("\n")[0] last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") - git_info = {"creation_date": creation_date or LAST_MONTH, "last_modified_date": last_modified_date or TODAY} + git_info = { + "creation_date": creation_date or LAST_YEAR, + "last_modified_date": last_modified_date or TODAY, + } # Get the authors and their contributions count using get_github_usernames_from_file function if self.config["add_authors"]: From b7edd0aa54ee7ed3bbada69428a1ad0f359a906c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:48:37 +0100 Subject: [PATCH 10/15] Default Author --- plugin/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/main.py b/plugin/main.py index fc85fd4..6928f85 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -17,7 +17,7 @@ today = datetime.now() TODAY = today.strftime("%Y-%m-%d %H:%M:%S +0000") -LAST_YEAR = today.replace(month=today.year - 1).strftime("%Y-%m-%d %H:%M:%S +0000") +LAST_YEAR = today.replace(year=today.year - 1).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): From b9085aa56b718594375d658a9cf9d62cb1a55f5c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:49:58 +0100 Subject: [PATCH 11/15] Default Author --- plugin/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index 6928f85..a8fe60c 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -16,8 +16,8 @@ ) today = datetime.now() -TODAY = today.strftime("%Y-%m-%d %H:%M:%S +0000") -LAST_YEAR = today.replace(year=today.year - 1).strftime("%Y-%m-%d %H:%M:%S +0000") +DEFAULT_CREATION_DATE = today.strftime("%Y-%m-%d %H:%M:%S +0000") +DEFAULT_MODIFIED_DATE = today.replace(year=today.year - 1).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): @@ -82,8 +82,8 @@ def get_git_info(self, file_path): creation_date = check_output(args).decode("utf-8").split("\n")[0] last_modified_date = check_output(["git", "log", "-1", "--pretty=format:%ai", file_path]).decode("utf-8") git_info = { - "creation_date": creation_date or LAST_YEAR, - "last_modified_date": last_modified_date or TODAY, + "creation_date": creation_date or DEFAULT_CREATION_DATE, + "last_modified_date": last_modified_date or DEFAULT_MODIFIED_DATE, } # Get the authors and their contributions count using get_github_usernames_from_file function From e74270145163f3cf7f39cf611ac9170ccee77d58 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:50:58 +0100 Subject: [PATCH 12/15] Default Author --- plugin/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index a8fe60c..849b2f7 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -1,7 +1,7 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license import json -from datetime import datetime +from datetime import datetime, timedelta from pathlib import Path from subprocess import check_output @@ -16,8 +16,8 @@ ) today = datetime.now() -DEFAULT_CREATION_DATE = today.strftime("%Y-%m-%d %H:%M:%S +0000") -DEFAULT_MODIFIED_DATE = today.replace(year=today.year - 1).strftime("%Y-%m-%d %H:%M:%S +0000") +DEFAULT_CREATION_DATE = (today - timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S +0000") +DEFAULT_MODIFIED_DATE = (today - timedelta(days=30)).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): From 3d0375117b8c476f39ad42be2137760cd4a58f3c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:51:09 +0100 Subject: [PATCH 13/15] Default Author --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 68bc17f..7695c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +.idea # PyInstaller # Usually these files are written by a python script from a template From db2f55efea637278a06820212e9df36898d6615f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:54:06 +0100 Subject: [PATCH 14/15] Default Author --- plugin/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/main.py b/plugin/main.py index 849b2f7..7f05468 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -17,7 +17,7 @@ today = datetime.now() DEFAULT_CREATION_DATE = (today - timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S +0000") -DEFAULT_MODIFIED_DATE = (today - timedelta(days=30)).strftime("%Y-%m-%d %H:%M:%S +0000") +DEFAULT_MODIFIED_DATE = (today - timedelta(days=45)).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin): From cfaaaa6abb54fa9200f625916de871368628305c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 29 Jan 2025 19:54:16 +0100 Subject: [PATCH 15/15] Default Author --- plugin/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/main.py b/plugin/main.py index 7f05468..a943fb7 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -17,7 +17,7 @@ today = datetime.now() DEFAULT_CREATION_DATE = (today - timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S +0000") -DEFAULT_MODIFIED_DATE = (today - timedelta(days=45)).strftime("%Y-%m-%d %H:%M:%S +0000") +DEFAULT_MODIFIED_DATE = (today - timedelta(days=40)).strftime("%Y-%m-%d %H:%M:%S +0000") class MetaPlugin(BasePlugin):