Skip to content

Commit 4898399

Browse files
authored
Ultralytics Refactor https://ultralytics.com/actions (#129)
Automated merge of Ultralytics Code Refactor
1 parent db17ac0 commit 4898399

File tree

1 file changed

+84
-69
lines changed

1 file changed

+84
-69
lines changed

README.md

Lines changed: 84 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,65 @@
1-
<a href="https://www.ultralytics.com/" target="_blank"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>
1+
<a href="https://www.ultralytics.com/"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>
22

33
# 🚀 MkDocs Ultralytics Plugin
44

5-
Welcome to the MkDocs Ultralytics Plugin documentation! 📄 This powerful plugin enhances your MkDocs-generated documentation with advanced SEO optimizations, interactive social elements, and structured data support. It automates the generation of meta tags, incorporates social sharing features, and adds JSON-LD structured data to elevate user engagement and improve your Markdown project's visibility on the web.
5+
Welcome to the documentation for the MkDocs Ultralytics Plugin! 📄 This powerful plugin enhances your [MkDocs](https://www.mkdocs.org/)-generated documentation with advanced Search Engine Optimization (SEO) features, interactive social elements, and structured data support. It automates the generation of essential meta tags, incorporates social sharing capabilities, and adds [JSON-LD](https://json-ld.org/) structured data to elevate user engagement and improve your Markdown project's visibility on the web.
66

7-
[![PyPI version](https://badge.fury.io/py/mkdocs-ultralytics-plugin.svg)](https://badge.fury.io/py/mkdocs-ultralytics-plugin) [![Downloads](https://static.pepy.tech/badge/mkdocs-ultralytics-plugin)](https://www.pepy.tech/projects/mkdocs-ultralytics-plugin) [![Ultralytics Actions](https://github.com/ultralytics/mkdocs/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/mkdocs/actions/workflows/format.yml) <a href="https://discord.com/invite/ultralytics"><img alt="Discord" src="https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue"></a> <a href="https://community.ultralytics.com/"><img alt="Ultralytics Forums" src="https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue"></a> <a href="https://reddit.com/r/ultralytics"><img alt="Ultralytics Reddit" src="https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue"></a>
7+
[![PyPI version](https://badge.fury.io/py/mkdocs-ultralytics-plugin.svg)](https://badge.fury.io/py/mkdocs-ultralytics-plugin)
8+
[![Downloads](https://static.pepy.tech/badge/mkdocs-ultralytics-plugin)](https://www.pepy.tech/projects/mkdocs-ultralytics-plugin)
9+
[![Ultralytics Actions](https://github.com/ultralytics/mkdocs/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/mkdocs/actions/workflows/format.yml)
10+
[![Ultralytics Discord](https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue)](https://discord.com/invite/ultralytics)
11+
[![Ultralytics Forums](https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue)](https://community.ultralytics.com/)
12+
[![Ultralytics Reddit](https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue)](https://reddit.com/r/ultralytics)
813

9-
## 🌟 Features
14+
## Features
1015

11-
This plugin seamlessly integrates a variety of features into your MkDocs site:
16+
This plugin seamlessly integrates a variety of valuable features into your MkDocs site:
1217

13-
- **Meta Tag Generation**: Creates meta description and image tags from the first paragraph and image on the page.
14-
- **Keyword Customization**: Allows you to define meta keywords directly in your Markdown front matter.
15-
- **Social Media Optimization**: Generates Open Graph and Twitter meta tags for improved sharing on social platforms.
16-
- **Sharing Made Simple**: Inserts convenient share buttons for Twitter and LinkedIn at the end of your content.
17-
- **Git Insights**: Gathers and displays git commit information, including dates and authors, within the page footer.
18-
- **JSON-LD Support**: Adds structured data in JSON-LD format for better search engine integration.
19-
- **FAQ Parsing**: Automatically parses FAQ sections and includes them in the structured data.
20-
- **Customizable Styling**: Includes inline CSS for consistent styling across your documentation.
18+
- **Meta Tag Generation**: Automatically creates meta description and image tags using the first paragraph and image found on each page, crucial for SEO and social previews.
19+
- **Keyword Customization**: Allows you to define specific meta keywords directly within your Markdown front matter for targeted SEO.
20+
- **Social Media Optimization**: Generates [Open Graph](https://ogp.me/) and [Twitter Card](https://developer.x.com/en/docs/x-for-websites/cards/overview/summary-card-with-large-image) meta tags to ensure your content looks great when shared on social platforms.
21+
- **Simple Sharing**: Inserts convenient share buttons for Twitter and LinkedIn at the end of your content, encouraging readers to share.
22+
- **Git Insights**: Gathers and displays [Git](https://git-scm.com/) commit information, including update dates and authors, directly within the page footer for transparency.
23+
- **JSON-LD Support**: Adds structured data in JSON-LD format, helping search engines understand your content better and potentially enabling rich results.
24+
- **FAQ Parsing**: Automatically parses FAQ sections (if present) and includes them in the structured data for enhanced search visibility.
25+
- **Customizable Styling**: Includes optional inline CSS to maintain consistent styling for plugin elements across your documentation, aligning with themes like [MkDocs Material](https://squidfunk.github.io/mkdocs-material/).
2126

22-
## 🛠 Installation
27+
## 🛠 Installation
2328

24-
Getting started with the MkDocs Ultralytics Plugin is easy! Install it via [pip](https://pypi.org/project/mkdocs-ultralytics-plugin/) with the following command:
29+
Getting started with the MkDocs Ultralytics Plugin is straightforward. Install it via [pip](https://pypi.org/project/pip/) using the following command:
2530

2631
```bash
2732
pip install mkdocs-ultralytics-plugin
2833
```
2934

3035
## 💻 Usage
3136

32-
To enable the plugin in your MkDocs configuration, simply add it under the `plugins` section in your `mkdocs.yml` file:
37+
To activate the plugin within your MkDocs project, add it to the `plugins` section of your `mkdocs.yml` configuration file:
3338

3439
```yaml
3540
plugins:
36-
- mkdocstrings
37-
- search
38-
- ultralytics
41+
- mkdocstrings # Example of another plugin
42+
- search # Example of another plugin
43+
- ultralytics # Add the Ultralytics plugin here
3944
```
4045
41-
## ⚙️ Plugin Arguments
46+
## ⚙️ Configuration Arguments
4247
43-
The plugin supports several configuration arguments to tailor its behavior to your needs:
48+
The plugin offers several configuration arguments to customize its behavior according to your project's requirements:
4449
45-
- `verbose`: Toggles verbose output. Useful for debugging. (default: `True`)
46-
- `enabled`: Toggles plugin activation. (default: `True`)
47-
- `default_image`: Provides a fallback image URL if none is found in your content. (default: `None`)
48-
- `default_author`: GitHub author email to use if no author is found for pages. (default: `None`)
49-
- `add_desc`: Controls the generation of meta description tags. (default: `True`)
50-
- `add_image`: Manages meta image tag generation. (default: `True`)
51-
- `add_keywords`: Allows meta keyword tag generation. (default: `True`)
52-
- `add_share_buttons`: Adds or removes social share buttons. (default: `True`)
53-
- `add_authors`: Includes author and updated date information in the content footer. (default: `False`)
54-
- `add_json_ld`: Adds JSON-LD structured data to the page. (default: `False`)
55-
- `add_css`: Includes inline CSS for styling. (default: `True`)
50+
- `verbose` (bool): Enables or disables detailed console output during the build process. Useful for debugging. Default: `True`.
51+
- `enabled` (bool): Globally enables or disables the plugin. Default: `True`.
52+
- `default_image` (str | None): Specifies a fallback image URL to use for meta tags if no image is found within the page content. Default: `None`.
53+
- `default_author` (str | None): Sets a default GitHub author email to use if Git author information cannot be retrieved for a page. Default: `None`.
54+
- `add_desc` (bool): Controls whether meta description tags are automatically generated. Default: `True`.
55+
- `add_image` (bool): Controls whether meta image tags (Open Graph, Twitter) are automatically generated. Default: `True`.
56+
- `add_keywords` (bool): Controls whether meta keyword tags are generated based on front matter. Default: `True`.
57+
- `add_share_buttons` (bool): Determines if social media share buttons (Twitter, LinkedIn) are added to the page content. Default: `True`.
58+
- `add_authors` (bool): Controls the display of author and last updated date information in the content footer based on Git history. Default: `False`.
59+
- `add_json_ld` (bool): Enables the generation and injection of JSON-LD structured data into the page's head. Default: `False`.
60+
- `add_css` (bool): Determines if the plugin's inline CSS styles are included for elements like share buttons. Default: `True`.
5661

57-
Include these arguments under the `ultralytics` plugin entry in your `mkdocs.yml`:
62+
You can include these arguments under the `ultralytics` entry in your `mkdocs.yml` file like this:
5863

5964
```yaml
6065
plugins:
@@ -63,84 +68,94 @@ plugins:
6368
- ultralytics:
6469
verbose: True
6570
enabled: True
66-
default_image: "https://example.com/default-image.png"
67-
default_author: "you@company.com"
71+
default_image: "https://www.ultralytics.com/images/social.png" # Example default image
72+
default_author: "git@ultralytics.com" # Example default author
6873
add_desc: True
6974
add_image: True
7075
add_keywords: True
7176
add_share_buttons: True
72-
add_authors: False
73-
add_json_ld: False
77+
add_authors: False # Disabled by default
78+
add_json_ld: False # Disabled by default
7479
add_css: True
7580
```
7681

77-
## 🧩 How it works
82+
## 🧩 How It Works
7883

79-
Here's a breakdown of the plugin's inner workings:
84+
Heres a brief overview of the plugin's core functionalities:
8085

81-
### Meta Description
86+
### Meta Description Generation
8287

83-
When `add_desc` is on, the plugin plucks the first paragraph from your Markdown and turns it into a `<meta name="description">` tag within the `<head>` of your page.
88+
When `add_desc` is enabled, the plugin extracts the first paragraph from your Markdown content and uses it to generate a `<meta name="description">` tag within the `<head>` section of the corresponding HTML page. This helps search engines and users understand the page's content at a glance.
8489

85-
### Meta Image
90+
### Meta Image Tagging
8691

87-
Enabled by `add_image`, the first available image in the Markdown is assigned as `<meta property="og:image">` and `<meta property="twitter:image">` tags. If no image is detected, `default_image` steps in.
92+
If `add_image` is active, the plugin identifies the first image referenced in the Markdown source. This image URL is then used to populate the `<meta property="og:image">` and `<meta property="twitter:image">` tags. If no image is detected on the page, the URL provided in `default_image` (if set) is used as a fallback.
8893

89-
### Meta Keywords
94+
### Meta Keyword Integration
9095

91-
Manually specify meta keywords in the Markdown front matter to inject a `<meta name="keywords">` tag into the `<head>` of your page.
96+
By defining keywords in the Markdown front matter (e.g., `keywords: machine learning, computer vision, mkdocs`), and with `add_keywords` enabled, the plugin injects a corresponding `<meta name="keywords">` tag into the page's `<head>`.
9297

93-
### Share Buttons
98+
### Social Share Buttons
9499

95-
Engage `add_share_buttons`, and voila! Twitter and LinkedIn sharing buttons appear, inviting users to spread the word about your content.
100+
Activating `add_share_buttons` automatically appends pre-styled Twitter and LinkedIn sharing buttons to the bottom of your main content area, making it easy for readers to share your documentation.
96101

97-
### Git Dates and Authors
102+
### Git Information Display
98103

99-
With `add_dates` and `add_authors`, the plugin fetches and flaunts the git commit timestamp and author names at the bottom of your page, keeping readers informed.
104+
When `add_authors` is enabled, the plugin leverages Git history to retrieve the commit timestamp and author(s) for each page. This information is then displayed at the bottom of the page, providing context on when the content was last updated and by whom.
100105

101106
## 💡 Plugin Code Insight
102107

103-
The `MetaPlugin` class within `plugin.py` is the heart of the plugin, orchestrating the metadata and feature insertions:
108+
The core logic resides within the `MetaPlugin` class in `plugin.py`. This class hooks into the MkDocs build process to modify page content and metadata.
104109

105110
```python
106-
# Our MkDocs plugin inherits features from the BasePlugin available in mkdocs
111+
# Import the base class for MkDocs plugins
107112
from mkdocs.plugins import BasePlugin
108113
109114
110-
# The MetaPlugin class holds the core functionality
115+
# Define the MetaPlugin class inheriting from BasePlugin
111116
class MetaPlugin(BasePlugin):
112-
# Acts on the page content to generate meta tags
117+
# This method runs after the Markdown is converted to HTML,
118+
# but before the template is rendered.
119+
# It's used here primarily to extract information like the first paragraph or image.
113120
def on_page_content(self, content, page, config, files):
114-
# ... (omitted code handling meta description and image generation)
115-
# Comments could further explain code (but are omitted for brevity)
116-
return content
117-
118-
# Alters the final page output to include the new meta tags
121+
# Logic to find the first paragraph for meta description
122+
# Logic to find the first image for meta image tags
123+
# ... (details omitted for brevity)
124+
# The modified or extracted data is often stored for later use.
125+
return content # Return the original content, as modifications happen later
126+
127+
# This method runs after the page template has been rendered.
128+
# It allows modification of the final HTML output.
119129
def on_post_page(self, output, page, config):
120-
# ... (omitted code that injects generated meta tags into the output)
121-
# Additional comments could describe processing steps
122-
return output
130+
# Logic to inject generated meta tags (description, image, keywords) into <head>
131+
# Logic to add share buttons HTML to the end of the content area
132+
# Logic to add author/date footer HTML
133+
# Logic to add JSON-LD script tag to <head>
134+
# Logic to add inline CSS if enabled
135+
# ... (details omitted for brevity)
136+
return output # Return the modified HTML output
123137
```
124138

139+
This structure allows the plugin to analyze content and then inject the necessary HTML elements and metadata into the final output effectively. Check the source code for the full implementation details.
140+
125141
## 🤝 Contribute
126142

127-
Join in on the collaboration! 🤗 The success of Ultralytics' open-source initiatives springs from the vibrant contributions of our community. Whether you're fixing bugs, adding features, warming up our discussions, or sharing your Ultralytics project tale, [check out](https://docs.ultralytics.com/help/contributing/) how you can be part of the journey. Filling out our [survey](https://www.ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey) is another great way to share your feedback. We are deeply thankful 🙇‍♂️ for each contributor's time and efforts!
143+
Collaboration fuels innovation! 🤗 The success of Ultralytics' open-source projects, including this plugin, thrives on community contributions. We welcome your involvement, whether it's fixing bugs, proposing new features, improving documentation, engaging in discussions, or sharing how you use Ultralytics tools.
128144

129-
<!-- A visual tribute to our contributors! -->
145+
Please see our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for more details on how you can make a difference. Filling out our short [Survey](https://www.ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey) also provides valuable feedback. We sincerely appreciate 🙇‍♂️ every contribution!
130146

131-
<a href="https://github.com/ultralytics/yolov5/graphs/contributors">
132-
<img width="100%" src="https://github.com/ultralytics/assets/raw/main/im/image-contributors.png" alt="Ultralytics open-source contributors"></a>
147+
[![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png)](https://github.com/ultralytics/ultralytics/graphs/contributors)
133148

134149
## 📜 License
135150

136-
Ultralytics projects come with two licensing flavors:
151+
Ultralytics provides two licensing options to accommodate different use cases:
137152

138-
- **AGPL-3.0 License**: This license fosters open collaboration and knowledge sharing, making it a perfect match for students and hobbyists. For specifics, check the [LICENSE](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) file.
139-
- **Enterprise License**: When it comes to commercial endeavors, this license gets things rolling by allowing Ultralytics software and AI models to be woven into your business offerings without the AGPL-3.0's open-source constraints. For commercial integrations, please explore our [Ultralytics Licensing](https://www.ultralytics.com/license) options.
153+
- **AGPL-3.0 License**: Ideal for students, researchers, and enthusiasts, this [OSI-approved](https://opensource.org/license/agpl-v3) license promotes open collaboration and knowledge sharing. See the [LICENSE](https://github.com/ultralytics/mkdocs/blob/main/LICENSE) file for details.
154+
- **Enterprise License**: Designed for commercial applications, this license allows seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. If your project requires an Enterprise License, please visit [Ultralytics Licensing](https://www.ultralytics.com/license).
140155

141156
## ✉️ Connect with Us
142157

143-
Have you stumbled upon a glitch, or do you have a splendid feature idea? Pop over to [GitHub Issues](https://github.com/ultralytics/mkdocs/issues) to drop us a line! Also, join our [Discord](https://discord.com/invite/ultralytics) and [Reddit](https://www.reddit.com/r/ultralytics/) for buzzing discussions, insights, and tips around our shared ML journeys.
158+
Encountered a bug or have an idea for a new feature? Please visit [GitHub Issues](https://github.com/ultralytics/mkdocs/issues) to report problems or suggest enhancements. For broader discussions, questions, and community support related to Ultralytics projects, join our vibrant [Discord](https://discord.com/invite/ultralytics) server and check out the [Ultralytics Reddit](https://www.reddit.com/r/ultralytics/?rdt=34950).
144159

145160
<br>
146161
<div align="center">

0 commit comments

Comments
 (0)