Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(shortcodes): Add example repository badge #7915

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ Besides plugins, there are some utilities that build on top of MkDocs in order
to provide extended functionality, like for example support for versioning.

[Insiders]: insiders/index.md

### <!-- md:examplerepo --> – Example Repository

This symbol indicates that an example repository is available on GitHub.
1 change: 1 addition & 0 deletions docs/setup/setting-up-a-blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ __Check out our [blog], which is created with the new [built-in blog plugin]!__
<!-- md:version 9.2.0 -->
<!-- md:plugin -->
<!-- md:flag experimental -->
<!-- md:examplerepo create-blog -->

The built-in blog plugin adds support for building a blog from a folder of
posts, which are annotated with dates and other structured data. First, add the
Expand Down
1 change: 1 addition & 0 deletions docs/setup/setting-up-social-cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Social card of our [formatting] reference
<!-- md:version 8.5.0 -->
<!-- md:plugin -->
<!-- md:flag experimental -->
<!-- md:examplerepo create-social-card -->

The built-in social plugin automatically generate a custom preview image for
each page. Install all [dependencies for image processing] and add the
Expand Down
1 change: 1 addition & 0 deletions docs/setup/setting-up-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ documentation remain untouched.

<!-- md:version 7.0.0 -->
<!-- md:utility [mike] -->
<!-- md:examplerepo example-versioning -->

[mike] makes it easy to deploy multiple versions of your project documentation.
It integrates natively with Material for MkDocs and can be enabled via
Expand Down
12 changes: 12 additions & 0 deletions material/overrides/hooks/shortcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def replace(match: Match):
return _badge_for_version_insiders(args, page, files)
else:
return _badge_for_version(args, page, files)
elif type == "examplerepo": return _badge_for_example_repo(args, page, files)
elif type == "sponsors": return _badge_for_sponsors(page, files)
elif type == "flag": return flag(args, page, files)
elif type == "option": return option(args)
Expand Down Expand Up @@ -142,6 +143,17 @@ def _badge_for_version(text: str, page: Page, files: Files):
text = f"[{text}]({_resolve_path(path, page, files)})" if spec else ""
)

# Create badge for example repositories
def _badge_for_example_repo(args: str, page: Page, files: Files):
repo_name = args.strip()
icon_url = _resolve_path("conventions.md#experimental", page, files)
niclasheinz marked this conversation as resolved.
Show resolved Hide resolved
text_href = f"https://github.com/mkdocs-material/{repo_name}"
icon = "material-github"
return _badge(
icon=f"[:{icon}:]({icon_url} 'Example Repository')",
text=f"[{repo_name}]({text_href})"
)

# Create badge for version of Insiders
def _badge_for_version_insiders(text: str, page: Page, files: Files):
spec = text.replace("insiders-", "")
Expand Down
Loading