Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foundation Site Blog Fixes #69

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/foundation/app/(Site)/blog/[slug]/BlogPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default async function BlogPost({ post }: PostProps) {
.filter(Boolean);

return (
<article className="mx-auto mb-32 mt-4 flex max-w-screen-xl flex-col">
<article className="mx-auto mb-32 mt-4 flex max-w-screen-xl flex-col items-start">
<Link href={SANITY_SCHEMA_URL.POST} prefetch>
<Button
data-testid={ButtonDataTestId.Back_To_Blog}
Expand All @@ -57,7 +57,11 @@ export default async function BlogPost({ post }: PostProps) {
mobileImagePosition="below"
/>
<div className="mt-6 flex flex-row justify-center gap-12 md:mt-12">
<PortableText body={body} className="max-w-screen-md" wrapperComponent="section" />
<PortableText
body={body}
className={cn(headings.length && 'max-w-screen-md')}
wrapperComponent="section"
/>
{headings.length ? (
<HeadingOutline headings={headings} title={blogDictionary('inThisArticle')} />
) : null}
Expand Down
4 changes: 2 additions & 2 deletions apps/foundation/app/(Site)/blog/[slug]/HeadingOutline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type HeadingOutlineProps = {

export default function HeadingOutline({ title, headings }: HeadingOutlineProps) {
return (
<nav className="wrap sticky top-12 mt-7 hidden h-max w-max max-w-[25vw] lg:block">
<nav className="wrap sticky top-12 hidden h-max w-max max-w-[25vw] lg:block">
<Typography variant="h2" className="mb-3">
{title}
</Typography>
Expand All @@ -32,7 +32,7 @@ export default function HeadingOutline({ title, headings }: HeadingOutlineProps)
onClick={() => {
scrollToHeading(heading);
}}
className={cn(navlinkVariants({ active: false }), 'w-full text-wrap text-start')}
className={cn(navlinkVariants({ active: false }), 'w-max text-wrap text-start')}
>
{heading}
</button>
Expand Down
3 changes: 3 additions & 0 deletions apps/foundation/app/(Site)/blog/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { getInitialSiteDataForSSR } from '@/lib/sanity/sanity-server';
import type { Metadata, ResolvingMetadata } from 'next';
import { generateSanityMetadata } from '@session/sanity-cms/lib/metadata';
import { client } from '@/lib/sanity/sanity.client';
import { generateRssFeed } from '@/lib/rss';

export async function generateMetadata(_: object, parent: ResolvingMetadata): Promise<Metadata> {
const { settings } = await getInitialSiteDataForSSR();

await generateRssFeed();

return settings.blogSeo
? await generateSanityMetadata(client, {
seo: settings.blogSeo,
Expand Down
8 changes: 5 additions & 3 deletions apps/foundation/app/(Site)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export default async function BlogGridPage() {
<ReadMoreText />
</PostInfoBlock>
</Link>
<Typography variant="h2" className="mt-12">
{blogDictionary('morePosts')}
</Typography>
{rest?.length ? (
<Typography variant="h2" className="mt-12">
{blogDictionary('morePosts')}
</Typography>
) : null}
<div className="mt-4 grid grid-cols-1 gap-12 md:mt-8 md:grid-cols-3">
{rest.map((post, index) => (
<Link
Expand Down
7 changes: 7 additions & 0 deletions apps/foundation/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRevalidateHandler } from '@session/sanity-cms/api/revalidate';
import { SANITY_SCHEMA_URL } from '@/lib/constants';
import { generateRssFeed } from '@/lib/rss';

const SANITY_REVALIDATE_SECRET = process.env.SANITY_REVALIDATE_SECRET!;
if (!SANITY_REVALIDATE_SECRET) {
Expand All @@ -12,4 +13,10 @@ export const { POST } = createRevalidateHandler({
page: SANITY_SCHEMA_URL.PAGE,
post: SANITY_SCHEMA_URL.POST,
},
rssGenerators: [
{
_type: 'post',
generateRssFeed,
},
],
});
2 changes: 1 addition & 1 deletion apps/foundation/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
priority: 1,
},
...pages.map((page) => ({
url: `${BASE_URL}${page.slug.current}`,
url: `${BASE_URL}/${page.slug.current}`,
lastModified: page._updatedAt,
changeFrequency: 'weekly' as const,
priority: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion apps/foundation/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Social, SocialLink } from '@session/ui/components/SocialLinkList';

export const BASE_URL = `https://session.foundation/`;
export const BASE_URL = `https://session.foundation`;

export const SOCIALS = {
[Social.Github]: { name: Social.Github, link: 'https://github.com/oxen-io/websites' },
Expand Down
73 changes: 73 additions & 0 deletions apps/foundation/lib/rss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import fs from 'fs';
import { generateXMLFromObject } from '@session/sanity-cms/lib/xml';
import { getSiteSettings } from '@session/sanity-cms/queries/getSiteSettings';
import { client } from '@/lib/sanity/sanity.client';
import { BASE_URL, SANITY_SCHEMA_URL } from '@/lib/constants';
import { getPostsWithMetadata } from '@session/sanity-cms/queries/getPosts';

export async function generateRssFeed() {
const posts = await getPostsWithMetadata({ client });

posts.sort((a, b) => {
const dateA = new Date(a.date ?? a._updatedAt);
const dateB = new Date(b.date ?? b._updatedAt);

return dateB.getTime() - dateA.getTime();
});

const date = new Date();

const settings = await getSiteSettings({ client });

const copyright = settings?.copyright;

const title =
settings?.blogSeo?.metaTitle ??
settings?.blogSeo?.openGraph?.title ??
settings?.seo?.metaTitle ??
settings?.seo?.openGraph?.title;

const json = {
rss: {
'@version': '2.0',
'@xmlns:atom': 'http://www.w3.org/2005/Atom',
'@xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
'@xmlns:dc': 'http://purl.org/dc/elements/1.1/',
channel: {
title,
description: 'RSS feed for Session Technology Foundation updates.',
link: BASE_URL,
image: {
url: `${BASE_URL}/images/logo.svg`,
title: `Session Technology Foundation updates`,
link: BASE_URL,
},
generator: 'mini-xml for Node.js',
lastBuildDate: date,
'atom:link': {
'@href': `${BASE_URL}/rss.xml`,
'@rel': 'self',
'@type': 'application/rss+xml',
},
copyright,
item: posts.map((post) => {
const url = `${BASE_URL}${SANITY_SCHEMA_URL.POST}${post.slug.current}`;
return {
title: post.title.trim(),
description: post.summary.trim(),
link: url,
guid: {
'@isPermaLink': 'true',
'#text': url,
},
pubDate: new Date(post.date ?? post._updatedAt),
};
}),
},
},
};

const feed = generateXMLFromObject(json, { pretty: true, indentSpaces: 2 });

fs.writeFileSync('./public/rss.xml', feed);
}
17 changes: 17 additions & 0 deletions apps/foundation/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ const nextConfig = {
images: {
remotePatterns: [{ hostname: 'cdn.sanity.io' }],
},
async rewrites() {
return [
...[
'/rss',
'/feed',
'/feed.xml',
'/blog.xml',
'/blog/rss',
'/blog/feed',
'/blog/rss.xml',
'/blog/feed.xml',
].map((source) => ({
source,
destination: '/rss.xml',
})),
];
},
};

export default withNextIntl(withPlaiceholder(nextConfig));
Loading