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

Added support for videos using a shortcode #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 12 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ def parse(cls, line: str, doc_path: "DocPath") -> Tuple[str, List[str]]:

for link in cls.get_links(line):
abs_url = link.abs_url(doc_path)
parsed = parsed.replace(
link.combined, f"[{link.title}]({abs_url}{link.header})"
)

if any(link.title.endswith(ext) for ext in (".webm", ".mp4")):
# use shortcode for videos
parsed = parsed.replace(
link.combined,
r"{{ " + f'video(url="{abs_url}", alt="{link.title}")' + r" }}",
)
else:
parsed = parsed.replace(
link.combined, f"[{link.title}]({abs_url}{link.header})"
)

linked.append(abs_url)

return parsed, linked
Expand Down
8 changes: 8 additions & 0 deletions zola/templates/shortcodes/video.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<video
controls
{% if autoplay %} autoplay {% endif %}
alt="{{alt}}"
src="{{config.base_url}}{{url}}"
width="100%"
height="auto"
></video>