diff --git a/packages/studiocms_blog/src/components/PageList.astro b/packages/studiocms_blog/src/components/PageList.astro index f1c1eda88..5d0a386a1 100644 --- a/packages/studiocms_blog/src/components/PageList.astro +++ b/packages/studiocms_blog/src/components/PageList.astro @@ -1,9 +1,9 @@ --- import { pages } from '@studiocms/blog:context'; import { FormattedDate } from 'studiocms:components'; -import type { pageDataReponse } from 'studiocms:helpers/contentHelper'; import { CustomImage } from 'studiocms:imageHandler/components'; import { pathWithBase } from 'studiocms:lib'; +import type { CombinedPageData } from 'studiocms:sdk/types'; const blogRouteFullPath = pages.get('/blog/[...slug]'); @@ -15,7 +15,7 @@ function getBlogRoute(slug: string) { } interface Props { - blogPageList: pageDataReponse[]; + blogPageList: CombinedPageData[]; } const { blogPageList } = Astro.props; diff --git a/packages/studiocms_blog/src/pages/blog/[...slug].astro b/packages/studiocms_blog/src/pages/blog/[...slug].astro index b10b4d97c..96a557c99 100644 --- a/packages/studiocms_blog/src/pages/blog/[...slug].astro +++ b/packages/studiocms_blog/src/pages/blog/[...slug].astro @@ -1,8 +1,8 @@ --- import { PostHeader } from '@studiocms:blog/components'; import { BlogLayout } from '@studiocms:blog/layouts'; -import { contentHelper } from 'studiocms:helpers/contentHelper'; import { StudioCMSRenderer } from 'studiocms:renderer'; +import studioCMS_SDK from 'studiocms:sdk'; import { name } from '../../../package.json'; // Get the slug from the URL @@ -14,15 +14,22 @@ if (!slug) { } // Fetch the blog post content -const { id, title, description, heroImage, publishedAt, updatedAt, content } = await contentHelper( - slug, - name -); + +const post = await studioCMS_SDK.GET.databaseEntry.pages.bySlug(slug, name); // If no content is found, redirect to 404 -if (!id) { +if (!post) { return new Response(null, { status: 404 }); } + +const { title, description, heroImage, publishedAt, updatedAt, defaultContent } = post; + +// If no content is found, redirect to 404 +if (!defaultContent) { + return new Response(null, { status: 404 }); +} + +const content = defaultContent.content || ''; ---
diff --git a/packages/studiocms_blog/src/pages/blog/index.astro b/packages/studiocms_blog/src/pages/blog/index.astro index 16b231790..56402e193 100644 --- a/packages/studiocms_blog/src/pages/blog/index.astro +++ b/packages/studiocms_blog/src/pages/blog/index.astro @@ -3,7 +3,7 @@ import config from '@studiocms/blog:config'; import { pages } from '@studiocms/blog:context'; import { PageList, RSSIcon } from '@studiocms:blog/components'; import { BlogLayout } from '@studiocms:blog/layouts'; -import { getPageList } from 'studiocms:helpers/contentHelper'; +import studioCMS_SDK from 'studiocms:sdk'; import { name } from '../../../package.json'; // Set the title and description @@ -14,15 +14,10 @@ const description: string = configDescription || 'Blog Index'; const showRSSFeed: boolean = blogIndex?.showRSSFeed || true; // Get all pages -const pageList = await getPageList(); +const blogPageList = await studioCMS_SDK.GET.packagePages(name); // Get the RSS feed URL const rssPath = pages.get('/rss.xml'); - -// Get all blog pages and sort by published date -const blogPageList = pageList - .filter((page) => page.package === name) - .sort((a, b) => Date.parse(b.publishedAt.toString()) - Date.parse(a.publishedAt.toString())); ---
diff --git a/packages/studiocms_blog/src/pages/rss.xml.ts b/packages/studiocms_blog/src/pages/rss.xml.ts index 2a671377c..77a5c582f 100644 --- a/packages/studiocms_blog/src/pages/rss.xml.ts +++ b/packages/studiocms_blog/src/pages/rss.xml.ts @@ -1,14 +1,11 @@ import config from '@studiocms/blog:config'; import { pages } from '@studiocms/blog:context'; -import { contentHelper, getPageList, getSiteConfig } from 'studiocms:helpers/contentHelper'; import { pathWithBase } from 'studiocms:lib'; -import { StudioCMSRenderer } from 'studiocms:renderer'; -import rss from '@astrojs/rss'; +import studioCMS_SDK from 'studiocms:sdk'; +import rss, { type RSSFeedItem } from '@astrojs/rss'; import type { APIContext } from 'astro'; import { name } from '../../package.json'; -import { experimental_AstroContainer as AstroContainer } from 'astro/container'; - const blogRouteFullPath = pages.get('/blog/[...slug]'); function getBlogRoute(slug: string) { @@ -20,41 +17,25 @@ function getBlogRoute(slug: string) { export async function GET(context: APIContext) { // Get Config from Studio Database - const studioCMSConfig = await getSiteConfig(); + const studioCMSConfig = await studioCMS_SDK.GET.database.config(); // Set Title, Description, and Site - const title = config.title ?? studioCMSConfig.title; - const description = config.description ?? studioCMSConfig.description; + const title = config.title ?? studioCMSConfig?.title ?? 'Blog'; + const description = config.description ?? studioCMSConfig?.description ?? 'Blog'; const site = context.site ?? 'https://example.com'; // Get all Posts from Studio Database - const unorderedPosts = await getPageList(); - - // Order Posts by Published Date - const orderedPosts = unorderedPosts - .filter((page) => page.package === name) - .sort((a, b) => Date.parse(b.publishedAt.toString()) - Date.parse(a.publishedAt.toString())); - - // Render Known Posts - const items = await Promise.all( - orderedPosts.map(async ({ slug, title, description, publishedAt: pubDate, package: pkg }) => { - const { content: fetchedContent } = await contentHelper(slug, pkg); - const container = await AstroContainer.create(); - const renderedContent = await container.renderToString(StudioCMSRenderer, { - props: { content: fetchedContent }, - }); - - const content = renderedContent - .replace(//, '') - .replace(//, '') - .replace(/<\/html>/, '') - .trim(); - - const link = pathWithBase(getBlogRoute(slug)); - - return { title, description, pubDate, content, link }; - }) - ); + const orderedPosts = await studioCMS_SDK.GET.packagePages(name); + + const items: RSSFeedItem[] = orderedPosts.map((post) => { + return { + title: post.title, + description: post.description, + pubDate: post.publishedAt, + link: pathWithBase(getBlogRoute(post.slug)), + categories: post.categories.map(({ name }) => name), + }; + }); return rss({ title, description, site, items }); } diff --git a/packages/studiocms_frontend/src/routes/[...slug].astro b/packages/studiocms_frontend/src/routes/[...slug].astro index 888e19698..328034b24 100644 --- a/packages/studiocms_frontend/src/routes/[...slug].astro +++ b/packages/studiocms_frontend/src/routes/[...slug].astro @@ -1,6 +1,6 @@ --- -import { contentHelper } from 'studiocms:helpers/contentHelper'; import { StudioCMSRenderer } from 'studiocms:renderer'; +import studioCMS_SDK from 'studiocms:sdk'; import Layout from '../components/Layout.astro'; const { slug } = Astro.params; @@ -9,11 +9,19 @@ if (!slug) { return new Response(null, { status: 404 }); } -const { title, description, heroImage, content, id } = await contentHelper(slug); +const page = await studioCMS_SDK.GET.databaseEntry.pages.bySlug(slug, 'studiocms'); -if (!id) { +if (!page) { return new Response(null, { status: 404 }); } + +const { title, description, heroImage, defaultContent } = page; + +if (!defaultContent) { + return new Response(null, { status: 404 }); +} + +const content = defaultContent.content || ''; --- diff --git a/packages/studiocms_frontend/src/routes/index.astro b/packages/studiocms_frontend/src/routes/index.astro index 0659ecce9..9da9538ea 100644 --- a/packages/studiocms_frontend/src/routes/index.astro +++ b/packages/studiocms_frontend/src/routes/index.astro @@ -1,13 +1,21 @@ --- -import { contentHelper } from 'studiocms:helpers/contentHelper'; import { StudioCMSRenderer } from 'studiocms:renderer'; +import studioCMS_SDK from 'studiocms:sdk'; import Layout from '../components/Layout.astro'; -const { title, description, heroImage, content, id } = await contentHelper('index'); +const index = await studioCMS_SDK.GET.databaseEntry.pages.bySlug('index', 'studiocms'); -if (!id) { +if (!index) { return new Response(null, { status: 404 }); } + +const { title, description, heroImage, defaultContent } = index; + +if (!defaultContent) { + return new Response(null, { status: 404 }); +} + +const content = defaultContent.content || ''; ---