Skip to content

Commit d2b1197

Browse files
committed
add schedule indiv for seo
1 parent 4c93304 commit d2b1197

4 files changed

Lines changed: 203 additions & 38 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Link from 'next/link';
2+
import Image from 'next/image';
3+
import { Post } from '@/models/post.model';
4+
5+
export default function ScheduleCard({ post }: { post: Post }): JSX.Element {
6+
let re = /(\w+).null - /;
7+
8+
return (
9+
<div className="flex justify-center">
10+
<div className="w-full lg:max-w-4xl">
11+
<div
12+
className="grid gap-2 p-4 transition-all rounded-md shadow-lg cursor-pointer dark:text-primary-50 dark:bg-basics-600 hover:shadow-2xl hover:scale-105 bg-basics-50"
13+
key={post._id}
14+
>
15+
<a
16+
href="https://twitch.tv/codingcatdev"
17+
target="blank"
18+
rel="noopener noreferrer"
19+
>
20+
<>
21+
<Image
22+
src={`${post?.coverPhoto?.public_id}`}
23+
alt={`Purrfect.dev hosted by Alex & Brittney with ${
24+
post?.guests && post?.guests?.length > 1 ? 'guests' : 'guest'
25+
} ${post?.guests?.map((guest) => guest.name)}`}
26+
width="480"
27+
height="270"
28+
layout="responsive"
29+
/>
30+
<div className="flex flex-col gap-1">
31+
<time
32+
dateTime={
33+
post?.recordingDate
34+
? new Date(post.recordingDate).toLocaleString()
35+
: ''
36+
}
37+
className="text-lg border-b-2 card-title border-b-primary-500"
38+
>
39+
{post?.recordingDate
40+
? new Date(post.recordingDate).toLocaleString()
41+
: ''}
42+
</time>
43+
<h2 className="font-sans bold lg:text-2xl">
44+
{post?.title?.replace(re, '')}
45+
</h2>
46+
<p className="text-lg font-thin">{post?.excerpt}</p>
47+
</div>
48+
</>
49+
</a>
50+
</div>
51+
</div>
52+
</div>
53+
);
54+
}

