feat: show draft posts/products on testing and staging
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 2m12s
Build & Deploy / 🏗️ Build (push) Successful in 4m37s
Build & Deploy / 🚀 Deploy (push) Successful in 15s
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 2m12s
Build & Deploy / 🏗️ Build (push) Successful in 4m37s
Build & Deploy / 🚀 Deploy (push) Successful in 15s
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
- Add config.showDrafts (true for dev/testing/staging, false for production) - Replace all isDev checks in blog.ts and products.ts with config.showDrafts - Previously only NODE_ENV=development showed drafts, missing testing/staging
This commit is contained in:
10
lib/blog.ts
10
lib/blog.ts
@@ -59,15 +59,14 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostD
|
||||
try {
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging';
|
||||
const { docs } = await payload.find({
|
||||
collection: 'posts',
|
||||
where: {
|
||||
slug: { equals: slug },
|
||||
...(!isDev ? { _status: { equals: 'published' } } : {}),
|
||||
...(!config.showDrafts ? { _status: { equals: 'published' } } : {}),
|
||||
},
|
||||
locale: locale as any,
|
||||
draft: isDev,
|
||||
draft: config.showDrafts,
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
@@ -107,15 +106,14 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostD
|
||||
export async function getAllPosts(locale: string): Promise<PostData[]> {
|
||||
try {
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
const isDev = process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging';
|
||||
const { docs } = await payload.find({
|
||||
collection: 'posts',
|
||||
where: {
|
||||
...(!isDev ? { _status: { equals: 'published' } } : {}),
|
||||
...(!config.showDrafts ? { _status: { equals: 'published' } } : {}),
|
||||
},
|
||||
locale: locale as any,
|
||||
sort: '-date',
|
||||
draft: isDev,
|
||||
draft: config.showDrafts,
|
||||
limit: 100,
|
||||
});
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ function createConfig() {
|
||||
isStaging: target === 'staging',
|
||||
isTesting: target === 'testing',
|
||||
isDevelopment: target === 'development',
|
||||
showDrafts: target === 'development' || target === 'testing' || target === 'staging',
|
||||
feedbackEnabled: env.NEXT_PUBLIC_FEEDBACK_ENABLED,
|
||||
gatekeeperUrl: env.GATEKEEPER_URL,
|
||||
|
||||
@@ -116,6 +117,9 @@ export const config = {
|
||||
get isDevelopment() {
|
||||
return getConfig().isDevelopment;
|
||||
},
|
||||
get showDrafts() {
|
||||
return getConfig().showDrafts;
|
||||
},
|
||||
get baseUrl() {
|
||||
return getConfig().baseUrl;
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getPayload } from 'payload';
|
||||
import configPromise from '@payload-config';
|
||||
import { mapSlugToFileSlug } from './slugs';
|
||||
import { config } from '@/lib/config';
|
||||
|
||||
export interface ProductFrontmatter {
|
||||
title: string;
|
||||
@@ -26,13 +27,12 @@ export async function getProductMetadata(
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging';
|
||||
const result = await payload.find({
|
||||
collection: 'products',
|
||||
where: {
|
||||
and: [
|
||||
{ slug: { equals: fileSlug } },
|
||||
...(!isDev ? [{ _status: { equals: 'published' } }] : []),
|
||||
...(!config.showDrafts ? [{ _status: { equals: 'published' } }] : []),
|
||||
],
|
||||
},
|
||||
locale: locale as any,
|
||||
@@ -70,13 +70,12 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging';
|
||||
const result = await payload.find({
|
||||
collection: 'products',
|
||||
where: {
|
||||
and: [
|
||||
{ slug: { equals: fileSlug } },
|
||||
...(!isDev ? [{ _status: { equals: 'published' } }] : []),
|
||||
...(!config.showDrafts ? [{ _status: { equals: 'published' } }] : []),
|
||||
],
|
||||
},
|
||||
locale: locale as any,
|
||||
@@ -127,11 +126,10 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
||||
export async function getAllProductSlugs(locale: string): Promise<string[]> {
|
||||
try {
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
const isDev = process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging';
|
||||
const result = await payload.find({
|
||||
collection: 'products',
|
||||
where: {
|
||||
...(!isDev ? { _status: { equals: 'published' } } : {}),
|
||||
...(!config.showDrafts ? { _status: { equals: 'published' } } : {}),
|
||||
},
|
||||
locale: locale as any,
|
||||
pagination: false,
|
||||
@@ -157,11 +155,10 @@ export async function getAllProducts(locale: string): Promise<ProductData[]> {
|
||||
images: true,
|
||||
} as const;
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging';
|
||||
const result = await payload.find({
|
||||
collection: 'products',
|
||||
where: {
|
||||
...(!isDev ? { _status: { equals: 'published' } } : {}),
|
||||
...(!config.showDrafts ? { _status: { equals: 'published' } } : {}),
|
||||
},
|
||||
locale: locale as any,
|
||||
depth: 1,
|
||||
|
||||
Reference in New Issue
Block a user