|
| 1 | +--- |
| 2 | +import { stegaClean } from "@sanity/client/stega"; |
| 3 | +
|
| 4 | +interface Props { |
| 5 | + title: string; |
| 6 | + audioUrl?: string | null; |
| 7 | + youtube?: string | null; |
| 8 | +} |
| 9 | +
|
| 10 | +const { title, audioUrl, youtube } = Astro.props; |
| 11 | +
|
| 12 | +const src = stegaClean(audioUrl); |
| 13 | +const youtubeUrl = stegaClean(youtube); |
| 14 | +const cleanTitle = stegaClean(title) ?? ""; |
| 15 | +
|
| 16 | +const spotifyUrl = `https://open.spotify.com/search/codingcat.dev%20${encodeURIComponent(cleanTitle)}/episodes`; |
| 17 | +const appleUrl = |
| 18 | + "https://podcasts.apple.com/us/podcast/codingcat-dev-podcast/id1491655542"; |
| 19 | +
|
| 20 | +const buttonClass = |
| 21 | + "inline-flex items-center justify-center gap-2 rounded-md px-3 py-2 text-sm transition-colors hover:bg-accent hover:text-accent-foreground"; |
| 22 | +--- |
| 23 | + |
| 24 | +{ |
| 25 | + src && ( |
| 26 | + <div class="flex w-full flex-col flex-wrap items-center justify-start gap-2 border border-foreground p-2 sm:flex-row sm:gap-4 sm:p-4"> |
| 27 | + <h2 class="w-full text-center text-xl font-bold sm:text-start"> |
| 28 | + Listening Options |
| 29 | + </h2> |
| 30 | + {/* |
| 31 | + * A native audio element, not the floating persistent player — that |
| 32 | + * player is a React island and lands with the rest of the islands. |
| 33 | + * This keeps every episode playable in the meantime with no JS. |
| 34 | + */} |
| 35 | + <audio class="w-full sm:flex-1" controls preload="none" src={src}> |
| 36 | + <track kind="captions" /> |
| 37 | + </audio> |
| 38 | + <div class="flex gap-1"> |
| 39 | + <a |
| 40 | + href={spotifyUrl} |
| 41 | + target="_blank" |
| 42 | + rel="noreferrer noopener" |
| 43 | + class={buttonClass} |
| 44 | + aria-label="Search for this episode on Spotify" |
| 45 | + > |
| 46 | + <svg class="size-5" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"> |
| 47 | + <path d="M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0Zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.779-.179-.899-.539-.12-.421.18-.78.54-.9 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.301 1.02Zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2Zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.419 1.56-.299.421-1.02.599-1.559.3Z" /> |
| 48 | + </svg> |
| 49 | + <span class="sr-only">Listen on Spotify</span> |
| 50 | + </a> |
| 51 | + <a |
| 52 | + href={appleUrl} |
| 53 | + target="_blank" |
| 54 | + rel="noreferrer noopener" |
| 55 | + class={buttonClass} |
| 56 | + aria-label="Listen on Apple Podcasts" |
| 57 | + > |
| 58 | + <svg class="size-5" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"> |
| 59 | + <path d="M5.34 0A5.328 5.328 0 0 0 0 5.34v13.32A5.328 5.328 0 0 0 5.34 24h13.32A5.328 5.328 0 0 0 24 18.66V5.34A5.328 5.328 0 0 0 18.66 0Zm6.525 2.568c2.336 0 4.448.902 6.056 2.587 1.224 1.272 1.912 2.619 2.264 4.392.12.59.12 2.2.007 2.864a8.506 8.506 0 0 1-3.24 5.296c-.608.46-2.096 1.261-2.336 1.261-.088 0-.096-.091-.056-.46.072-.592.144-.715.48-.856.535-.224 1.447-.874 2.008-1.435a7.644 7.644 0 0 0 2.008-3.536c.208-.824.184-2.656-.048-3.504-.728-2.672-2.512-4.544-5.096-5.336-.784-.24-2.44-.336-3.384-.2-2.36.32-4.448 1.664-5.616 3.616-1.096 1.832-1.264 4.24-.44 6.224.6 1.448 1.784 2.792 3.048 3.472.28.152.352.28.416.72.048.36.024.44-.056.44-.048 0-.416-.16-.816-.36l-.024-.008c-1.472-.72-2.72-2.032-3.448-3.648-1.472-3.248-.688-7.02 1.928-9.352 1.72-1.53 3.88-2.28 6.344-2.28z" /> |
| 60 | + </svg> |
| 61 | + <span class="sr-only">Listen on Apple Podcasts</span> |
| 62 | + </a> |
| 63 | + {youtubeUrl && ( |
| 64 | + <a |
| 65 | + href={youtubeUrl} |
| 66 | + target="_blank" |
| 67 | + rel="noreferrer noopener" |
| 68 | + class={buttonClass} |
| 69 | + aria-label="Watch on YouTube" |
| 70 | + > |
| 71 | + <svg class="size-5" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"> |
| 72 | + <path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814ZM9.545 15.568V8.432L15.818 12l-6.273 3.568Z" /> |
| 73 | + </svg> |
| 74 | + <span class="sr-only">Watch on YouTube</span> |
| 75 | + </a> |
| 76 | + )} |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + ) |
| 80 | +} |
0 commit comments