feat: add ability to scrape youtube video
This commit is contained in:
@ -1,30 +1,10 @@
|
||||
export const isYoutubeLink = (link: string) => {
|
||||
try {
|
||||
const url = new URL(link);
|
||||
return ["youtu.be", "youtube.com"].includes(url.hostname);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function extractYoutubeId(link: string) {
|
||||
const url = new URL(link);
|
||||
if (url.searchParams.has("v")) {
|
||||
const id = url.searchParams.get("v");
|
||||
|
||||
if (id?.length && id.length > 4) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
return url.pathname.replace(/^\//, "");
|
||||
}
|
||||
import { extractYoutubeId } from "@lib/string.ts";
|
||||
|
||||
export const YoutubePlayer = ({ link }: { link: string }) => {
|
||||
const id = extractYoutubeId(link);
|
||||
return (
|
||||
<iframe
|
||||
class="mb-6"
|
||||
width="100%"
|
||||
height="400px"
|
||||
src={`https://www.youtube-nocookie.com/embed/${id}`}
|
||||
|
Reference in New Issue
Block a user