Skip to content

Commit

Permalink
Default Author
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jan 29, 2025
1 parent c13d6b1 commit 7a74c2b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +15,8 @@
get_youtube_video_ids,
)

TODAY = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000')


class MetaPlugin(BasePlugin):
"""
Expand All @@ -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
Expand Down Expand Up @@ -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()
]
Expand Down

0 comments on commit 7a74c2b

Please sign in to comment.