Skip to content

Commit

Permalink
Fix authors bug (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored Feb 20, 2024
1 parent 38bf7bc commit b434011
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
27 changes: 10 additions & 17 deletions plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class MetaPlugin(BasePlugin):
("add_keywords", config_options.Type(bool, default=True)), # Add new argument for keywords
("add_share_buttons", config_options.Type(bool, default=True)), # Add new argument
("add_dates", config_options.Type(bool, default=True)), # Add dates section
("add_authors", config_options.Type(bool, default=True)), # Add authors section
("add_json_ld", config_options.Type(bool, default=True)), # Add JSON-LD structured data
("add_authors", config_options.Type(bool, default=False)), # Add authors section
("add_json_ld", config_options.Type(bool, default=False)), # Add JSON-LD structured data
)

@staticmethod
def get_git_info(file_path):
def get_git_info(self, file_path):
"""Retrieves git information including hash, date, and branch."""
file_path = Path(file_path).resolve()

# Get the creation date
Expand All @@ -41,12 +41,14 @@ def get_git_info(file_path):
git_info["last_modified_date"] = last_modified_date

# Get the authors and their contributions count using get_github_usernames_from_file function
authors_info = get_github_usernames_from_file(file_path)
git_info["authors"] = [(author, info["url"], info["changes"]) for author, info in authors_info.items()]
if self.config["add_authors"]:
authors_info = get_github_usernames_from_file(file_path)
git_info["authors"] = [(author, info["url"], info["changes"]) for author, info in authors_info.items()]

return git_info

def on_page_content(self, content, page, config, files):
"""Processes page content with optional enhancements like images and keywords."""
if not self.config["enabled"]:
return content

Expand Down Expand Up @@ -75,13 +77,15 @@ def on_page_content(self, content, page, config, files):

@staticmethod
def insert_content(soup, content_to_insert):
"""Enhances page content with images and meta descriptions if not already present."""
if comments_header := soup.find("h2", id="__comments"):
comments_header.insert_before(content_to_insert)
# Fallback: append the content to the md-typeset div if the comments header is not found
if md_typeset := soup.select_one(".md-content__inner"):
md_typeset.append(content_to_insert)

def on_post_page(self, output, page, config):
"""Enhances page content with images and meta descriptions if not already present."""
if not config["site_url"]:
print(
"WARNING - mkdocs-ultralytics-plugin: Please add a 'site_url' to your mkdocs.yml "
Expand Down Expand Up @@ -195,17 +199,6 @@ def on_post_page(self, output, page, config):
twitter_share_link = f"https://twitter.com/intent/tweet?url={page_url}"
linkedin_share_link = f"https://www.linkedin.com/shareArticle?url={page_url}"

# share_buttons = f'''
# <div class="share-buttons" style="text-align: right;">
# <a href="javascript:void(0);" onclick="window.open('{twitter_share_link}', 'TwitterShare', 'width=550,height=680,menubar=no,toolbar=no'); return false;" style="margin-right: 20px;">
# <i class="fa-brands fa-twitter fa-xl"></i> Tweet
# </a>
# <a href="javascript:void(0);" onclick="window.open('{linkedin_share_link}', 'LinkedinShare', 'width=550,height=730,menubar=no,toolbar=no'); return false;">
# <i class="fa-brands fa-linkedin fa-xl"></i> Share
# </a>
# </div>
# '''

share_buttons = f"""
<style>
.share-button:hover {{
Expand Down
2 changes: 1 addition & 1 deletion plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_github_username_from_email(email, local_cache, file_path="", verbose=Tru

# If the email ends with "@users.noreply.github.com", parse the username directly
if email.endswith("@users.noreply.github.com"):
username = email.split("+")[1].split("@")[0]
username = email.split("+")[-1].split("@")[0]
local_cache[email] = username # save the username in the local cache for future use
return username

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mkdocs-ultralytics-plugin"
version = "0.0.43"
version = "0.0.44"
description = "An MkDocs plugin that provides Ultralytics Docs customizations at https://docs.ultralytics.com."
readme = "README.md"
requires-python = ">=3.8"
Expand Down

0 comments on commit b434011

Please sign in to comment.