From f347a3f4f0a64ec9535351d67b91fff3b3cf6a73 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 14 Sep 2023 13:15:03 +0300 Subject: [PATCH 01/38] Add Page SEO --- apps/codeforafrica/payload.config.ts | 2 +- .../src/lib/data/common/index.js | 3 + apps/codeforafrica/src/lib/data/seo.js | 57 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 apps/codeforafrica/src/lib/data/seo.js diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index f152e0df2..3bdcf88f4 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -57,7 +57,7 @@ export default buildConfig({ }, }), seo({ - collections: [], + collections: ["pages"], globals: [], uploadsCollection: "media", generateTitle: ({ doc }: any) => doc?.title?.value as string, diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index 67af24ffa..e4342b832 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -1,4 +1,5 @@ import blockify from "@/codeforafrica/lib/data/blockify"; +import getPageSeoFromMeta from "@/codeforafrica/lib/data/seo"; import { imageFromMedia } from "@/codeforafrica/lib/data/utils"; function getNavBar(settings) { @@ -58,10 +59,12 @@ export async function getPageProps(api, context) { const footer = getFooter(settings); const blocks = await blockify(page.blocks); + const seo = getPageSeoFromMeta(page, settings); return { blocks, footer, navbar, + seo, }; } diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js new file mode 100644 index 000000000..e4c793925 --- /dev/null +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -0,0 +1,57 @@ +import site from "@/codeforafrica/utils/site"; + +function stringifyDescription(description) { + if (!description || !Array.isArray(description)) { + return ""; + } + let result = ""; + description.forEach((item) => { + if (item.text) { + result += item.text; + } + + if (Array.isArray(item.children)) { + result += stringifyDescription(item.children); + } + }); + return result; +} + +export default function getPageSeoFromMeta(page, settings) { + const { title: pageTitle, meta: pageMeta } = page; + const { title: metaTitle, description: metaDescription, image } = pageMeta; + const { title: siteTitle, description: siteDescription } = settings; + const title = metaTitle || pageTitle || siteTitle || null; + const description = + metaDescription || stringifyDescription(siteDescription) || null; + const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; + const defaultTitle = siteTitle || null; + const canonical = site.url; + const openGraph = { + title, + description, + type: "website", + site_name: siteTitle, + }; + if (image.url) { + const { alt, height, mimeType: type, url, width } = image; + openGraph.images = [ + { + alt: alt || title || defaultTitle, + height, + type, + url, + width, + }, + ]; + } + + return { + title, + titleTemplate, + defaultTitle, + description, + canonical, + openGraph, + }; +} From 7746a66c4bdfc6a3d2e3f061b01e0cf84a3ce8d5 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:49:49 +0300 Subject: [PATCH 02/38] Fix canonical url --- apps/codeforafrica/src/lib/data/seo.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index e4c793925..d6ca6cd5a 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -1,5 +1,6 @@ import site from "@/codeforafrica/utils/site"; +const siteUrl = new URL(site.environmentUrl).href; function stringifyDescription(description) { if (!description || !Array.isArray(description)) { return ""; @@ -26,7 +27,10 @@ export default function getPageSeoFromMeta(page, settings) { metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; const defaultTitle = siteTitle || null; - const canonical = site.url; + // TODO: Handle canonical url for nested pages + // NOTE: We can do this Regex because we're sure about the url contents + // see: https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS + const canonical = siteUrl.replace(/\/+$/, ""); const openGraph = { title, description, From 3c8cb1cda9302258237c938d167f6648902e8b08 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:31:41 +0300 Subject: [PATCH 03/38] Update jest mock value --- apps/codeforafrica/jest.setup.js | 2 ++ apps/codeforafrica/src/lib/data/seo.js | 6 +----- apps/codeforafrica/src/pages/_error.page.js | 2 +- apps/codeforafrica/src/pages/_error.test.js | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/codeforafrica/jest.setup.js b/apps/codeforafrica/jest.setup.js index d477634b5..646b9d21c 100644 --- a/apps/codeforafrica/jest.setup.js +++ b/apps/codeforafrica/jest.setup.js @@ -17,6 +17,8 @@ global.TextDecoder = jest.fn().mockImplementation(() => ({ decode: jest.fn(), })); +process.env.NEXT_PUBLIC_APP_URL = "http://localhost:3000"; + jest.mock("next/router", () => ({ useRouter: jest.fn().mockImplementation(() => ({ asPath: "", diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index d6ca6cd5a..8a7b057b2 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -1,6 +1,5 @@ import site from "@/codeforafrica/utils/site"; -const siteUrl = new URL(site.environmentUrl).href; function stringifyDescription(description) { if (!description || !Array.isArray(description)) { return ""; @@ -27,10 +26,7 @@ export default function getPageSeoFromMeta(page, settings) { metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; const defaultTitle = siteTitle || null; - // TODO: Handle canonical url for nested pages - // NOTE: We can do this Regex because we're sure about the url contents - // see: https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS - const canonical = siteUrl.replace(/\/+$/, ""); + const canonical = site.url.replace(/\/+$/, ""); const openGraph = { title, description, diff --git a/apps/codeforafrica/src/pages/_error.page.js b/apps/codeforafrica/src/pages/_error.page.js index 5440bc17e..028b97db6 100644 --- a/apps/codeforafrica/src/pages/_error.page.js +++ b/apps/codeforafrica/src/pages/_error.page.js @@ -6,7 +6,7 @@ function CustomError(props) { } export async function getStaticProps(context) { - return getPageStaticProps(context, "/_error"); + return getPageStaticProps({ ...context, params: { slugs: ["400"] } }); } export default CustomError; diff --git a/apps/codeforafrica/src/pages/_error.test.js b/apps/codeforafrica/src/pages/_error.test.js index 945005169..f15c14783 100644 --- a/apps/codeforafrica/src/pages/_error.test.js +++ b/apps/codeforafrica/src/pages/_error.test.js @@ -9,7 +9,7 @@ import theme from "@/codeforafrica/theme"; const render = createRender({ theme }); const defaultProps = { - sections: [], + blocks: [], }; describe("/404", () => { From e4db5794a399cfd82db4924798ea2136f09a6cf7 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:46:42 +0300 Subject: [PATCH 04/38] Update Docker build mongo url --- .github/workflows/codeforafrica-deploy-review-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index 7eec5f81e..fa979a515 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -54,7 +54,7 @@ jobs: uses: docker/build-push-action@v3 with: build-args: | - MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} + MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ secrets.CODEFORAFRICA_MONGO_DB_NAME }} NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} GHOST_URL=${{ secrets.GHOST_URL }} From 6e71624390ff654431284d38945c105e5fc3dcaf Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:09:59 +0300 Subject: [PATCH 05/38] Confitional url --- apps/codeforafrica/src/lib/data/seo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index 8a7b057b2..62890cbf4 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -26,7 +26,7 @@ export default function getPageSeoFromMeta(page, settings) { metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; const defaultTitle = siteTitle || null; - const canonical = site.url.replace(/\/+$/, ""); + const canonical = site?.url?.replace(/\/+$/, ""); const openGraph = { title, description, From 5ca44ff80752081b6460eb0670ad5c338859512d Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:27:49 +0300 Subject: [PATCH 06/38] Config url --- .github/workflows/codeforafrica-deploy-review-app.yml | 2 +- apps/codeforafrica/src/lib/data/seo.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index fa979a515..7eec5f81e 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -54,7 +54,7 @@ jobs: uses: docker/build-push-action@v3 with: build-args: | - MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ secrets.CODEFORAFRICA_MONGO_DB_NAME }} + MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} GHOST_URL=${{ secrets.GHOST_URL }} diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index 62890cbf4..8a7b057b2 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -26,7 +26,7 @@ export default function getPageSeoFromMeta(page, settings) { metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; const defaultTitle = siteTitle || null; - const canonical = site?.url?.replace(/\/+$/, ""); + const canonical = site.url.replace(/\/+$/, ""); const openGraph = { title, description, From 20690472a4e0127397e2eb829b4d9f340382867c Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:28:08 +0300 Subject: [PATCH 07/38] clone db before docker build --- .../codeforafrica-deploy-review-app.yml | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index 7eec5f81e..16a8ab38e 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -50,24 +50,6 @@ jobs: password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} username: ${{ secrets.DOCKER_HUB_USERNAME }} - - name: Build Docker image - uses: docker/build-push-action@v3 - with: - build-args: | - MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} - NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} - PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} - GHOST_URL=${{ secrets.GHOST_URL }} - GHOST_API_KEY=${{ secrets.GHOST_API_KEY }} - NEXT_PUBLIC_APP_LOGO_URL=${{ secrets.NEXT_PUBLIC_APP_CFA_LOGO_URL }} - NEXT_PUBLIC_APP_NAME=${{ secrets.NEXT_PUBLIC_APP_CFA_NAME }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - context: . - file: ./Dockerfile.codeforafrica - push: true - tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" - - name: Push to dokku uses: dokku/github-action@master with: @@ -89,6 +71,24 @@ jobs: |-------|--------| | ${{ env.APP_NAME }} | [Visit](https://${{ env.APP_NAME }}.dev.codeforafrica.org) | + - name: Build Docker image + uses: docker/build-push-action@v3 + with: + build-args: | + MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} + NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} + PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} + GHOST_URL=${{ secrets.GHOST_URL }} + GHOST_API_KEY=${{ secrets.GHOST_API_KEY }} + NEXT_PUBLIC_APP_LOGO_URL=${{ secrets.NEXT_PUBLIC_APP_CFA_LOGO_URL }} + NEXT_PUBLIC_APP_NAME=${{ secrets.NEXT_PUBLIC_APP_CFA_NAME }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + context: . + file: ./Dockerfile.codeforafrica + push: true + tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" + destroy_review_app: runs-on: ubuntu-latest # only run when a pull request is closed From 9eb3042cf3e88278a2ab96107b57f973879e5b8a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:57:27 +0300 Subject: [PATCH 08/38] Clone DB before docker build --- .../codeforafrica-deploy-review-app.yml | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index 16a8ab38e..f3f261a32 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -33,6 +33,14 @@ jobs: with: fetch-depth: 0 + - name: Clone Dokku App + uses: dokku/github-action@master + with: + # create a review app + command: review-apps:create + git_remote_url: ${{ env.DOKKU_REMOTE_URL }}/codeforafrica-ui + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -50,6 +58,24 @@ jobs: password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} username: ${{ secrets.DOCKER_HUB_USERNAME }} + - name: Build Docker image + uses: docker/build-push-action@v3 + with: + build-args: | + MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} + NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} + PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} + GHOST_URL=${{ secrets.GHOST_URL }} + GHOST_API_KEY=${{ secrets.GHOST_API_KEY }} + NEXT_PUBLIC_APP_LOGO_URL=${{ secrets.NEXT_PUBLIC_APP_CFA_LOGO_URL }} + NEXT_PUBLIC_APP_NAME=${{ secrets.NEXT_PUBLIC_APP_CFA_NAME }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + context: . + file: ./Dockerfile.codeforafrica + push: true + tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" + - name: Push to dokku uses: dokku/github-action@master with: @@ -71,24 +97,6 @@ jobs: |-------|--------| | ${{ env.APP_NAME }} | [Visit](https://${{ env.APP_NAME }}.dev.codeforafrica.org) | - - name: Build Docker image - uses: docker/build-push-action@v3 - with: - build-args: | - MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} - NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} - PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} - GHOST_URL=${{ secrets.GHOST_URL }} - GHOST_API_KEY=${{ secrets.GHOST_API_KEY }} - NEXT_PUBLIC_APP_LOGO_URL=${{ secrets.NEXT_PUBLIC_APP_CFA_LOGO_URL }} - NEXT_PUBLIC_APP_NAME=${{ secrets.NEXT_PUBLIC_APP_CFA_NAME }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - context: . - file: ./Dockerfile.codeforafrica - push: true - tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" - destroy_review_app: runs-on: ubuntu-latest # only run when a pull request is closed From df89686907c78ff80f50310dbe066de701077bf9 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:01:01 +0300 Subject: [PATCH 09/38] Add review app name --- .github/workflows/codeforafrica-deploy-review-app.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index f3f261a32..27f6daa82 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -39,6 +39,7 @@ jobs: # create a review app command: review-apps:create git_remote_url: ${{ env.DOKKU_REMOTE_URL }}/codeforafrica-ui + review_app_name: ${{ env.APP_NAME }} ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Set up Docker Buildx From 558112facc806d786f018ad2f43397448d73c101 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:07:46 +0300 Subject: [PATCH 10/38] Use codeforafrica db name --- .github/workflows/codeforafrica-deploy-review-app.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index 27f6daa82..fa979a515 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -33,15 +33,6 @@ jobs: with: fetch-depth: 0 - - name: Clone Dokku App - uses: dokku/github-action@master - with: - # create a review app - command: review-apps:create - git_remote_url: ${{ env.DOKKU_REMOTE_URL }}/codeforafrica-ui - review_app_name: ${{ env.APP_NAME }} - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -63,7 +54,7 @@ jobs: uses: docker/build-push-action@v3 with: build-args: | - MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} + MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ secrets.CODEFORAFRICA_MONGO_DB_NAME }} NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} GHOST_URL=${{ secrets.GHOST_URL }} From a5b882b79db91d47d9eac49384e2db80080f13d9 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:16:03 +0300 Subject: [PATCH 11/38] Return empty object from props --- apps/codeforafrica/src/lib/data/common/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index e4342b832..7eedf0b72 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -51,7 +51,7 @@ export async function getPageProps(api, context) { docs: [page], } = await api.findPage(slug); if (!page) { - return null; + return {}; } const settings = await api.findGlobal("settings"); From 34e7a550ea97416efb00f69e23b9289cb0e3c421 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:22:19 +0300 Subject: [PATCH 12/38] Remove cannocial --- apps/codeforafrica/src/lib/data/seo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index 8a7b057b2..f93e462c8 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -1,4 +1,4 @@ -import site from "@/codeforafrica/utils/site"; +// import site from "@/codeforafrica/utils/site"; function stringifyDescription(description) { if (!description || !Array.isArray(description)) { @@ -26,7 +26,7 @@ export default function getPageSeoFromMeta(page, settings) { metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; const defaultTitle = siteTitle || null; - const canonical = site.url.replace(/\/+$/, ""); + // const canonical = site.url.replace(/\/+$/, ""); const openGraph = { title, description, @@ -51,7 +51,7 @@ export default function getPageSeoFromMeta(page, settings) { titleTemplate, defaultTitle, description, - canonical, + // canonical, openGraph, }; } From 5c094bcf02930eb517e2701c7dbf0e9501b1b092 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:30:43 +0300 Subject: [PATCH 13/38] Add Next public url --- Dockerfile.charterafrica | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.charterafrica b/Dockerfile.charterafrica index ec49f44b8..1b1b7bd99 100644 --- a/Dockerfile.charterafrica +++ b/Dockerfile.charterafrica @@ -58,7 +58,7 @@ ARG NEXT_TELEMETRY_DISABLED=1 \ # When building Next.js, point to the local Payload instance PAYLOAD_PUBLIC_APP_URL=http://localhost:3000 \ PAYLOAD_SECRET_KEY - +ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL} RUN pnpm build-next --filter=charterafrica # Needed by Payload at Payload build time From e09f19bb9efc898fb6e9b40cbd150747fcbb4359 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:37:40 +0300 Subject: [PATCH 14/38] Check for empty image --- apps/codeforafrica/src/lib/data/seo.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index f93e462c8..081ee67be 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -19,7 +19,11 @@ function stringifyDescription(description) { export default function getPageSeoFromMeta(page, settings) { const { title: pageTitle, meta: pageMeta } = page; - const { title: metaTitle, description: metaDescription, image } = pageMeta; + const { + title: metaTitle, + description: metaDescription, + image = {}, + } = pageMeta; const { title: siteTitle, description: siteDescription } = settings; const title = metaTitle || pageTitle || siteTitle || null; const description = From 96e5fff90ca11e35ed35e9d8d5fafe2c72be55f0 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:51:13 +0300 Subject: [PATCH 15/38] Remove unnecessary changes --- .github/workflows/codeforafrica-deploy-review-app.yml | 2 +- apps/codeforafrica/src/lib/data/common/index.js | 2 +- apps/codeforafrica/src/lib/data/seo.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeforafrica-deploy-review-app.yml b/.github/workflows/codeforafrica-deploy-review-app.yml index fa979a515..7eec5f81e 100644 --- a/.github/workflows/codeforafrica-deploy-review-app.yml +++ b/.github/workflows/codeforafrica-deploy-review-app.yml @@ -54,7 +54,7 @@ jobs: uses: docker/build-push-action@v3 with: build-args: | - MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ secrets.CODEFORAFRICA_MONGO_DB_NAME }} + MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }} NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }} PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }} GHOST_URL=${{ secrets.GHOST_URL }} diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index 7eedf0b72..e4342b832 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -51,7 +51,7 @@ export async function getPageProps(api, context) { docs: [page], } = await api.findPage(slug); if (!page) { - return {}; + return null; } const settings = await api.findGlobal("settings"); diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index 081ee67be..79753b14b 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -1,4 +1,4 @@ -// import site from "@/codeforafrica/utils/site"; +import site from "@/codeforafrica/utils/site"; function stringifyDescription(description) { if (!description || !Array.isArray(description)) { @@ -30,7 +30,7 @@ export default function getPageSeoFromMeta(page, settings) { metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; const defaultTitle = siteTitle || null; - // const canonical = site.url.replace(/\/+$/, ""); + const canonical = site.url.replace(/\/+$/, ""); const openGraph = { title, description, @@ -55,7 +55,7 @@ export default function getPageSeoFromMeta(page, settings) { titleTemplate, defaultTitle, description, - // canonical, + canonical, openGraph, }; } From c38b8d4193778dec0160bae7c99be6e607b0fe54 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:57:03 +0300 Subject: [PATCH 16/38] Handle empty props --- apps/codeforafrica/src/lib/data/rest/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 80c11bb13..b74fd48d6 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -37,6 +37,6 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); return { - props, + props: props || {}, }; } From 060cc6dd518bcfd0c0390c929e7fdd08e87719b6 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:09:44 +0300 Subject: [PATCH 17/38] Remove unnecessary env variable --- Dockerfile.charterafrica | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile.charterafrica b/Dockerfile.charterafrica index 1b1b7bd99..dac7a01f7 100644 --- a/Dockerfile.charterafrica +++ b/Dockerfile.charterafrica @@ -58,7 +58,6 @@ ARG NEXT_TELEMETRY_DISABLED=1 \ # When building Next.js, point to the local Payload instance PAYLOAD_PUBLIC_APP_URL=http://localhost:3000 \ PAYLOAD_SECRET_KEY -ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL} RUN pnpm build-next --filter=charterafrica # Needed by Payload at Payload build time From 7f2b2db5ea7943c7378cdba3d58ee2caaa1f7860 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:35:59 +0300 Subject: [PATCH 18/38] Misc Fixes --- Dockerfile.charterafrica | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile.charterafrica b/Dockerfile.charterafrica index dac7a01f7..71875bbf8 100644 --- a/Dockerfile.charterafrica +++ b/Dockerfile.charterafrica @@ -58,6 +58,7 @@ ARG NEXT_TELEMETRY_DISABLED=1 \ # When building Next.js, point to the local Payload instance PAYLOAD_PUBLIC_APP_URL=http://localhost:3000 \ PAYLOAD_SECRET_KEY + RUN pnpm build-next --filter=charterafrica # Needed by Payload at Payload build time From e01ab9294ce85d9b073acc3f174bf6a259ba246d Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:36:31 +0300 Subject: [PATCH 19/38] Misc Fixes --- Dockerfile.charterafrica | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.charterafrica b/Dockerfile.charterafrica index 71875bbf8..ec49f44b8 100644 --- a/Dockerfile.charterafrica +++ b/Dockerfile.charterafrica @@ -58,7 +58,7 @@ ARG NEXT_TELEMETRY_DISABLED=1 \ # When building Next.js, point to the local Payload instance PAYLOAD_PUBLIC_APP_URL=http://localhost:3000 \ PAYLOAD_SECRET_KEY - + RUN pnpm build-next --filter=charterafrica # Needed by Payload at Payload build time From 4c48ad6cf36a51916485d968d77296ed8ba4fad8 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:07:33 +0300 Subject: [PATCH 20/38] Fix SEO title and description --- apps/codeforafrica/src/lib/data/seo.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/seo.js b/apps/codeforafrica/src/lib/data/seo.js index 79753b14b..3de731194 100644 --- a/apps/codeforafrica/src/lib/data/seo.js +++ b/apps/codeforafrica/src/lib/data/seo.js @@ -1,20 +1,21 @@ import site from "@/codeforafrica/utils/site"; function stringifyDescription(description) { - if (!description || !Array.isArray(description)) { + if (!Array.isArray(description)) { return ""; } - let result = ""; - description.forEach((item) => { + return description.reduce((result, item) => { if (item.text) { + // eslint-disable-next-line no-param-reassign result += item.text; } if (Array.isArray(item.children)) { + // eslint-disable-next-line no-param-reassign result += stringifyDescription(item.children); } - }); - return result; + return result; + }, ""); } export default function getPageSeoFromMeta(page, settings) { @@ -25,7 +26,12 @@ export default function getPageSeoFromMeta(page, settings) { image = {}, } = pageMeta; const { title: siteTitle, description: siteDescription } = settings; - const title = metaTitle || pageTitle || siteTitle || null; + const title = + metaTitle || + pageTitle || + siteTitle || + process.env.NEXT_PUBLIC_APP_NAME || + null; const description = metaDescription || stringifyDescription(siteDescription) || null; const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; From 88768dffefa6f84a852c160523869912a60a381a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:51:10 +0300 Subject: [PATCH 21/38] Fix not found pages --- apps/codeforafrica/src/lib/data/rest/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index b74fd48d6..4ee7a18b1 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -36,7 +36,12 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); + if (!props) { + return { + notFound: true, + }; + } return { - props: props || {}, + props, }; } From 7182df8664fea4ed7d818db69162800d9a89f215 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 09:14:00 +0300 Subject: [PATCH 22/38] Add default values for error pages --- apps/codeforafrica/src/lib/data/rest/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 4ee7a18b1..63517ea4b 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -38,7 +38,9 @@ export async function getPageStaticProps(context) { const props = await getPageProps(api, context); if (!props) { return { - notFound: true, + props: { + title: "Page not found", + }, }; } return { From 916cb6e409ae049cb5af7000efef37cbeff198d1 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:43:33 +0300 Subject: [PATCH 23/38] Add global tags --- apps/codeforafrica/payload.config.ts | 3 +- .../src/payload/collections/Tags.js | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 apps/codeforafrica/src/payload/collections/Tags.js diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index f152e0df2..c291fe7cf 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -5,6 +5,7 @@ import Media from "./src/payload/collections/Media"; import Pages from "./src/payload/collections/Pages"; import Partners from "./src/payload/collections/Partners"; import Settings from "./src/payload/globals/Settings"; +import Tags from "./src/payload/collections/Tags"; import { CollectionConfig, GlobalConfig } from "payload/types"; import dotenv from "dotenv"; import seo from "@payloadcms/plugin-seo"; @@ -30,7 +31,7 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Pages, Media, Partners] as CollectionConfig[], + collections: [Pages, Media, Partners, Tags] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), diff --git a/apps/codeforafrica/src/payload/collections/Tags.js b/apps/codeforafrica/src/payload/collections/Tags.js new file mode 100644 index 000000000..933a042eb --- /dev/null +++ b/apps/codeforafrica/src/payload/collections/Tags.js @@ -0,0 +1,28 @@ +import slug from "../fields/slug"; + +const Tags = { + slug: "tag", + admin: { + useAsTitle: "name", + }, + access: { + read: () => true, // Everyone can read Pages + }, + fields: [ + { + name: "name", + label: { + en: "Name", + fr: "Nom", + pt: "Nome", + }, + type: "text", + localized: true, + required: true, + unique: true, + }, + slug({ fieldToUse: "name" }), + ], +}; + +export default Tags; From 8ba56382ab2f4bdc9bf4aafb15e6b908b70172c2 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:53:45 +0300 Subject: [PATCH 24/38] Add Author collection --- apps/codeforafrica/payload.config.ts | 3 ++- .../src/payload/collections/Authors.js | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 apps/codeforafrica/src/payload/collections/Authors.js diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index c291fe7cf..ef0f88e77 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -1,6 +1,7 @@ import path from "path"; import { buildConfig } from "payload/config"; +import Authors from "./src/payload/collections/Authors"; import Media from "./src/payload/collections/Media"; import Pages from "./src/payload/collections/Pages"; import Partners from "./src/payload/collections/Partners"; @@ -31,7 +32,7 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Pages, Media, Partners, Tags] as CollectionConfig[], + collections: [Authors,Pages, Media, Partners, Tags] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), diff --git a/apps/codeforafrica/src/payload/collections/Authors.js b/apps/codeforafrica/src/payload/collections/Authors.js new file mode 100644 index 000000000..7b6d41c5b --- /dev/null +++ b/apps/codeforafrica/src/payload/collections/Authors.js @@ -0,0 +1,25 @@ +const Authors = { + slug: "author", + access: { + read: () => true, + }, + admin: { + useAsTitle: "fullName", + }, + fields: [ + { + name: "fullName", + type: "text", + label: { + en: "Full Name", + fr: "Nom et prénom", + pt: "Nome completo", + }, + localized: false, + required: true, + }, + // If more author information needed e.g contact details go here + ], +}; + +export default Authors; From 3976618cabd6e420c159dd1a87f11f667847daa2 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:55:30 +0300 Subject: [PATCH 25/38] Add tags and authors relationships --- .../codeforafrica/src/payload/fields/authors.js | 17 +++++++++++++++++ apps/codeforafrica/src/payload/fields/tags.js | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 apps/codeforafrica/src/payload/fields/authors.js create mode 100644 apps/codeforafrica/src/payload/fields/tags.js diff --git a/apps/codeforafrica/src/payload/fields/authors.js b/apps/codeforafrica/src/payload/fields/authors.js new file mode 100644 index 000000000..7d29076b3 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/authors.js @@ -0,0 +1,17 @@ +import { deepmerge } from "@mui/utils"; + +const authors = (overrides) => + deepmerge( + { + name: "authors", + type: "relationship", + relationTo: "author", + hasMany: true, + admin: { + position: "sidebar", + }, + }, + overrides, + ); + +export default authors; diff --git a/apps/codeforafrica/src/payload/fields/tags.js b/apps/codeforafrica/src/payload/fields/tags.js new file mode 100644 index 000000000..d38440d6f --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/tags.js @@ -0,0 +1,14 @@ +import { deepmerge } from "@mui/utils"; + +const tags = (overrides) => { + const field = { + name: "tags", + required: true, + type: "relationship", + relationTo: "tag", + hasMany: true, + }; + return deepmerge(field, overrides); +}; + +export default tags; From b1d24de3ee4a2ea729ca4238f624b96b83e2974a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:46:17 +0300 Subject: [PATCH 26/38] Add published on field --- .../src/payload/fields/publishedOn.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 apps/codeforafrica/src/payload/fields/publishedOn.js diff --git a/apps/codeforafrica/src/payload/fields/publishedOn.js b/apps/codeforafrica/src/payload/fields/publishedOn.js new file mode 100644 index 000000000..f735543a8 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/publishedOn.js @@ -0,0 +1,22 @@ +import { deepmerge } from "@mui/utils"; + +const publishedOn = (overrides) => + deepmerge( + { + name: "publishedOn", + type: "date", + required: true, + hooks: { + beforeValidate: [({ value }) => (value ? new Date(value) : new Date())], + }, + admin: { + date: { + pickerAppearance: "dayAndTime", + }, + position: "sidebar", + }, + }, + overrides, + ); + +export default publishedOn; From ee1c6bdeaa9aaaf4524dd78c7dc7083891910ff6 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:55:59 +0300 Subject: [PATCH 27/38] Add contents building blocks --- .../src/payload/blocks/ExternalEmbed.js | 81 +++++++++++++++++++ .../src/payload/blocks/MediaBlock.js | 23 ++++++ .../src/payload/blocks/RichText.js | 32 ++++++++ .../src/payload/fields/blockFields.js | 21 +++++ .../src/payload/fields/content.js | 18 +++++ 5 files changed, 175 insertions(+) create mode 100644 apps/codeforafrica/src/payload/blocks/ExternalEmbed.js create mode 100644 apps/codeforafrica/src/payload/blocks/MediaBlock.js create mode 100644 apps/codeforafrica/src/payload/blocks/RichText.js create mode 100644 apps/codeforafrica/src/payload/fields/blockFields.js create mode 100644 apps/codeforafrica/src/payload/fields/content.js diff --git a/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js new file mode 100644 index 000000000..d12c71f85 --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js @@ -0,0 +1,81 @@ +import blockFields from "../fields/blockFields"; + +const ExternalEmbed = { + slug: "external-embed", + fields: [ + blockFields({ + name: "embedBlockFields", + fields: [ + { + type: "row", + fields: [ + { + name: "embedType", + type: "radio", + defaultValue: "url", + options: [ + { + label: { + en: "URL", + fr: "URL", + pt: "URL", + }, + value: "url", + }, + { + label: { + en: "Code", + fr: "Code", + pt: "Código", + }, + value: "code", + }, + ], + }, + ], + }, + { + name: "url", + label: { + en: "URL", + fr: "URL", + pt: "URL", + }, + type: "text", + required: true, + admin: { + condition: (_, siblingData) => siblingData?.embedType === "url", + }, + }, + { + name: "caption", + label: { + en: "Caption", + fr: "Légende", + pt: "Rubrica", + }, + type: "text", + localized: true, + admin: { + condition: (_, siblingData) => siblingData?.embedType === "url", + }, + }, + { + name: "code", + label: { + en: "Code", + fr: "Code", + pt: "Código", + }, + type: "code", + required: true, + admin: { + condition: (_, siblingData) => siblingData?.embedType === "code", + }, + }, + ], + }), + ], +}; + +export default ExternalEmbed; diff --git a/apps/codeforafrica/src/payload/blocks/MediaBlock.js b/apps/codeforafrica/src/payload/blocks/MediaBlock.js new file mode 100644 index 000000000..08b2530a6 --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/MediaBlock.js @@ -0,0 +1,23 @@ +import blockFields from "../fields/blockFields"; + +const MediaBlock = { + slug: "mediaBlock", + fields: [ + blockFields({ + name: "mediaBlockFields", + fields: [ + { + name: "image", + type: "upload", + relationTo: "media", + required: true, + filterOptions: { + mimeType: { contains: "image" }, + }, + }, + ], + }), + ], +}; + +export default MediaBlock; diff --git a/apps/codeforafrica/src/payload/blocks/RichText.js b/apps/codeforafrica/src/payload/blocks/RichText.js new file mode 100644 index 000000000..ae19f33fc --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/RichText.js @@ -0,0 +1,32 @@ +import blockFields from "../fields/blockFields"; +import richText from "../fields/richText"; + +const RichText = { + slug: "richText", + fields: [ + blockFields({ + name: "richTextBlockFields", + fields: [ + richText({ + name: "content", + admin: { + elements: [ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "link", + "ol", + "ul", + "indent", + ], + }, + }), + ], + }), + ], +}; + +export default RichText; diff --git a/apps/codeforafrica/src/payload/fields/blockFields.js b/apps/codeforafrica/src/payload/fields/blockFields.js new file mode 100644 index 000000000..55188a7c5 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/blockFields.js @@ -0,0 +1,21 @@ +import { deepmerge } from "@mui/utils"; + +const blockFields = ({ name, fields, overrides }) => + deepmerge( + { + name, + label: false, + type: "group", + admin: { + hideGutter: true, + style: { + margin: 0, + padding: 0, + }, + }, + fields, + }, + overrides, + ); + +export default blockFields; diff --git a/apps/codeforafrica/src/payload/fields/content.js b/apps/codeforafrica/src/payload/fields/content.js new file mode 100644 index 000000000..893bfaf00 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/content.js @@ -0,0 +1,18 @@ +import { deepmerge } from "@mui/utils"; + +import ExternalEmbed from "../blocks/ExternalEmbed"; +import MediaBlock from "../blocks/MediaBlock"; +import RichText from "../blocks/RichText"; + +const content = (overrides) => + deepmerge( + { + name: "content", + type: "blocks", + blocks: [RichText, MediaBlock, ExternalEmbed], + localized: true, + }, + overrides, + ); + +export default content; From e684b994fb0c5632abdb05d5a54f41d2b082e459 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:05:46 +0300 Subject: [PATCH 28/38] Format code --- apps/codeforafrica/payload.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index ef0f88e77..94f3541f1 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -32,7 +32,7 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Authors,Pages, Media, Partners, Tags] as CollectionConfig[], + collections: [Authors, Pages, Media, Partners, Tags] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), From 9957e133a72a18535550d0ca4bd07ffe12256e7a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:46:40 +0300 Subject: [PATCH 29/38] Fix not found pages --- apps/codeforafrica/src/lib/data/rest/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 80c11bb13..63517ea4b 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -36,6 +36,13 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); + if (!props) { + return { + props: { + title: "Page not found", + }, + }; + } return { props, }; From 32a9da1782eb162c3e4867d7eaad5818f0b03007 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:00:46 +0300 Subject: [PATCH 30/38] Default value for error pages --- apps/codeforafrica/src/lib/data/common/index.js | 6 ++++++ apps/codeforafrica/src/lib/data/local/index.js | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index e4342b832..f241c3eda 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -50,6 +50,12 @@ export async function getPageProps(api, context) { const { docs: [page], } = await api.findPage(slug); + // default value if error page has not been created yet + if (!page && slug === "404") { + return { + title: "Page not found", + }; + } if (!page) { return null; } diff --git a/apps/codeforafrica/src/lib/data/local/index.js b/apps/codeforafrica/src/lib/data/local/index.js index 5d8cc6e76..725d86f11 100644 --- a/apps/codeforafrica/src/lib/data/local/index.js +++ b/apps/codeforafrica/src/lib/data/local/index.js @@ -3,9 +3,6 @@ import api from "@/codeforafrica/lib/payload"; export async function getPageServerSideProps(context) { const props = await getPageProps(api, context); - if (!props) { - return { notFound: true }; - } return { props, From 51d56d93d2597d330f30a95826308f1c57d4e6e4 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:02:30 +0300 Subject: [PATCH 31/38] Default value for error pages --- apps/codeforafrica/src/lib/data/rest/index.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 63517ea4b..80c11bb13 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -36,13 +36,6 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); - if (!props) { - return { - props: { - title: "Page not found", - }, - }; - } return { props, }; From 0fb6c46fa5942a3294005eb884239cf3c7757059 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:04:09 +0300 Subject: [PATCH 32/38] Add notfound --- apps/codeforafrica/src/lib/data/local/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/codeforafrica/src/lib/data/local/index.js b/apps/codeforafrica/src/lib/data/local/index.js index 725d86f11..5d8cc6e76 100644 --- a/apps/codeforafrica/src/lib/data/local/index.js +++ b/apps/codeforafrica/src/lib/data/local/index.js @@ -3,6 +3,9 @@ import api from "@/codeforafrica/lib/payload"; export async function getPageServerSideProps(context) { const props = await getPageProps(api, context); + if (!props) { + return { notFound: true }; + } return { props, From c2a29e3a54a49a54cfd71d1b6a0ecbac33d3b3ac Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:39:22 +0300 Subject: [PATCH 33/38] Remove unnecessary error props --- apps/codeforafrica/src/lib/data/common/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index f9a880f20..ce3fcc029 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -146,12 +146,7 @@ export async function getPageProps(api, context) { const { docs: [page], } = await api.findPage(slug); - // default value if error page has not been created yet - if (!page && slug === "404") { - return { - title: "Page not found", - }; - } + if (!page) { if (["404", "500"].includes(slug)) { return getDefaultErrorPageProps(slug); From fb1cac084c52f87b705154d66073aff047b4da4b Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:40:58 +0300 Subject: [PATCH 34/38] Remove unnecessary spaces --- apps/codeforafrica/src/lib/data/common/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index ce3fcc029..6925987d6 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -146,7 +146,6 @@ export async function getPageProps(api, context) { const { docs: [page], } = await api.findPage(slug); - if (!page) { if (["404", "500"].includes(slug)) { return getDefaultErrorPageProps(slug); From 1dac236e40b55eb9a85f9f3b8bbbfcad17ebad25 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:46:45 +0300 Subject: [PATCH 35/38] Update get posts cms --- apps/codeforafrica/src/lib/data/rest/index.js | 7 ----- .../src/payload/blocks/ExternalEmbed.js | 30 ++++--------------- .../src/payload/collections/Authors.js | 7 +---- .../src/payload/collections/Tags.js | 6 +--- 4 files changed, 7 insertions(+), 43 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 63517ea4b..80c11bb13 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -36,13 +36,6 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); - if (!props) { - return { - props: { - title: "Page not found", - }, - }; - } return { props, }; diff --git a/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js index d12c71f85..fd89a9b68 100644 --- a/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js +++ b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js @@ -15,19 +15,11 @@ const ExternalEmbed = { defaultValue: "url", options: [ { - label: { - en: "URL", - fr: "URL", - pt: "URL", - }, + label: "URL", value: "url", }, { - label: { - en: "Code", - fr: "Code", - pt: "Código", - }, + label: "Code", value: "code", }, ], @@ -36,11 +28,7 @@ const ExternalEmbed = { }, { name: "url", - label: { - en: "URL", - fr: "URL", - pt: "URL", - }, + label: "URL", type: "text", required: true, admin: { @@ -49,11 +37,7 @@ const ExternalEmbed = { }, { name: "caption", - label: { - en: "Caption", - fr: "Légende", - pt: "Rubrica", - }, + label: "Caption", type: "text", localized: true, admin: { @@ -62,11 +46,7 @@ const ExternalEmbed = { }, { name: "code", - label: { - en: "Code", - fr: "Code", - pt: "Código", - }, + label: "Code", type: "code", required: true, admin: { diff --git a/apps/codeforafrica/src/payload/collections/Authors.js b/apps/codeforafrica/src/payload/collections/Authors.js index 7b6d41c5b..5967d4152 100644 --- a/apps/codeforafrica/src/payload/collections/Authors.js +++ b/apps/codeforafrica/src/payload/collections/Authors.js @@ -10,15 +10,10 @@ const Authors = { { name: "fullName", type: "text", - label: { - en: "Full Name", - fr: "Nom et prénom", - pt: "Nome completo", - }, + label: "Full Name", localized: false, required: true, }, - // If more author information needed e.g contact details go here ], }; diff --git a/apps/codeforafrica/src/payload/collections/Tags.js b/apps/codeforafrica/src/payload/collections/Tags.js index 933a042eb..4cecf8e07 100644 --- a/apps/codeforafrica/src/payload/collections/Tags.js +++ b/apps/codeforafrica/src/payload/collections/Tags.js @@ -11,11 +11,7 @@ const Tags = { fields: [ { name: "name", - label: { - en: "Name", - fr: "Nom", - pt: "Nome", - }, + label: "Name", type: "text", localized: true, required: true, From 8101c7e9b82044648e7ea3c57cd4c43c420ca541 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 20 Sep 2023 14:43:29 +0300 Subject: [PATCH 36/38] Fix formating --- apps/codeforafrica/payload.config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index b6de2adad..3022d93ff 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -33,7 +33,14 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Authors, Impact, Pages, Media, Partners, Tags] as CollectionConfig[], + collections: [ + Authors, + Impact, + Pages, + Media, + Partners, + Tags, + ] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), From 338535753e4f77e6707e49f5168769f0538d745a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:45:37 +0300 Subject: [PATCH 37/38] Remove unnecessary comment --- apps/codeforafrica/src/payload/collections/Tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/payload/collections/Tags.js b/apps/codeforafrica/src/payload/collections/Tags.js index 4cecf8e07..0f3cf7fe2 100644 --- a/apps/codeforafrica/src/payload/collections/Tags.js +++ b/apps/codeforafrica/src/payload/collections/Tags.js @@ -6,7 +6,7 @@ const Tags = { useAsTitle: "name", }, access: { - read: () => true, // Everyone can read Pages + read: () => true, }, fields: [ { From 126ac08b36c97b73ea001cf0dd95e5c37d7d3de1 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:19:25 +0300 Subject: [PATCH 38/38] Fix formating --- apps/codeforafrica/payload.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index 14e693014..2b825d735 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -41,7 +41,7 @@ export default buildConfig({ Pages, Media, Partners, - Tags + Tags, ] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: {