2024-07-17 10:56:36 -03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import posixpath
|
|
|
|
import re
|
|
|
|
|
|
|
|
from mkdocs.config.defaults import MkDocsConfig
|
|
|
|
from mkdocs.structure.files import File, Files
|
|
|
|
from mkdocs.structure.pages import Page
|
|
|
|
from re import Match
|
|
|
|
|
|
|
|
# very much stolen/based on https://github.com/squidfunk/mkdocs-material/blob/master/src/overrides/hooks/shortcodes.py
|
|
|
|
|
|
|
|
def on_page_markdown(markdown: str, *, page: Page, config: MkDocsConfig, files: Files):
|
|
|
|
# Replace callback
|
|
|
|
def replace(match: Match):
|
|
|
|
type, args = match.groups()
|
|
|
|
args = args.strip()
|
|
|
|
if type == "version": return _version_block(args)
|
2024-11-29 11:17:45 -03:00
|
|
|
if type == "inline_version": return _inline_version_block(args)
|
|
|
|
elif type == "pro": return _pro_ad()
|
|
|
|
elif type == "inline_pro": return _inline_pro_ad()
|
|
|
|
elif type == "featpro": return _pro_feat_ad()
|
2024-07-17 10:56:36 -03:00
|
|
|
elif type == "templates": return _templates_ad()
|
2024-11-28 08:47:20 -03:00
|
|
|
elif type == "alpha": return _alpha_block()
|
2024-07-17 10:56:36 -03:00
|
|
|
|
|
|
|
# Otherwise, raise an error
|
|
|
|
raise RuntimeError(f"Unknown shortcode: {type}")
|
|
|
|
|
|
|
|
# Find and replace all external asset URLs in current page
|
|
|
|
return re.sub(
|
|
|
|
r"<!-- md:(\w+)(.*?) -->",
|
|
|
|
replace, markdown, flags = re.I | re.M
|
|
|
|
)
|
|
|
|
|
2024-11-29 11:17:45 -03:00
|
|
|
def _pro_feat_ad():
|
2024-09-03 19:57:07 -03:00
|
|
|
return "".join([
|
|
|
|
f"<div class=\"admonition example\">",
|
|
|
|
f"<p class=\"admonition-title\">GoReleaser Pro</p>",
|
|
|
|
f"<p>This feature is exclusively available with <a href=\"/pro/\">GoReleaser Pro</a>.</p>",
|
|
|
|
f"</div>"
|
|
|
|
])
|
|
|
|
|
2024-11-29 11:17:45 -03:00
|
|
|
def _pro_ad():
|
2024-07-17 10:56:36 -03:00
|
|
|
return "".join([
|
|
|
|
f"<div class=\"admonition example\">",
|
|
|
|
f"<p class=\"admonition-title\">GoReleaser Pro</p>",
|
2024-09-03 19:57:07 -03:00
|
|
|
f"<p>One or more features are exclusively available with <a href=\"/pro/\">GoReleaser Pro</a>.</p>",
|
2024-07-17 10:56:36 -03:00
|
|
|
f"</div>"
|
|
|
|
])
|
|
|
|
|
2024-11-29 11:17:45 -03:00
|
|
|
def _inline_pro_ad():
|
|
|
|
return f"This feature is only available in GoReleaser Pro."
|
|
|
|
|
2024-07-17 10:56:36 -03:00
|
|
|
def _version_block(text: str):
|
2024-11-29 11:17:45 -03:00
|
|
|
if "unreleased" in text:
|
|
|
|
tag = text.removesuffix("-unreleased")
|
|
|
|
return f"> :material-tag-outline: This will be available in the next release ({tag}). Stay tuned!"
|
2024-11-29 00:17:45 -03:00
|
|
|
return f"> :material-tag-outline: Since <a href=\"/blog/goreleaser-{text}\">{text}</a>."
|
2024-07-17 10:56:36 -03:00
|
|
|
|
2024-11-29 11:17:45 -03:00
|
|
|
def _inline_version_block(text: str):
|
|
|
|
if "unreleased" in text:
|
|
|
|
tag = text.removesuffix("-unreleased")
|
|
|
|
return f"Since: {tag} (unreleased)"
|
|
|
|
return f"Since: {text}"
|
|
|
|
|
2024-11-28 08:47:20 -03:00
|
|
|
def _alpha_block():
|
2024-11-29 00:17:45 -03:00
|
|
|
return f"> :material-flask-outline: This feature is currently in alpha. Feedback is greatly appreciated!"
|
2024-11-28 08:47:20 -03:00
|
|
|
|
2024-07-17 10:56:36 -03:00
|
|
|
def _templates_ad():
|
|
|
|
return "".join([
|
|
|
|
f"<div class=\"admonition tip\">",
|
|
|
|
f"<p class=\"admonition-title\">Tip</p>",
|
2024-09-03 19:57:07 -03:00
|
|
|
f"<p>Discover more about the <a href=\"/customization/templates/\">name template engine</a>.</p>",
|
2024-07-17 10:56:36 -03:00
|
|
|
f"</div>"
|
|
|
|
])
|