diff --git a/.gitpod.yml b/.gitpod.yml index b64f371f..7103f35f 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,6 +1,6 @@ additionalRepositories: - - url: https://github.com/SU-SWS/ace-stanfordlagunita/ + - url: https://github.com/SU-SWS/acsf-cardinalsites-public checkoutLocation: back checkoutLocation: front ports: @@ -37,12 +37,14 @@ tasks: mkdir -p blt && cp .gitpod/blt.yml blt/local.blt.yml && find docroot/sites/ -name 'local*' | xargs rm -rf && + cp .gitpod/global.settings.php docroot/sites/settings/global.settings.php && + cp .gitpod/default.local.services.yml docroot/sites/local.services.yml && export NEXT_PUBLIC_DRUPAL_BASE_URL=`gp url 8001` && export PREVIEW_URL=${NEXT_PUBLIC_DRUPAL_BASE_URL#"https://"} && blt blt:telemetry:disable --no-interaction && blt settings && - blt drupal:install --site=supress -n && - drush @supress.local cset system.theme default stanford_profile_admin_theme -y && + blt drupal:install -n && + drush cset system.theme default claro -y && cd /workspace/front && cp .env.example .env.local && sed -i 's/#DRUPAL_REVALIDATE_SECRET/DRUPAL_REVALIDATE_SECRET/' .env.local && @@ -57,37 +59,38 @@ tasks: find docroot -name 'local.drush.yml' | xargs rm && export NEXT_PUBLIC_DRUPAL_BASE_URL=`gp url 8001` && export PREVIEW_URL=${NEXT_PUBLIC_DRUPAL_BASE_URL#"https://"} && - echo " docroot/sites/local.sites.php && blt blt:telemetry:disable --no-interaction && echo 'Establishing Settings' && blt settings && echo 'Logging Into Drupal' && - drush @supress.local uli --uri=$NEXT_PUBLIC_DRUPAL_BASE_URL && - drush @supress.local uli --uri=$NEXT_PUBLIC_DRUPAL_BASE_URL | xargs gp preview --external && + drush uli --uri=$NEXT_PUBLIC_DRUPAL_BASE_URL && + drush uli --uri=$NEXT_PUBLIC_DRUPAL_BASE_URL | xargs gp preview --external && git config core.fileMode false && echo 'Connecting Drupal to Frontend' && - drush @supress.local su-next-connect "$(gp url 3000)" --preview-secret=DRUPAL_PREVIEW_SECRET --revalidation-secret=DRUPAL_REVALIDATION_SECRET && + drush su-next-connect "$(gp url 3000)" --preview-secret=DRUPAL_PREVIEW_SECRET --revalidation-secret=DRUPAL_REVALIDATION_SECRET && cd /workspace/front && yarn install && - yarn config set --home enableTelemetry 0 && - yarn next telemetry disable && sed -i -r "s|NEXT_PUBLIC_DRUPAL_BASE_URL.*|NEXT_PUBLIC_DRUPAL_BASE_URL=$NEXT_PUBLIC_DRUPAL_BASE_URL|g" .env.local && yarn dev & gp ports await 3000 && gp url 3000 | xargs gp preview --external - name: SSH Keys command: | + rm -rf ~/.ssh/id_rsa && + rm -rf ~/.ssh/id_rsa.pub && + eval $(command gp env -e) && + mkdir -p ~/.ssh && + [[ ! -z $SSH_PUBLIC_KEY ]] && + echo $SSH_PUBLIC_KEY | base64 -d > ~/.ssh/id_rsa.pub && + chmod 644 ~/.ssh/id_rsa.pub && + [[ ! -z $SSH_PRIVATE_KEY ]] && + echo $SSH_PRIVATE_KEY | base64 -d > ~/.ssh/id_rsa && + chmod 600 ~/.ssh/id_rsa && + cd /workspace/front && + [[ ! -z $GITCONFIG ]] && + echo $GITCONFIG | base64 -d > ~/.gitconfig && + chmod 644 ~/.gitconfig git remote set-url origin $(echo $GITPOD_WORKSPACE_CONTEXT | jq -r .repository.cloneUrl | sed -E 's|^.*.com/(.*)$|git@github.com:\1|') - mkdir -p ~/.ssh - if [[ ! -z $SSH_PUBLIC_KEY ]]; then - echo $SSH_PUBLIC_KEY | base64 -d > ~/.ssh/id_rsa.pub && chmod 644 ~/.ssh/id_rsa.pub - fi - if [[ ! -z $SSH_PRIVATE_KEY ]]; then - echo $SSH_PRIVATE_KEY | base64 -d > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa - fi - if [[ ! -z $GITCONFIG ]]; then - echo $GITCONFIG | base64 -d > ~/.gitconfig && chmod 644 ~/.gitconfig - fi vscode: extensions: diff --git a/app/[...slug]/page.tsx b/app/[...slug]/page.tsx index f71fb39e..fde7eb7d 100644 --- a/app/[...slug]/page.tsx +++ b/app/[...slug]/page.tsx @@ -1,11 +1,10 @@ import NodePage from "@components/nodes/pages/node-page"; -import UnpublishedBanner from "@components/elements/unpublished-banner"; import {Metadata} from "next"; import {NodeUnion} from "@lib/gql/__generated__/drupal.d"; import {getAllNodePaths, getEntityFromPath} from "@lib/gql/gql-queries"; import {getNodeMetadata} from "./metadata"; -import {isDraftMode} from "@lib/drupal/utils"; import {notFound, redirect} from "next/navigation"; +import {getPathFromContext, PageProps} from "@lib/drupal/utils"; // https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config export const revalidate = false; @@ -13,28 +12,17 @@ export const dynamic = 'force-static'; const Page = async ({params}: PageProps) => { const path = getPathFromContext({params}) - const inDraft = isDraftMode(); - const {redirect: redirectPath, entity, error} = await getEntityFromPath(path, inDraft) + const {redirect: redirectPath, entity, error} = await getEntityFromPath(path) if (error) throw new Error(error); if (redirectPath?.url) redirect(redirectPath.url) if (!entity) notFound(); - return ( - <> - - Unpublished Page - - - - ) + return } export const generateMetadata = async ({params}: PageProps): Promise => { - // If the user is in draft mode, there's no need to emit any customized metadata. - if (isDraftMode()) return {}; - const path = getPathFromContext({params}) const {entity} = await getEntityFromPath(path) return entity ? getNodeMetadata(entity) : {}; @@ -46,18 +34,4 @@ export const generateStaticParams = async (): Promise => return nodePaths.map(path => ({slug: path.split('/').filter(part => !!part)})); } -const getPathFromContext = (context: PageProps, prefix = ""): string => { - let {slug} = context.params - - slug = Array.isArray(slug) ? slug.map((s) => encodeURIComponent(s)).join("/") : slug - slug = slug.replace(/^\//, ''); - return prefix ? `${prefix}/${slug}` : `/${slug}` -} - -type PageProps = { - params: { slug: string | string[] } - searchParams?: Record -} - - export default Page; \ No newline at end of file diff --git a/app/api/draft/disable/route.tsx b/app/api/draft/disable/route.tsx deleted file mode 100644 index 8b383737..00000000 --- a/app/api/draft/disable/route.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import {NextResponse} from "next/server"; -import {draftMode} from 'next/headers' - -export const revalidate = 0; - -export async function GET() { - draftMode().disable() - return NextResponse.json({disabled: true}); -} \ No newline at end of file diff --git a/app/api/draft/route.tsx b/app/api/draft/route.tsx index 77ff0429..e0d78e7f 100644 --- a/app/api/draft/route.tsx +++ b/app/api/draft/route.tsx @@ -1,6 +1,6 @@ import {NextRequest, NextResponse} from "next/server"; -import {draftMode} from 'next/headers' import {redirect} from 'next/navigation' +import {cookies} from "next/headers"; export const revalidate = 0; @@ -18,10 +18,15 @@ export async function GET(request: NextRequest) { if (!slug) { return NextResponse.json({message: 'Invalid slug path'}, {status: 401}) } - - draftMode().enable() + cookies().set('preview', secret, { + maxAge: 60 * 60, + httpOnly: true, + sameSite: 'none', + secure: true, + partitioned: true, + }); // Redirect to the path from the fetched post // We don't redirect to searchParams.slug as that might lead to open redirect vulnerabilities - redirect(slug) + redirect(`/preview/${slug}`) } \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index a3334945..dc5ec287 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,17 +1,12 @@ import '../src/styles/index.css'; import BackToTop from "@components/elements/back-to-top"; -import DrupalWindowSync from "@components/elements/drupal-window-sync"; -import Editori11y from "@components/tools/editorially"; -import Link from "@components/elements/link"; import PageFooter from "@components/global/page-footer"; import PageHeader from "@components/global/page-header"; -import Script from "next/script"; -import {GoogleAnalytics} from "@next/third-parties/google"; import {Icon} from "next/dist/lib/metadata/types/metadata-types"; -import {StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"; -import {getConfigPage} from "@lib/gql/gql-queries"; -import {isDraftMode} from "@lib/drupal/utils"; import {sourceSans3} from "../src/styles/fonts"; +import DrupalWindowSync from "@components/elements/drupal-window-sync"; +import {isPreviewMode} from "@lib/drupal/utils"; +import UserAnalytics from "@components/elements/user-analytics"; const appleIcons: Icon[] = [60, 72, 76, 114, 120, 144, 152, 180].map(size => ({ url: `https://www-media.stanford.edu/assets/favicon/apple-touch-icon-${size}x${size}.png`, @@ -47,30 +42,20 @@ export const metadata = { // https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config export const revalidate = false; -const RootLayout = async ({children, modal}: { children: React.ReactNode, modal: React.ReactNode }) => { - const draftMode = isDraftMode(); - const siteSettingsConfig = await getConfigPage('StanfordBasicSiteSetting') +const RootLayout = ({children, modal}: { children: React.ReactNode, modal: React.ReactNode }) => { + const isPreview = isPreviewMode(); return ( - {draftMode && <>} - - {/* Add Google Analytics and SiteImprove when not in draft mode. */} - {(!draftMode && siteSettingsConfig?.suGoogleAnalytics) && - <> -