diff --git a/.gitignore b/.gitignore index 39e7793..aa7d895 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ public/rss.xml public/atom*.xml public/images/placeholders/* !public/images/placeholders/.gitkeep + +public/rss/*.xml diff --git a/src/components/SEO/SEO.tsx b/src/components/SEO/SEO.tsx index a04a17c..c2513a2 100644 --- a/src/components/SEO/SEO.tsx +++ b/src/components/SEO/SEO.tsx @@ -18,6 +18,7 @@ type Metadata = { date?: string | null contentType?: LPE.PostType noIndex?: boolean + rssFileName?: string } const SITE_URL = getWebsiteUrl() @@ -36,6 +37,7 @@ export default function SEO({ date, contentType, noIndex = false, + rssFileName, }: Metadata) { const title = _title && _title.length @@ -75,12 +77,7 @@ export default function SEO({ - {noIndex && ( <> diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 1fc983d..577f49a 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,3 +1,4 @@ +import { LPERssFeed } from '@/services/rss.service' import { CustomNextPage, GetStaticProps } from 'next' import SEO from '../components/SEO/SEO' import { HomePage, HomePageProps } from '../containers/HomePage' @@ -9,7 +10,7 @@ type PageProps = Pick const Page: CustomNextPage = (props) => { return ( <> - + ) @@ -42,6 +43,11 @@ export const getStaticProps: GetStaticProps = async () => { const { data: tags = [] } = await strapiApi.getTopics() + const rss = new LPERssFeed('main') + await rss.init() + latest.data.forEach((post) => rss.addPost(post)) + await rss.save() + return { props: { data: { diff --git a/src/pages/podcasts/[showSlug]/index.tsx b/src/pages/podcasts/[showSlug]/index.tsx index cd2baa6..fcd42a4 100644 --- a/src/pages/podcasts/[showSlug]/index.tsx +++ b/src/pages/podcasts/[showSlug]/index.tsx @@ -1,5 +1,6 @@ import { SEO } from '@/components/SEO' import PodcastShowContainer from '@/containers/PodcastShowContainer' +import { LPERssFeed } from '@/services/rss.service' import { GetStaticPropsContext } from 'next' import { useRouter } from 'next/router' import { ReactNode } from 'react' @@ -37,6 +38,7 @@ const PodcastShowPage = ({ imageUrl={undefined} pagePath={getPostLink('podcast', { showSlug: showSlug as string })} tags={[]} + rssFileName={`${showSlug}.xml`} /> { showSlug: showSlug as string, }) + const rss = new LPERssFeed(showSlug as string, { + title: shows[0].title, + description: shows[0].descriptionText, + image: shows[0].logo.url, + language: 'en', + id: shows[0].id ?? (showSlug as string), + copyright: `All rights reserved ${new Date().getFullYear()}, ${ + shows[0].title + }`, + }) + await rss.init() + latestEpisodes.data.forEach((post: LPE.Post.Document) => rss.addPost(post)) + await rss.save() + return { props: { show: shows[0], diff --git a/src/services/rss.service.ts b/src/services/rss.service.ts index ad26841..edd0b8f 100644 --- a/src/services/rss.service.ts +++ b/src/services/rss.service.ts @@ -113,7 +113,7 @@ export class LPERssFeed { category: [ ...(post.type === 'article' ? [articleCategory] - : [showCategories[post.show!.id]]), + : [showCategories[post.showId as string]]), ...post.tags.map( (tag) => ({ diff --git a/src/services/strapi/transformers/utils.ts b/src/services/strapi/transformers/utils.ts index 2acade7..619a406 100644 --- a/src/services/strapi/transformers/utils.ts +++ b/src/services/strapi/transformers/utils.ts @@ -100,10 +100,10 @@ export const transformStrapiHtmlContent = async ({ const tagName = node.tagName.toLowerCase() const isFigure = tagName === 'figure' const isMedia = isFigure && !!node.querySelector('oembed') - const isImage = isFigure && !isMedia && !!node.querySelector('img') + const isImage = !!node.querySelector('img') const empty = node.text.length === 0 - if (!isFigure && empty) continue + if (!isFigure && !isImage && empty) continue blockIndex++ @@ -116,7 +116,8 @@ export const transformStrapiHtmlContent = async ({ const caption = text const alt = image.getAttribute('alt') || '' - const url = image.getAttribute('src') || '' + let url = image.getAttribute('src') || '' + url = url.slice(url.indexOf('/uploads/')) const width = parseInt(image.getAttribute('width') || '0', 10) const height = parseInt(image.getAttribute('height') || '0', 10) @@ -130,6 +131,9 @@ export const transformStrapiHtmlContent = async ({ alt: alt || caption, labels: [], order: blockIndex, + placeholder: isVercel() + ? getStrapiImageUrlBySize('thumbnail', url) + : await placeholderService.pixelate(url), url: url.startsWith('/') ? transformStrapiImageUrl(url) : url, footnotes, })