Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jenbreese committed Apr 8, 2024
2 parents 8f50956 + 7c8f24f commit fecc45e
Show file tree
Hide file tree
Showing 97 changed files with 1,170 additions and 1,092 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"warn",
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
],
"no-console": ["error", { "allow": ["warn"] }]
"no-console": ["error", { "allow": ["warn"] }],
"quotes": ["error", "double"]
},
"plugins": ["unused-imports"],
"ignorePatterns": ["**/__generated__/**/*"]
Expand Down
52 changes: 27 additions & 25 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -30,20 +30,21 @@ tasks:
init: >
eval $(gp env -e APACHE_DOCROOT_IN_REPO=../back/docroot) &&
cd /workspace/back &&
git checkout 2.x &&
rm -rf config/default &&
mkdir -p config/default &&
touch config/default/core.extension.yml &&
composer install --no-interaction &&
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 &&
Expand All @@ -55,41 +56,42 @@ tasks:
eval $(gp env -e APACHE_DOCROOT_IN_REPO=../back/docroot) &&
apache2ctl restart &&
gp ports await 8001 &&
find docroot -name 'local.drush.yml' | xargs rm -rf &&
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 "<?php \$sites['$PREVIEW_URL'] = 'supress';" > 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 &&
git remote set-url origin $(echo $GITPOD_WORKSPACE_CONTEXT | jq -r .repository.cloneUrl | sed -E 's|^.*.com/(.*)$|git@github.com:\1|')
gp url 3000 | xargs gp preview --external
- name: SSH Keys
before: |
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
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|')
vscode:
extensions:
- bradlc.vscode-tailwindcss
- bradlc.vscode-tailwindcss
32 changes: 16 additions & 16 deletions app/[...slug]/metadata.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import {Maybe, NodeStanfordEvent, NodeStanfordNews, NodeStanfordPage, NodeStanfordPerson, NodeStanfordPolicy, NodeUnion, ParagraphStanfordWysiwyg, ParagraphUnion} from "@lib/gql/__generated__/drupal.d";
import {Metadata} from "next";
import {decode} from 'html-entities';
import {decode} from "html-entities";