‎frontend/main/src/components/ScheduleCards.tsx‎

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ export default function ScheduleCards({
2020
className="grid gap-2 p-4 transition-all rounded-md shadow-lg cursor-pointer dark:text-primary-50 dark:bg-basics-600 hover:shadow-2xl hover:scale-105 bg-basics-50"
2121
key={post._id}
2222
>
23-
<a
24-
href="https://twitch.tv/codingcatdev"
25-
target="blank"
26-
rel="noopener noreferrer"
27-
>
28-
<>
23+
<Link href={`/schedule/${post.slug}`}>
24+
<a>
2925
<Image
3026
src={`${post?.coverPhoto?.public_id}`}
3127
alt={`Purrfect.dev hosted by Alex & Brittney with ${
@@ -37,26 +33,6 @@ export default function ScheduleCards({
3733
height="270"
3834
layout="responsive"
3935
/>
40-
{/* Individual guest images */}
41-
{/* <div className="flex gap-2">
42-
{post?.guests?.map((guest) => {
43-
return (
44-
<div className="w-20 h-20" key={guest.id}>
45-
<Image
46-
src={`/main-codingcatdev-photo/podcast-guest/${guest.twitter?.replace(
47-
'https://twitter.com/',
48-
''
49-
)}`}
50-
alt={guest.name}
51-
width="50"
52-
height="50"
53-
layout="responsive"
54-
className="w-20 h-20 rounded-full cursor-pointer"
55-
/>
56-
</div>
57-
);
58-
})}
59-
</div> */}
6036
<div className="flex flex-col gap-1">
6137
<time
6238
dateTime={
@@ -75,8 +51,8 @@ export default function ScheduleCards({
7551
</h2>
7652
<p className="text-lg font-thin">{post?.excerpt}</p>
7753
</div>
78-
</>
79-
</a>
54+
</a>
55+
</Link>
8056
</div>
8157
);
8258
})}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import {
2+
getSite,
3+
queryPurrfectStreamBySlug,
4+
queryPurrfectStreamByScheduled,
5+
} from '@/services/notion.server';
6+
import { NextSeo } from 'next-seo';
7+
import Layout from '@/layout/Layout';
8+
import { Site } from '@/models/site.model';
9+
import { Post, PostType } from '@/models/post.model';
10+
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
11+
import ScheduleUpper from '@/components/ScheduleUpper';
12+
import ScheduleCard from '@/components/ScheduleCard';
13+
14+
interface StaticParams {
15+
site: Site;
16+
post: Post;
17+
}
18+
19+
export const getStaticPaths: GetStaticPaths = async () => {
20+
const paths: { params: { slug: string } }[] = [];
21+
const scheduled = await queryPurrfectStreamByScheduled(10000);
22+
for (const p of scheduled.results as any) {
23+
if (p?.properties?.slug?.url) {
24+
paths.push({
25+
params: {
26+
slug: `${p?.properties?.slug?.url}`,
27+
},
28+
});
29+
}
30+
}
31+
return {
32+
paths,
33+
fallback: true,
34+
};
35+
};
36+
37+
export const getStaticProps: GetStaticProps<StaticParams> = async ({
38+
params,
39+
preview,
40+
previewData,
41+
}) => {
42+
const { slug } = params as any;
43+
44+
if (!slug) {
45+
return {
46+
notFound: true,
47+
};
48+
}
49+
const site = getSite();
50+
const scheduled = await queryPurrfectStreamByScheduled(
51+
undefined,
52+
undefined,
53+
slug
54+
);
55+
const post = scheduled?.results?.at(0) || null;
56+
57+
if (!post) {
58+
console.log('Schedule not found');
59+
return {
60+
notFound: true,
61+
};
62+
}
63+
64+
return {
65+
props: {
66+
site,
67+
post,
68+
},
69+
};
70+
};
71+
72+
export default function AuthorPage({
73+
site,
74+
post,
75+
}: InferGetStaticPropsType<typeof getStaticProps>) {
76+
return (
77+
<>
78+
<NextSeo
79+
title={post.title}
80+
description={post.excerpt}
81+
canonical={`https://codingcat.dev/${post._type}/${post.slug}`}
82+
openGraph={{
83+
type: 'website',
84+
locale: 'en_US',
85+
url: `https://codingcat.dev/${post._type}/${post.slug}`,
86+
title: post.title,
87+
description: post.excerpt,
88+
site_name: 'CodingCatDev',
89+
images: [
90+
{
91+
url: `https://media.codingcat.dev/image/upload/f_png,c_fit,w_1200,h_630${post?.coverPhoto?.public_id}`,
92+
width: 1200,
93+
height: 630,
94+
alt: post?.title,
95+
},
96+
{
97+
url: `https://media.codingcat.dev/image/upload/f_png${post?.coverPhoto?.public_id}`,
98+
alt: post?.title,
99+
},
100+
],
101+
}}
102+
></NextSeo>
103+
<Layout site={site}>
104+
<div className="flex flex-col gap-8 p-4 sm:p-10">
105+
<ScheduleUpper />
106+
<ScheduleCard post={post} />
107+
</div>
108+
</Layout>
109+
</>
110+
);
111+
}

‎frontend/main/src/services/notion.server.ts‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -766,28 +766,52 @@ export const queryPurrfectStreamByReleased = async (
766766

767767
export const queryPurrfectStreamByScheduled = async (
768768
page_size?: number,
769-
start_cursor?: string | null
769+
start_cursor?: string | null,
770+
slug?: string
770771
) => {
771772
if (skipNotion) {
772773
return {
773774
has_more: false,
774775
results: [],
775776
} as unknown as NotionPosts;
776777
}
777-
let raw = await notionClient.databases.query({
778-
database_id: config.purrfectStreamsDb,
779-
start_cursor: start_cursor ? start_cursor : undefined,
780-
page_size,
781-
filter: {
778+
let filter: any = {
779+
and: [
780+
{
781+
property: 'Status',
782+
select: {
783+
equals: 'Scheduled',
784+
},
785+
},
786+
{
787+
property: 'slug',
788+
url: {
789+
is_not_empty: true,
790+
},
791+
},
792+
],
793+
};
794+
795+
if (slug) {
796+
filter = {
782797
and: [
798+
...filter.and,
799+
783800
{
784-
property: 'Status',
785-
select: {
786-
equals: 'Scheduled',
801+
property: 'slug',
802+
url: {
803+
contains: slug,
787804
},
788805
},
789806
],
790-
},
807+
};
808+
}
809+
console.log(filter);
810+
let raw = await notionClient.databases.query({
811+
database_id: config.purrfectStreamsDb,
812+
start_cursor: start_cursor ? start_cursor : undefined,
813+
page_size,
814+
filter,
791815
sorts: [
792816
{
793817
property: 'Recording Date',

0 commit comments

Comments
 (0)