[bugfix,site][s]: replace YOUTUBE_REGEX

This commit is contained in:
khalilcodes 2022-06-21 15:32:21 +03:00
parent d284ea96ce
commit 3ecdf4cca2
4 changed files with 36 additions and 37 deletions

View File

@ -1,5 +1,5 @@
import Link from "next/link"
import { YOUTUBE_REGEX } from "../../lib/constants"
import { YOUTUBE_ID_REGEX } from "../../lib/constants"
export function Latest({ posts }) {
return (
@ -23,7 +23,7 @@ export function Latest({ posts }) {
<div className="flex-1 bg-slate-800 p-6 flex flex-col justify-between">
<div className="flex-1">
<p className="text-sm font-medium text-indigo-600 dark:text-yellow-500">
{youtube && YOUTUBE_REGEX.test(youtube) ? (
{youtube && YOUTUBE_ID_REGEX.test(youtube) ? (
<a target="_blank" rel="noopener" href={youtube} className="hover:underline">
Video
</a>) : <p>Article</p>}

View File

@ -3,13 +3,13 @@ import MdxContent from "./MdxContent";
import siteConfig from "../config/siteConfig";
import LiteYouTubeEmbed from "react-lite-youtube-embed";
import { YOUTUBE_REGEX, YOUTUBE_ID_REGEX } from "lib/constants";
import { YOUTUBE_ID_REGEX } from "lib/constants";
export default function MdxPage({ body, meta }) {
const { title, description, date, keywords, youtube, podcast, image, _raw } =
meta;
const youtubeId = youtube && YOUTUBE_REGEX.test(youtube) && youtube.match(YOUTUBE_ID_REGEX)[1]
const youtubeId = youtube && YOUTUBE_ID_REGEX.test(youtube) && youtube.match(YOUTUBE_ID_REGEX)[1]
const PodcastIcon = siteConfig.social.find((s) => s.name === "Podcast").icon;

View File

@ -1,4 +1,3 @@
export const YOUTUBE_REGEX = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
export const YOUTUBE_ID_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:\S*&)?vi?=|(?:embed|v|vi|user|shorts)\/))([^?&\"'>\s]+)/
export const TWITTER_REGEX = /^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)/;

View File

@ -1,6 +1,6 @@
import Link from "next/link";
import { allOtherPages } from "contentlayer/generated"
import { YOUTUBE_REGEX } from "lib/constants";
import { YOUTUBE_ID_REGEX } from "lib/constants";
export async function getStaticProps() {
const posts = allOtherPages
@ -39,7 +39,7 @@ export default function Notes({ posts }) {
<div className="flex-1 bg-slate-800 p-6 flex flex-col justify-between">
<div className="flex-1">
<p className="text-sm font-medium text-indigo-600 dark:text-yellow-500">
{youtube && YOUTUBE_REGEX.test(youtube)
{youtube && YOUTUBE_ID_REGEX.test(youtube)
? (<a target="_blank" rel="noopener" href={youtube} className="hover:underline">
Video
</a>)