Fix admin studio article preview always showing "moved" error
ArticlePage and NewsGrid called useContent() directly, bypassing the draft content SiteApp resolves for admin previews. Since /admin is rendered outside ContentProvider, this always returned an empty post list, so every article in the studio looked unpublished. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,15 +3,25 @@ import { useNavigate } from 'react-router-dom'
|
||||
import { formatPostDate, publishedPosts, useContent } from '../../cms/store'
|
||||
import { applyJsonLd, applyMeta, articleJsonLd } from '../../cms/seo'
|
||||
import { categoryMeta, splitAuthor } from './NewsGrid'
|
||||
import type { Post } from '../../cms/types'
|
||||
import type { Post, SiteContent } from '../../cms/types'
|
||||
|
||||
/**
|
||||
* A single article at /blog/<slug>. Rendered into the #pg-article container inside
|
||||
* the site markup, so it inherits the real nav, footer and enquiry modal — and the
|
||||
* white-section rule that makes the body copy readable.
|
||||
*/
|
||||
export default function ArticlePage({ slug, suppressMeta = false }: { slug: string; suppressMeta?: boolean }) {
|
||||
const content = useContent()
|
||||
export default function ArticlePage({
|
||||
slug,
|
||||
suppressMeta = false,
|
||||
content: contentProp,
|
||||
}: {
|
||||
slug: string
|
||||
suppressMeta?: boolean
|
||||
/** Admin preview: use the editor's draft rather than the published context. */
|
||||
content?: SiteContent
|
||||
}) {
|
||||
const publishedContent = useContent()
|
||||
const content = contentProp || publishedContent
|
||||
const navigate = useNavigate()
|
||||
|
||||
// Drafts are reachable by direct link so they can be reviewed before going live,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { POST_CATEGORIES, type Post, type PostCategory } from '../../cms/types'
|
||||
import { POST_CATEGORIES, type Post, type PostCategory, type SiteContent } from '../../cms/types'
|
||||
import { formatPostDate, publishedPosts, useContent } from '../../cms/store'
|
||||
|
||||
export const categoryMeta = (id: string) => POST_CATEGORIES.find((c) => c.id === id) || POST_CATEGORIES[0]
|
||||
@@ -48,8 +48,20 @@ function Card({ post, onOpen }: { post: Post; onOpen: (post: Post) => void }) {
|
||||
* The newsroom grid (/news) and the home page's latest-three strip. Both read the
|
||||
* same CMS post library, so publishing an article puts it everywhere it belongs.
|
||||
*/
|
||||
export default function NewsGrid({ limit, showFilters = true, heading }: { limit?: number; showFilters?: boolean; heading?: string }) {
|
||||
const content = useContent()
|
||||
export default function NewsGrid({
|
||||
limit,
|
||||
showFilters = true,
|
||||
heading,
|
||||
content: contentProp,
|
||||
}: {
|
||||
limit?: number
|
||||
showFilters?: boolean
|
||||
heading?: string
|
||||
/** Admin preview: use the editor's draft rather than the published context. */
|
||||
content?: SiteContent
|
||||
}) {
|
||||
const publishedContent = useContent()
|
||||
const content = contentProp || publishedContent
|
||||
const navigate = useNavigate()
|
||||
const [filter, setFilter] = useState<PostCategory | 'all'>('all')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user