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

youtube shortcode is not working. #371

Closed
soumendrak opened this issue Aug 28, 2024 · 5 comments
Closed

youtube shortcode is not working. #371

soumendrak opened this issue Aug 28, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@soumendrak
Copy link
Contributor

Bug Report

I have used an YT shortcode which was working fine withe Apollo theme. However, in tabi I am facing issue.

<div class="youtube-embed">
    <iframe width="100%" height="600" src="https://www.youtube.com/embed/{{id}}" frameborder="0"
        allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
        allowfullscreen></iframe>
</div>

I have added this file, youtube.html under templates/shortcode

Environment

Zola version: 0.19.1
tabi version or commit: 2.13.0

Expected Behavior

Youtube video should have come as an embedding.

Current Behavior

Tell us what happens instead of the expected behavior.
image
link

Step to Reproduce

  1. Create the youtube shortcode html file.
  2. Use it in any markdown post file
Live streaming links of the conference:
{{ youtube(id="GPkWL-9akQc") }}
  1. Build and serve the site
@welpo
Copy link
Owner

welpo commented Aug 28, 2024

Hi Soumendra!

Did you allow youtube connections through the CSP?

@github-staff github-staff deleted a comment from tankeco Aug 28, 2024
@github-staff github-staff deleted a comment from soumendrak Aug 28, 2024
@soumendrak
Copy link
Contributor Author

Thanks @welpo for the precise solution. After making the following changes, it fixed the issue.

allowed_domains = [
    { directive = "font-src", domains = ["'self'", "data:"] },
    { directive = "img-src", domains = ["'self'", "https://*", "data:"] },
    { directive = "media-src", domains = ["'self'", "https://cdn.jsdelivr.net/"] },
    { directive = "script-src", domains = ["'self'"] },
    { directive = "style-src", domains = ["'self'"] },
-    { directive = "frame-src", domains = ["player.vimeo.com", "https://www.youtube-nocookie.com"] },
+    { directive = "frame-src", domains = ["player.vimeo.com", "https://www.youtube.com"] },
]

@welpo
Copy link
Owner

welpo commented Aug 28, 2024

Glad to hear!

The example CSP example uses youtube-nocookie for privacy reasons (and because it was the default shortcode built-in with Zola until some time ago).

You might want to modify your shortcode to use the youtube-nocookie URL. The old shortcode:

<div {% if class %}class="{{class}}"{% endif %}>
    <iframe src="https://www.youtube-nocookie.com/embed/{{id}}{% if playlist %}?list={{playlist}}{% endif %}{% if autoplay %}?autoplay=1{% endif %}" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>

@soumendrak
Copy link
Contributor Author

@welpo Thanks for this snippet. Is there any reason why Zola removed this shortcode?

@welpo
Copy link
Owner

welpo commented Aug 29, 2024

They were removed here: getzola/zola@a56e424

Reasoning:

The youtube one for example had been broken for a long time and no one really noticed. It's better to not have anything than something not tested/doesn't work. Most of them were only a couple of lines anyway.

I might add Vimeo/YouTube shortcodes to tabi and mention the CSP changes necessary to make them work on the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@welpo @soumendrak and others