From 12a309a6fbce5b81845e5b111a14a9ccafe5b358 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 8 Aug 2024 21:08:00 +0300 Subject: [PATCH 1/5] Ensure PAYLOAD_PUBLIC_APP_URL is set --- apps/civicsignalblog/.env | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/civicsignalblog/.env b/apps/civicsignalblog/.env index 9c951a201..2b1d235e6 100644 --- a/apps/civicsignalblog/.env +++ b/apps/civicsignalblog/.env @@ -1,11 +1,12 @@ MIGRATIONS_DIR=./migrations NEXT_PUBLIC_APP_DIRECTORY="apps/civicsignal/" NEXT_PUBLIC_APP_NAME="Code for Africa" -NEXT_PUBLIC_APP_URL="https://blog.civicsignal.africa" +NEXT_PUBLIC_APP_URL="http://localhost:3000" NEXT_PUBLIC_GOOGLE_ANALYTICS_ID="G-NXX5DBEHXC" NEXT_PUBLIC_IMAGE_DOMAINS="" NEXT_PUBLIC_IMAGE_UNOPTIMIZED="true" NEXT_PUBLIC_VERCEL_URL=${VERCEL_URL} +PAYLOAD_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL SENTRY_ENVIRONMENT=local SENTRY_ORG=code-for-africa SENTRY_PROJECT=civicsignal From 915a3d60d7763292dacf75048c28ebd051dc5ea8 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 8 Aug 2024 21:08:29 +0300 Subject: [PATCH 2/5] Use loadEnvConfig to load env vars --- apps/civicsignalblog/payload.config.ts | 7 ++++--- apps/civicsignalblog/server.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/civicsignalblog/payload.config.ts b/apps/civicsignalblog/payload.config.ts index 3d2b683e4..8868d1d3b 100644 --- a/apps/civicsignalblog/payload.config.ts +++ b/apps/civicsignalblog/payload.config.ts @@ -6,11 +6,11 @@ import { mongooseAdapter } from "@payloadcms/db-mongodb"; import { webpackBundler } from "@payloadcms/bundler-webpack"; import { CollectionConfig, GlobalConfig } from "payload/types"; import { cloudStorage } from "@payloadcms/plugin-cloud-storage"; -import dotenv from "dotenv"; import { sentry } from "@payloadcms/plugin-sentry"; import seo from "@payloadcms/plugin-seo"; import nestedDocs from "@payloadcms/plugin-nested-docs"; import { s3Adapter } from "@payloadcms/plugin-cloud-storage/s3"; +import { loadEnvConfig } from "@next/env"; import Authors from "./src/payload/collections/Authors"; import Media from "./src/payload/collections/Media"; @@ -22,8 +22,9 @@ import Tags from "./src/payload/collections/Tags"; import Users from "./src/payload/collections/Users"; import { defaultLocale, locales } from "./src/payload/utils/locales"; -dotenv.config(); -dotenv.config({ path: "./.env.local" }); +const dev = process.env.NODE_ENV !== "production"; +const projectDir = process.cwd(); +loadEnvConfig(projectDir, dev); const appURL = process?.env?.PAYLOAD_PUBLIC_APP_URL; diff --git a/apps/civicsignalblog/server.ts b/apps/civicsignalblog/server.ts index 063368788..3b7d8418b 100644 --- a/apps/civicsignalblog/server.ts +++ b/apps/civicsignalblog/server.ts @@ -7,10 +7,10 @@ import payload from "payload"; import { Payload } from "payload/dist/payload"; import { loadEnvConfig } from "@next/env"; +const dev = process.env.NODE_ENV !== "production"; const projectDir = process.cwd(); -loadEnvConfig(projectDir); +loadEnvConfig(projectDir, dev); -const dev = process.env.NODE_ENV !== "production"; const hostname = process.env.NEXT_HOSTNAME || "localhost"; const port = parseInt(process.env.PORT || "3000", 10); const sendGridAPIKey = process.env.SENDGRID_API_KEY; From 366c52148677fe1f619833381a27cbdd95f0d1c3 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 8 Aug 2024 21:10:07 +0300 Subject: [PATCH 3/5] Handle attributes that could be empty during preview --- apps/civicsignalblog/src/lib/data/utils/posts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/src/lib/data/utils/posts.js b/apps/civicsignalblog/src/lib/data/utils/posts.js index 376f479c8..4b74fd74d 100644 --- a/apps/civicsignalblog/src/lib/data/utils/posts.js +++ b/apps/civicsignalblog/src/lib/data/utils/posts.js @@ -106,8 +106,8 @@ export async function getPost(api, slug, primaryTag) { authors, title, coverImage, - excerpt, - tags, + excerpt = null, + tags = [], meta, publishedOn, ...other From faf74a21524ffee673e515bee483f1415a2b1519 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 8 Aug 2024 21:12:23 +0300 Subject: [PATCH 4/5] Add normal preview to posts --- apps/civicsignalblog/src/payload/collections/Posts.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/civicsignalblog/src/payload/collections/Posts.js b/apps/civicsignalblog/src/payload/collections/Posts.js index d8b95606b..d85ebadc7 100644 --- a/apps/civicsignalblog/src/payload/collections/Posts.js +++ b/apps/civicsignalblog/src/payload/collections/Posts.js @@ -4,6 +4,7 @@ import image from "../fields/image"; import publishedOn from "../fields/publishedOn"; import slug from "../fields/slug"; import tags from "../fields/tags"; +import formatDraftUrl from "../utils/formatDraftUrl"; const Posts = { slug: "posts", @@ -22,12 +23,14 @@ const Posts = { defaultColumns: ["title", "authors", "publishedOn"], description: "Stories", group: "Publication", + preview: (doc, options) => formatDraftUrl("posts/stories", doc, options), 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}`, + // Assumed that all posts appear under posts/stories + url: ({ data }) => { + return `${process.env.PAYLOAD_PUBLIC_APP_URL}/posts/stories/${data.slug}`; + }, }, }, fields: [ From 16e682150857a89ff58fec6dafbabb471a4a776f Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 8 Aug 2024 21:20:58 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=20Bump=20civicsignalblog=20version:=200.1.?= =?UTF-8?q?6=20=E2=86=92=200.1.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/civicsignalblog/contrib/dokku/Dockerfile | 2 +- apps/civicsignalblog/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/contrib/dokku/Dockerfile b/apps/civicsignalblog/contrib/dokku/Dockerfile index f59a37f1f..ff2543b4e 100644 --- a/apps/civicsignalblog/contrib/dokku/Dockerfile +++ b/apps/civicsignalblog/contrib/dokku/Dockerfile @@ -1 +1 @@ -FROM codeforafrica/codeforafrica-ui:0.1.6 +FROM codeforafrica/codeforafrica-ui:0.1.7 diff --git a/apps/civicsignalblog/package.json b/apps/civicsignalblog/package.json index 99fe184bf..d1d178d25 100644 --- a/apps/civicsignalblog/package.json +++ b/apps/civicsignalblog/package.json @@ -1,6 +1,6 @@ { "name": "civicsignalblog", - "version": "0.1.6", + "version": "0.1.7", "private": true, "author": "Code for Africa ", "description": "This is the (temporary) CivicSignal blog",