-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use nextJS draft mode instead of preview (#87)
- Loading branch information
Showing
25 changed files
with
252 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {draftMode} from 'next/headers' | ||
import {redirect} from "next/navigation"; | ||
|
||
export async function GET(request: Request) { | ||
draftMode().disable() | ||
redirect('/'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// route handler with secret and slug | ||
import {draftMode} from 'next/headers' | ||
import {redirect} from 'next/navigation' | ||
import {getResourceByPath} from "@/lib/drupal/get-resource"; | ||
import {DrupalNode} from "next-drupal"; | ||
|
||
export async function GET(request: Request) { | ||
// Parse query string parameters | ||
const {searchParams} = new URL(request.url) | ||
const secret = searchParams.get('secret') | ||
const slug = searchParams.get('slug') | ||
|
||
// Check the secret and next parameters | ||
// This secret should only be known to this route handler and the CMS | ||
if (secret !== process.env.DRUPAL_PREVIEW_SECRET || !slug) { | ||
return new Response('Invalid token', {status: 401}) | ||
} | ||
// Enable Draft Mode by setting the cookie | ||
draftMode().enable() | ||
|
||
if (slug.startsWith('/admin/paragraph')) { | ||
redirect(slug); | ||
} | ||
// Fetch the headless CMS t44343o check if the provided `slug` exists | ||
// getPostBySlug would implement the required fetching logic to the headless CMS | ||
const node = await getResourceByPath<DrupalNode>(slug, {draftMode: true}) | ||
|
||
// If the slug doesn't exist prevent draft mode from being enabled | ||
if (!node) { | ||
return new Response('Invalid slug', {status: 401}) | ||
} | ||
|
||
// Redirect to the path from the fetched post | ||
// We don't redirect to searchParams.slug as that might lead to open redirect vulnerabilities | ||
redirect(node.path.alias) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {ExclamationCircleIcon} from "@heroicons/react/20/solid"; | ||
|
||
const UnpublishedBanner = () => { | ||
return ( | ||
<div className="su-bg-illuminating su-py-10 su-text-3xl su-font-bold"> | ||
<div className="su-centered-container su-flex su-gap-10"><ExclamationCircleIcon width={20}/>Unpublished</div> | ||
</div> | ||
) | ||
} | ||
export default UnpublishedBanner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import Jsona from "jsona"; | ||
import {TDeserializeOptions, TJsonApiBody} from "jsona/src/JsonaTypes"; | ||
|
||
const dataFormatter = new Jsona() | ||
|
||
export const deserialize = (body, options?) => { | ||
export const deserialize = (body:TJsonApiBody | string, options?: TDeserializeOptions) => { | ||
if (!body) return null | ||
return dataFormatter.deserialize(body, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
93b359d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
su-library – ./
su-library-git-1x-stanford-libraries.vercel.app
su-library-stanford-libraries.vercel.app
library-netlify.stanford.edu
su-library.vercel.app
library.stanford.edu
library-prod.stanford.edu