Skip to content
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
302 changes: 221 additions & 81 deletions .agents/skills/migrate-strapi-content/SKILL.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions apps/strapi/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ STRAPI_PREVIEW_ENABLED=true

# Shared secret for frontend and backend that enables draft mode.
STRAPI_PREVIEW_SECRET=your-secret-key

# ----- Frontend revalidation -----

# Shared secret with the Next.js app for triggering on-demand revalidation.
# Must match `STRAPI_REVALIDATE_SECRET` in apps/ui/.env.local.
STRAPI_REVALIDATE_SECRET=your-revalidate-secret
3 changes: 2 additions & 1 deletion apps/strapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"react-router-dom": "^6.0.0",
"strapi-plugin-config-sync": "2.1.0",
"styled-components": "^6.0.0",
"vitest": "catalog:"
"vitest": "catalog:",
"zod": "^4.3.6"
},
"devDependencies": {
"@types/node": "catalog:",
Expand Down
7 changes: 7 additions & 0 deletions apps/strapi/src/admin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { StrapiApp } from "@strapi/strapi/admin"

import "@repo/design-system/styles.css"

import DataRevalidate from "./extensions/DataRevalidate"
import InternalJobs from "./extensions/InternalJobs"

export default {
Expand All @@ -13,5 +14,11 @@ export default {
name: "InternalJobs",
Component: InternalJobs,
})
app
.getPlugin("content-manager")
.injectComponent("editView", "right-links", {
name: "DataRevalidate",
Component: DataRevalidate,
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import { Button } from "@strapi/design-system"
import {
getFetchClient,
unstable_useContentManagerContext,
useNotification,
useQueryParams,
} from "@strapi/strapi/admin"
import { useMemo, useState } from "react"

import {
REVALIDATE_COLLECTIONS,
type RevalidateCollectionConfig,
} from "../../../revalidate/config"

type ContentManagerContext = {
model?: string
uid?: string
form?: {
values?: Record<string, unknown>
initialValues?: Record<string, unknown>
}
}

type RevalidateAction = {
label: string
successMessage: string
errorMessage: string
payload: {
uid: string
fullPaths?: string[]
tags?: string[]
locale?: string | null
}
}

const parseString = (value: unknown): string | null => {
if (typeof value !== "string") {
return null
}

const normalized = value.trim()

return normalized.length > 0 ? normalized : null
}

/**
* Action map for the per-uid "Revalidate cache" button. Path-based actions
* mirror the synthesized routes in `documentMiddlewares/revalidate.ts`; tag-only
* actions cover single types and embedded collection types.
*/
function buildAction(
config: RevalidateCollectionConfig,
slug: string | null,
fullPath: string | null,
locale: string | null
): RevalidateAction | null {
const uid = config.uid
const tags = config.tags ?? []

if (config.mode === "tag-revalidate") {
return {
label: "Revalidate cache",
successMessage: "Revalidated cache.",
errorMessage: "Failed to revalidate cache.",
payload: { uid, tags: [`strapi:${uid}`, ...tags] },
}
}

if (uid === "api::page.page") {
if (!fullPath) {
return null
}

return {
label: "Revalidate cache",
successMessage: `Revalidated page cache at "${fullPath}".`,
errorMessage: "Failed to revalidate page cache.",
payload: {
uid,
fullPaths: [fullPath],
locale,
tags: tags.length > 0 ? tags : undefined,
},
}
}

const builder = config.pathBuilder
if (builder) {
const built = builder({ slug }, locale ?? undefined)

if (!built) {
return null
}

const pathCandidates = Array.isArray(built) ? built : [built]
const fullPaths = pathCandidates
.filter((value): value is string => typeof value === "string")
.map((value) => value.trim())
.filter((value) => value.length > 0)

if (fullPaths.length === 0) {
return null
}

const path = fullPaths[0] ?? "/"

return {
label: "Revalidate cache",
successMessage: `Revalidated cache at "${path}".`,
errorMessage: "Failed to revalidate cache.",
payload: {
uid,
fullPaths,
locale,
tags: tags.length > 0 ? tags : undefined,
},
}
}

return null
}

function DataRevalidateButton() {
const [isLoading, setIsLoading] = useState(false)
const [{ query }] = useQueryParams<{
locale?: unknown
plugins?: { i18n?: { locale?: unknown } }
}>()
const { post } = getFetchClient()
const { toggleNotification } = useNotification()
const ctx = unstable_useContentManagerContext() as ContentManagerContext
const uid = parseString(ctx?.model ?? ctx?.uid)

const fullPath = useMemo(() => {
const values = ctx?.form?.values ?? ctx?.form?.initialValues

return parseString(values?.fullPath)
}, [ctx?.form?.initialValues, ctx?.form?.values])

const slug = useMemo(() => {
const values = ctx?.form?.values ?? ctx?.form?.initialValues

return parseString(values?.slug)
}, [ctx?.form?.initialValues, ctx?.form?.values])

const locale = useMemo(() => {
return (
parseString(query?.plugins?.i18n?.locale) ?? parseString(query?.locale)
)
}, [query])

const action = useMemo(() => {
if (!uid) {
return null
}

const config = REVALIDATE_COLLECTIONS.find((entry) => entry.uid === uid)
if (!config) {
return null
}

return buildAction(config, slug, fullPath, locale)
}, [fullPath, locale, slug, uid])

if (!action) {
return null
}

const runRevalidate = async () => {
if (isLoading) {
return
}

setIsLoading(true)

try {
await post("/api/revalidate", action.payload)
toggleNotification({
type: "success",
message: action.successMessage,
})
} catch (error) {
console.error(`Failed to revalidate cache for ${uid}:`, error)
toggleNotification({
type: "danger",
message: action.errorMessage,
})
} finally {
setIsLoading(false)
}
}

return (
<Button
variant="danger-light"
fullWidth
onClick={runRevalidate}
loading={isLoading}
disabled={isLoading}
>
{action.label}
</Button>
)
}

export default DataRevalidateButton
7 changes: 7 additions & 0 deletions apps/strapi/src/admin/extensions/DataRevalidate/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DataRevalidateButton from "./DataRevalidateButton"

function DataRevalidate() {
return <DataRevalidateButton />
}

export default DataRevalidate
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"regex": "^[a-z0-9-]+$"
},
"description": {
"type": "text",
"type": "richtext",
"pluginOptions": {
"i18n": {
"localized": true
Expand Down
24 changes: 20 additions & 4 deletions apps/strapi/src/api/blog-post/content-types/blog-post/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,38 @@
"sections": {
"type": "dynamiczone",
"components": [
"sections.section-header",
"sections.faq-section",
"sections.how-it-works",
"sections.section-header",
"sections.two-columns-benefits",
"sections.two-column-grid",
"cards.feature-card",
"cards.content-card",
"cards.case-study-card",
"media.image",
"media.image-gallery",
"media.video",
"media.embed",
"media.brand-logo-grid",
"testimonials.quote",
"forms.newsletter",
"blog.callout",
"blog.related-posts",
"blog.editors-picks",
"blog.resource-cta",
"forms.newsletter",
"sections.testimonies",
"sections.meet-the-team",
"media.video",
"sections.hero",
"sections.hero-home",
"sections.feature-card-grid",
"forms.hubspot-form",
"forms.hubspot-form-ssr",
"forms.conversion",
"migration.data-sink",
"media.embed",
"sections.cta-banner",
"sections.community-banner",
"sections.comparator-grid",
"sections.disclaimer",
"sections.richtext"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,34 @@
"content": {
"type": "dynamiczone",
"components": [
"sections.hero",
"sections.section-header",
"sections.faq-section",
"sections.how-it-works",
"sections.section-header",
"sections.two-columns-benefits",
"sections.two-column-grid",
"cards.feature-card",
"cards.content-card",
"cards.case-study-card",
"media.image",
"media.image-gallery",
"media.video",
"media.brand-logo-grid",
"testimonials.quote",
"sections.testimonies",
"forms.newsletter",
"sections.testimonies",
"sections.meet-the-team",
"media.video",
"sections.hero",
"sections.hero-home",
"sections.feature-card-grid",
"forms.hubspot-form",
"forms.hubspot-form-ssr",
"forms.conversion",
"migration.data-sink",
"media.embed",
"sections.cta-banner",
"sections.community-banner",
"sections.comparator-grid",
"sections.disclaimer",
"sections.richtext"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,31 @@
"sections.two-column-grid",
"cards.feature-card",
"cards.content-card",
"cards.case-study-card",
"media.image",
"media.image-gallery",
"media.brand-logo-grid",
"testimonials.quote",
"forms.newsletter",
"media.embed",
"media.video",
"blog.callout",
"blog.related-posts",
"blog.editors-picks",
"blog.resource-cta",
"sections.testimonies",
"sections.meet-the-team",
"sections.hero",
"sections.hero-home",
"sections.feature-card-grid",
"media.video",
"forms.hubspot-form",
"forms.hubspot-form-ssr",
"forms.conversion",
"migration.data-sink",
"sections.cta-banner",
"sections.community-banner",
"sections.comparator-grid",
"sections.disclaimer",
"sections.richtext"
]
}
Expand Down
Loading
Loading