-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from dmlb/youtube-page-fixes
Youtube page fixes
- Loading branch information
Showing
7 changed files
with
130 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,70 +1,49 @@ | ||
<script lang="ts"> | ||
export let title: string | ||
export let videoId: string | ||
export let channelInfo: any // Contains channel data for the video uploader | ||
// export let realeasedDatetime: string; | ||
import type { YoutubeChannel, YoutubeVideo } from "$lib/interfaces" | ||
const thumbnail = `https://i.ytimg.com/vi/${videoId}/default.jpg` | ||
const { channelCustomName, channelName } = channelInfo | ||
export let video: YoutubeVideo | ||
export let channelInfo: YoutubeChannel // Contains channel data for the video uploader | ||
function trimString(str: string, maxLength: number): string { | ||
/** | ||
* Trims a string to a max length, finding a space character in order to end the string. | ||
*/ | ||
// Check if the length of the input string is already less than or equal to maxLength | ||
if (str.length <= maxLength) { | ||
return str | ||
} | ||
// Trim the string to maxLength characters | ||
let trimmedString = str.substring(0, maxLength) | ||
// Find the last occurrence of a space character in the trimmed string | ||
let lastIndex = trimmedString.lastIndexOf(" ") | ||
// If a space character is found, trim the string again to remove everything after the space character | ||
if (lastIndex !== -1) { | ||
trimmedString = trimmedString.substring(0, lastIndex) | ||
} | ||
// Add an ellipsis to indicate that the string has been trimmed | ||
return trimmedString + "..." | ||
} | ||
const { title, videoId, videoPic, videoPicH, videoPicW } = video | ||
const { channelCustomName, channelName, channelPic } = channelInfo | ||
</script> | ||
|
||
<a | ||
href="https://youtu.be/{videoId}" | ||
class="lg:hover:scale-105" | ||
target="_blank" | ||
rel="noreferrer" | ||
<div | ||
class="flex flex-col w-full flex-row gap-2 bg-white dark:bg-zinc-800 md:flex md:w-auto md:h-auto shadow-md dark:shadow-zinc-900 rounded-lg lg:hover:scale-105" | ||
> | ||
<div | ||
class="flex w-full flex-row bg-white dark:bg-zinc-800 md:block md:w-auto md:h-auto shadow-md dark:shadow-zinc-900 rounded-lg" | ||
> | ||
<img | ||
loading="lazy" | ||
class="rounded-l-lg md:rounded-bl-none md:rounded-t-lg md:w-full" | ||
height="90" | ||
width="120" | ||
src={thumbnail} | ||
alt="{title} thumbnail" | ||
/> | ||
<div class="mx-2"> | ||
<!-- Don't trim title on mobile, trim on desktop (probably a better way to do this with media queries) --> | ||
<div | ||
class="md:block text-sm font-semibold text-zinc-900 dark:text-zinc-100" | ||
> | ||
{@html title} | ||
</div> | ||
<a | ||
class="text-sm text-zinc-700 dark:text-zinc-400" | ||
href="https://www.youtube.com/{channelCustomName}" | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{@html channelName}</a | ||
> | ||
<a href="https://youtu.be/{videoId}" target="_blank" rel="noreferrer"> | ||
{#if videoPic} | ||
<img | ||
loading="lazy" | ||
class="rounded-l-lg md:rounded-bl-none md:rounded-t-lg md:w-full" | ||
height={videoPicH} | ||
width={videoPicW} | ||
src={videoPic} | ||
alt="" | ||
/> | ||
{/if} | ||
<div | ||
class="md:block text-sm font-semibold text-zinc-900 dark:text-zinc-100" | ||
> | ||
{@html title} | ||
</div> | ||
</div> | ||
</a> | ||
</a> | ||
<a | ||
class="text-sm text-zinc-700 dark:text-zinc-400 inline-flex gap-1 items-center" | ||
href="https://www.youtube.com/{channelCustomName}" | ||
target="_blank" | ||
rel="noreferrer" | ||
aria-label="{channelName} youtube channel (in a new tab)" | ||
> | ||
{#if channelPic} | ||
<img | ||
class="rounded-full" | ||
src={channelPic} | ||
height="18" | ||
width="18" | ||
alt="" | ||
/> | ||
{/if} | ||
{channelName} | ||
</a> | ||
</div> |