export const getNodeMetadata = (node: NodeUnion): Metadata => {
const defaultData = {
title: node.title,
other: {}
}
switch (node.__typename) {
case 'NodeStanfordPage':
case "NodeStanfordPage":
return {
...getBasicPageMetaData(node),
...defaultData
}

case 'NodeStanfordNews':
case "NodeStanfordNews":
return {
...getNewsMetaData(node),
...defaultData
}

case 'NodeStanfordEvent':
case "NodeStanfordEvent":
return {
...getEventMetaData(node),
...defaultData
}

case 'NodeStanfordPerson':
case "NodeStanfordPerson":
return {
...getPersonMetaData(node),
...defaultData
}

case 'NodeStanfordPolicy':
case "NodeStanfordPolicy":
return {
...getPolicyMetaData(node),
...defaultData
Expand All @@ -52,7 +52,7 @@ const getBasicPageMetaData = (node: NodeStanfordPage) => {
return {
description: description,
openGraph: {
type: 'website',
type: "website",
title: node.title,
description: description,
images: image ? getOpenGraphImage(image.url, image.alt || "") : []
Expand All @@ -62,10 +62,10 @@ const getBasicPageMetaData = (node: NodeStanfordPage) => {

const getNewsMetaData = (node: NodeStanfordNews) => {
const pageImage = node.suNewsFeaturedMedia?.mediaImage;
const bannerImage = node.suNewsBanner?.__typename === 'MediaImage' ? node.suNewsBanner.mediaImage : undefined;
const bannerImage = node.suNewsBanner?.__typename === "MediaImage" ? node.suNewsBanner.mediaImage : undefined;

const imageUrl = pageImage?.url || bannerImage?.url
const imageAlt = pageImage?.alt || bannerImage?.alt || '';
const imageAlt = pageImage?.alt || bannerImage?.alt || "";

const description = node.suNewsDek || getFirstText(node.suNewsComponents);

Expand All @@ -77,7 +77,7 @@ const getNewsMetaData = (node: NodeStanfordNews) => {
return {
description: description,
openGraph: {
type: 'article',
type: "article",
title: node.title,
description: description,
publishedTime: publishTime || null,
Expand All @@ -90,13 +90,13 @@ const getNewsMetaData = (node: NodeStanfordNews) => {
const getPersonMetaData = (node: NodeStanfordPerson) => {
const pageImage = node.suPersonPhoto?.mediaImage;
const imageUrl = pageImage?.url;
const imageAlt = pageImage?.alt || '';
const imageAlt = pageImage?.alt || "";
const description = node.suPersonFullTitle || getCleanDescription(node.body?.processed);

return {
description: description,
openGraph: {
type: 'profile',
type: "profile",
title: node.title,
description: description,
firstName: node.suPersonFirstName,
Expand All @@ -112,7 +112,7 @@ const getEventMetaData = (node: NodeStanfordEvent) => {
return {
description: description,
openGraph: {
type: 'website',
type: "website",
title: node.title,
description: description,
}
Expand All @@ -125,23 +125,23 @@ const getPolicyMetaData = (node: NodeStanfordPolicy) => {
return {
description: description,
openGraph: {
type: 'website',
type: "website",
title: node.title,
description: description,
}
}
}

const getFirstText = (components?: Maybe<ParagraphUnion[]>) => {
const firstWysiwyg = components?.find(component => component.__typename === 'ParagraphStanfordWysiwyg') as ParagraphStanfordWysiwyg;
const firstWysiwyg = components?.find(component => component.__typename === "ParagraphStanfordWysiwyg") as ParagraphStanfordWysiwyg;
if (firstWysiwyg) {
return getCleanDescription(firstWysiwyg.suWysiwygText?.processed);
}
}

const getCleanDescription = (description: string | undefined): string | undefined => {
if (description) {
const text: string = description.replace(/(<([^>]+)>)/gi, " ").replace('/ +/', ' ').split('.').slice(0, 1).join('.') + '.';
const text: string = description.replace(/(<([^>]+)>)/gi, " ").replace("/ +/", " ").split(".").slice(0, 1).join(".") + ".";
return text?.length > 1 ? decode(text) : undefined;
}
}
Expand Down
10 changes: 4 additions & 6 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import {getPathFromContext, PageProps} from "@lib/drupal/utils";

// https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
export const revalidate = false;
export const dynamic = 'force-static';
export const dynamic = "force-static";

const Page = async ({params}: PageProps) => {
const path = getPathFromContext({params})

const {redirect: redirectPath, entity, error} = await getEntityFromPath<NodeUnion>(path)
const {redirect: redirectPath, entity, error} = await getEntityFromPath<NodeUnion>(getPathFromContext({params}))

if (error) throw new Error(error);
if (redirectPath?.url) redirect(redirectPath.url)
Expand All @@ -29,9 +27,9 @@ export const generateMetadata = async ({params}: PageProps): Promise<Metadata> =
}

export const generateStaticParams = async (): Promise<PageProps["params"][]> => {
if (process.env.BUILD_COMPLETE !== 'true') return []
if (process.env.BUILD_COMPLETE !== "true") return []
const nodePaths = await getAllNodePaths();
return nodePaths.map(path => ({slug: path.split('/').filter(part => !!part)}));
return nodePaths.map(path => ({slug: path.split("/").filter(part => !!part)}));
}

export default Page;
9 changes: 9 additions & 0 deletions app/api/draft/disable/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {NextResponse} from "next/server";
import {cookies} from "next/headers";

export const revalidate = 0;

export async function GET() {
cookies().delete("preview");
return NextResponse.json({disabled: true}, {status: 200})
}
18 changes: 9 additions & 9 deletions app/api/draft/route.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import {NextRequest, NextResponse} from "next/server";
import {redirect} from 'next/navigation'
import {redirect} from "next/navigation"
import {cookies} from "next/headers";

export const revalidate = 0;

export async function GET(request: NextRequest) {

const secret = request.nextUrl.searchParams.get('secret')
const slug = request.nextUrl.searchParams.get('slug')
const secret = request.nextUrl.searchParams.get("secret")
const slug = request.nextUrl.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) {
return NextResponse.json({message: 'Invalid token'}, {status: 401})
return NextResponse.json({message: "Invalid token"}, {status: 401})
}

if (!slug) {
return NextResponse.json({message: 'Invalid slug path'}, {status: 401})
return NextResponse.json({message: "Invalid slug path"}, {status: 401})
}
cookies().set('preview', secret, {
cookies().set("preview", secret, {
maxAge: 60 * 60,
httpOnly: true,
sameSite: 'none',
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(`/preview/${slug}`)
// We don"t redirect to searchParams.slug as that might lead to open redirect vulnerabilities
redirect(`/preview${slug === "/home" ? "" : slug}`)
}
12 changes: 6 additions & 6 deletions app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export const revalidate = 0;

export const GET = async (request: NextRequest) => {

const secret = request.nextUrl.searchParams.get('secret');
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) return NextResponse.json({message: 'Invalid token'}, {status: 403});
const secret = request.nextUrl.searchParams.get("secret");
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) return NextResponse.json({message: "Invalid token"}, {status: 403});

let path = request.nextUrl.searchParams.get('slug');
if (!path || path.startsWith('/node/')) return NextResponse.json({message: 'Invalid slug'}, {status: 400});
let path = request.nextUrl.searchParams.get("slug");
if (!path || path.startsWith("/node/")) return NextResponse.json({message: "Invalid slug"}, {status: 400});

const tagsInvalidated = ['paths', `paths:${path}`];
if (path.startsWith('/tags/')) path.substring(6).split('/').map(tag => tagsInvalidated.push(tag))
const tagsInvalidated = ["paths", `paths:${path}`];
if (path.startsWith("/tags/")) path.substring(6).split("/").map(tag => tagsInvalidated.push(tag))

tagsInvalidated.map(tag => revalidateTag(tag));
nodeCache.del(tagsInvalidated)
Expand Down
10 changes: 7 additions & 3 deletions app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"use client";

import Button from "@components/elements/button";

const ErrorPage = ({error, reset}: { error: Error; reset: () => void }) => {
console.warn(error.message);
return (
<div className="centered my-50 mt-32">
<h1>Something went wrong!</h1>
Apologies, an error occurred when attempting to preset the page you are attempting to view. Please try a different
path.
<button onClick={() => reset()}>Try again</button>
<p>
Apologies, an error occurred when attempting to preset the page you are attempting to view. Please try a
different path.
</p>
<Button buttonElem onClick={() => reset()}>Try again</Button>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/gallery/[...uuid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ParagraphStanfordGallery} from "@lib/gql/__generated__/drupal";
import Image from "next/image";

export const metadata = {
title: 'Gallery Image',
title: "Gallery Image",
robots: {
index: false
}
Expand Down
Loading

0 comments on commit fecc45e

Please sign in to comment.