Skip to content

Commit

Permalink
Merge pull request #832 from CodeForAfrica/feat/live-preview-civicsignal
Browse files Browse the repository at this point in the history
Enabled Live Preview
  • Loading branch information
koechkevin authored Aug 8, 2024
2 parents d4ee1db + 71e05e3 commit 108081f
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 249 deletions.
2 changes: 1 addition & 1 deletion apps/civicsignalblog/contrib/dokku/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM codeforafrica/codeforafrica-ui:0.1.5
FROM codeforafrica/codeforafrica-ui:0.1.6
3 changes: 2 additions & 1 deletion apps/civicsignalblog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "civicsignalblog",
"version": "0.1.5",
"version": "0.1.6",
"private": true,
"author": "Code for Africa <tech@codeforafrica.org>",
"description": "This is the (temporary) CivicSignal blog",
Expand Down Expand Up @@ -47,6 +47,7 @@
"@next/env": "^14.2.5",
"@payloadcms/bundler-webpack": "^1.0.7",
"@payloadcms/db-mongodb": "^1.7.1",
"@payloadcms/live-preview-react": "^0.2.0",
"@payloadcms/plugin-cloud-storage": "^1.1.3",
"@payloadcms/plugin-nested-docs": "^1.0.12",
"@payloadcms/plugin-sentry": "^0.0.6",
Expand Down
2 changes: 1 addition & 1 deletion apps/civicsignalblog/src/lib/data/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function getPageSeoFromMeta(page, settings) {
type: "website",
site_name: siteTitle,
};
if (image.url) {
if (image?.url) {
const { alt, height, mimeType: type, url, width } = image;
openGraph.images = [
{
Expand Down
15 changes: 8 additions & 7 deletions apps/civicsignalblog/src/lib/data/utils/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ export async function getPost(api, slug, primaryTag) {
const postMeta = {
title,
description: excerpt,
image: coverImage,
image: coverImage ?? null,
...meta,
};
const blocks = [
{
authors: authors.map(({ fullName, bio }) => {
return {
name: fullName,
bio,
};
}),
authors:
authors?.map(({ fullName, bio }) => {
return {
name: fullName,
bio,
};
}) ?? null,
title,
coverImage,
excerpt,
Expand Down
9 changes: 8 additions & 1 deletion apps/civicsignalblog/src/pages/[...slugs].page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLivePreview } from "@payloadcms/live-preview-react";
import React from "react";
import { SWRConfig } from "swr";

Expand All @@ -18,7 +19,13 @@ const componentsBySlugs = {
stories: Articles,
};

function Index({ blocks, fallback }) {
function Index(initialData) {
const { data: props } = useLivePreview({
serverURL: process.env.NEXT_PUBLIC_APP_URL || "",
depth: 2,
initialData,
});
const { blocks, fallback } = props;
if (!blocks?.length) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions apps/civicsignalblog/src/payload/collections/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const Pages = {
group: "Publication",
preview: (doc, options) => formatDraftUrl("pages", doc, options),
useAsTitle: "title",
livePreview: {
url: ({ data }) =>
`${process.env.PAYLOAD_PUBLIC_APP_URL}/${data.slug !== "index" ? `${data.slug}` : ""}`,
},
},
fields: [
{
Expand Down
5 changes: 5 additions & 0 deletions apps/civicsignalblog/src/payload/collections/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const Posts = {
group: "Publication",
useAsTitle: "title",
listSearchableFields: ["content", "excerpt"],
livePreview: {
// Assumed that all posts appear under pots/stories
url: ({ data }) =>
`${process.env.PAYLOAD_PUBLIC_APP_URL}/posts/stories/${data.slug}`,
},
},
fields: [
{
Expand Down
268 changes: 30 additions & 238 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

0 comments on commit 108081f

Please sign in to comment.