From 8a3cf6ce4814608f0bac2998c9a06c69e1412175 Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Wed, 28 Jun 2023 17:41:35 +0100 Subject: [PATCH] [website] use demo ghost for blog in dev (#428) * use demo ghost in dev * union * u ci.yml --- .github/workflows/ci.yml | 1 + apps/website/.env | 12 ++++++++++++ apps/website/.env.development | 14 ++++++++++++++ apps/website/src/config/env.client.mjs | 10 ++++++++++ apps/website/src/config/env.server.mjs | 7 +++++++ apps/website/src/lib/ghost.ts | 10 +++++----- 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 apps/website/.env.development diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9fd83f6..100a23a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: types: [opened, synchronize] env: + NEXT_PUBLIC_GHOST_API_URL: '' NEXT_PUBLIC_GHOST_API_KEY: '' INFURA_API_KEY: '' TAMAGUI_TARGET: 'web' diff --git a/apps/website/.env b/apps/website/.env index 8a7fcfdd..10aaef1f 100644 --- a/apps/website/.env +++ b/apps/website/.env @@ -1,3 +1,15 @@ +# .env, .env.development, and .env.production files should be included in your repository as they define defaults. +# .env*.local should be added to .gitignore, as those files are intended to be ignored. +# .env.local is where secrets can be stored. +# +# – https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#default-environment-variables + +# The vercel env pull sub-command will export development environment variables to a local .env file or a different file of your choice. +# +# `vercel env pull ./apps/website/.env.development.local` +# +# – https://vercel.com/docs/cli/env#exporting-development-environment-variables + IGNORE_TS_CONFIG_PATHS=true TAMAGUI_TARGET=web TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1 diff --git a/apps/website/.env.development b/apps/website/.env.development new file mode 100644 index 00000000..8b4b877e --- /dev/null +++ b/apps/website/.env.development @@ -0,0 +1,14 @@ +# .env, .env.development, and .env.production files should be included in your repository as they define defaults. +# .env*.local should be added to .gitignore, as those files are intended to be ignored. +# .env.local is where secrets can be stored. +# +# – https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#default-environment-variables + +# The vercel env pull sub-command will export development environment variables to a local .env file or a different file of your choice. +# +# `vercel env pull ./apps/website/.env.development.local` +# +# – https://vercel.com/docs/cli/env#exporting-development-environment-variables + +NEXT_PUBLIC_GHOST_API_URL=https://demo.ghost.io +NEXT_PUBLIC_GHOST_API_KEY=22444f78447824223cefc48062 diff --git a/apps/website/src/config/env.client.mjs b/apps/website/src/config/env.client.mjs index 6f8b35fd..9335cb19 100644 --- a/apps/website/src/config/env.client.mjs +++ b/apps/website/src/config/env.client.mjs @@ -1,9 +1,19 @@ import { z } from 'zod' export const envSchema = z.object({ + NEXT_PUBLIC_VERCEL_ENV: z + .union([ + z.literal('production'), + z.literal('preview'), + z.literal('development'), + ]) + .optional(), + NEXT_PUBLIC_GHOST_API_URL: z.string(), NEXT_PUBLIC_GHOST_API_KEY: z.string(), }) export const clientEnv = envSchema.parse({ + NEXT_PUBLIC_VERCEL_ENV: process.env.NEXT_PUBLIC_VERCEL_ENV, + NEXT_PUBLIC_GHOST_API_URL: process.env.NEXT_PUBLIC_GHOST_API_URL, NEXT_PUBLIC_GHOST_API_KEY: process.env.NEXT_PUBLIC_GHOST_API_KEY, }) diff --git a/apps/website/src/config/env.server.mjs b/apps/website/src/config/env.server.mjs index 2f0ec2d2..9d108d70 100644 --- a/apps/website/src/config/env.server.mjs +++ b/apps/website/src/config/env.server.mjs @@ -7,6 +7,13 @@ if (typeof window !== 'undefined') { } export const envSchema = z.object({ + VERCEL_ENV: z + .union([ + z.literal('production'), + z.literal('preview'), + z.literal('development'), + ]) + .optional(), INFURA_API_KEY: z.string(), TAMAGUI_TARGET: z.literal('web'), NEXT_PUBLIC_GHOST_API_KEY: z.string(), diff --git a/apps/website/src/lib/ghost.ts b/apps/website/src/lib/ghost.ts index cb7caf28..397dd33a 100644 --- a/apps/website/src/lib/ghost.ts +++ b/apps/website/src/lib/ghost.ts @@ -4,7 +4,7 @@ import { clientEnv } from '@/config/env.client.mjs' /** @see https://ghost.org/docs/content-api# */ const ghost = new GhostContentAPI({ - url: 'https://our.status.im', + url: clientEnv.NEXT_PUBLIC_GHOST_API_URL, key: clientEnv.NEXT_PUBLIC_GHOST_API_KEY, version: 'v5.0', }) @@ -62,7 +62,7 @@ export const getPostsByAuthorSlug = async (slug: string, page = 1) => { export const getPostSlugs = async (): Promise => { const posts = await ghost.posts.browse({ - limit: '7', + limit: 7, fields: 'slug', filter: 'visibility:public', }) @@ -72,7 +72,7 @@ export const getPostSlugs = async (): Promise => { export const getTags = async () => { return await ghost.tags.browse({ - limit: 'all', + limit: clientEnv.NEXT_PUBLIC_VERCEL_ENV === 'production' ? 'all' : 6, fields: 'name,slug', filter: 'visibility:public', }) @@ -80,7 +80,7 @@ export const getTags = async () => { export const getTagSlugs = async (): Promise => { const tags = await ghost.tags.browse({ - limit: 'all', + limit: clientEnv.NEXT_PUBLIC_VERCEL_ENV === 'production' ? 'all' : 6, fields: 'slug', filter: 'visibility:public', }) @@ -90,7 +90,7 @@ export const getTagSlugs = async (): Promise => { export const getAuthorSlugs = async (): Promise => { const authors = await ghost.authors.browse({ - limit: 'all', + limit: clientEnv.NEXT_PUBLIC_VERCEL_ENV === 'production' ? 'all' : 6, fields: 'slug', filter: 'visibility:public', })