-
Notifications
You must be signed in to change notification settings - Fork 64
YouTube player for markdown #1291
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
074798b
Fixed YouTube Player
nikoshell 58d394d
Merge branch 'ep2025' into ep2025-yt
nikoshell b4d938e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b49e2b0
Update src/components/ui/YouTube.astro
nikoshell 1f2f4ef
Merge branch 'ep2025' into ep2025-yt
nikoshell 62bc74f
Fix astro check errors
nikoshell 5e5f8b1
Add flag EP_FAST_BUILD
nikoshell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
EP_SESSIONS_API="https://static.europython.eu/programme/ep2025/releases/current/sessions.json" | ||
EP_SPEAKERS_API="https://static.europython.eu/programme/ep2025/releases/current/speakers.json" | ||
EP_SCHEDULE_API="https://static.europython.eu/programme/ep2025/releases/current/schedule.json" | ||
EP_FAST_BUILD="true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,78 @@ | ||
--- | ||
import { YouTube as Player } from "@astro-community/astro-embed-youtube"; | ||
|
||
type Props = { | ||
id?: string; | ||
class?: string; | ||
[key: string]: any; | ||
import 'lite-youtube-embed/src/lite-yt-embed.css'; | ||
import liteJS from 'lite-youtube-embed/src/lite-yt-embed.js?url'; | ||
|
||
const urlPattern = | ||
/(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:\/\/)??(?:w{3}\.)??(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/|shorts\/)??([A-Za-z0-9-_]{11})(?:[^\s<>]*)(?=(\s*))\4(?:<\/a>)??(?=(\s*))\5/; | ||
|
||
function urlMatcher(url: string): string | undefined { | ||
const match = url.match(urlPattern); | ||
return match?.[3]; | ||
} | ||
|
||
export interface Props extends astroHTML.JSX.HTMLAttributes { | ||
id: string; | ||
poster?: string; | ||
posterQuality?: 'max' | 'high' | 'default' | 'low'; | ||
params?: string; | ||
playlabel?: string; | ||
} | ||
|
||
const { | ||
id, | ||
poster, | ||
posterQuality = 'default', | ||
title, | ||
class: userClass = '', | ||
...attrs | ||
} = Astro.props; | ||
|
||
const attrId = attrs.id || ''; | ||
...attrs | ||
} = Astro.props as Props; | ||
|
||
const defaultClass = 'border-4 border-white rounded-lg shadow-lg'; | ||
const className = `${defaultClass} ${userClass}`.trim(); | ||
|
||
const idRegExp = /^[A-Za-z0-9-_]{11}$/; | ||
|
||
function extractID(idOrUrl: string) { | ||
if (idRegExp.test(idOrUrl)) return idOrUrl; | ||
return urlMatcher(idOrUrl); | ||
} | ||
|
||
const videoid = extractID(id); | ||
const posterFile = | ||
{ | ||
max: 'maxresdefault', | ||
high: 'sddefault', | ||
default: 'hqdefault', | ||
low: 'default', | ||
}[posterQuality] || 'hqdefault'; | ||
nikoshell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const posterURL = | ||
poster || `https://i.ytimg.com/vi/${videoid}/${posterFile}.jpg`; | ||
const href = `https://youtube.com/watch?v=${videoid}`; | ||
--- | ||
|
||
<Player id={attrId} class={className} {...attrs} /> | ||
<lite-youtube | ||
{videoid} | ||
{title} | ||
data-title={title} | ||
{...attrs} | ||
class={className} | ||
style=`background-image: url('${posterURL}');` | ||
> | ||
<a {href} class="lty-playbtn "> | ||
<span class="lyt-visually-hidden">{attrs.playlabel || 'Play'}</span> | ||
</a> | ||
</lite-youtube> | ||
|
||
<script is:inline type="module" src={liteJS}></script> | ||
|
||
<style is:global> | ||
lite-youtube > iframe { | ||
all: unset !important; | ||
width: 100% !important; | ||
height: 100% !important; | ||
position: absolute !important; | ||
inset: 0 !important; | ||
border: 0 !important; | ||
} | ||
</style> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.