Skip to content

Commit

Permalink
fix: update sites to handle unpublished entities
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn committed Jun 13, 2021
1 parent c1fc90a commit 93dd678
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/example-blog/pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function getStaticPaths(context) {
export async function getStaticProps(context) {
const page = await getResourceFromContext("node--page", context)

if (!page) {
if (!page?.status) {
return {
notFound: true,
}
Expand Down
2 changes: 2 additions & 0 deletions examples/example-blog/pages/blog/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function BlogPostPage({ post }) {
export async function getStaticPaths(context) {
let paths = await getPathsFromContext("node--article", context, {
params: {
"filter[status]": "1",
"fields[node--article]": "path,field_site",
},
})
Expand All @@ -86,6 +87,7 @@ export async function getStaticProps(context) {

if (
!post ||
!post.status ||
!post.field_site?.some(({ id }) => id === process.env.DRUPAL_SITE_ID)
) {
return {
Expand Down
1 change: 1 addition & 0 deletions examples/example-blog/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function getStaticProps(context) {
context,
{
params: {
"filter[status]": "1",
include: "field_image, uid",
sort: "-created",
},
Expand Down
4 changes: 2 additions & 2 deletions examples/example-marketing/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function getStaticProps(
params,
})

if (!page) {
if (!page?.status) {
return {
notFound: true,
}
Expand All @@ -80,6 +80,6 @@ export async function getStaticProps(
props: {
page,
},
revalidate: 60,
revalidate: 1,
}
}
3 changes: 2 additions & 1 deletion examples/example-marketing/pages/blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function getStaticProps(context) {
context,
{
params: {
"filter[status]": "1",
include: "field_image, uid",
sort: "-created",
},
Expand All @@ -45,6 +46,6 @@ export async function getStaticProps(context) {
props: {
articles,
},
revalidate: 60,
revalidate: 1,
}
}
10 changes: 8 additions & 2 deletions examples/example-marketing/pages/blog/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export default function BlogPostPage({ post, preview }) {
}

export async function getStaticPaths(context) {
let paths = await getPathsFromContext("node--article", context)
let paths = await getPathsFromContext("node--article", context, {
params: {
"filter[status]": "1",
"fields[node--article]": "path,field_site",
},
})

paths = paths.filter((entity) =>
entity.field_site?.some(({ id }) => id === process.env.DRUPAL_SITE_ID)
Expand All @@ -92,6 +97,7 @@ export async function getStaticProps(context) {

if (
!post ||
!post.status ||
!post.field_site?.some(({ id }) => id === process.env.DRUPAL_SITE_ID)
) {
return {
Expand All @@ -103,6 +109,6 @@ export async function getStaticProps(context) {
props: {
post,
},
revalidate: 60,
revalidate: 1,
}
}

1 comment on commit 93dd678

@vercel
Copy link

@vercel vercel bot commented on 93dd678 Jun 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.