Skip to content

Commit

Permalink
Enforce quote eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Apr 5, 2024
1 parent 14f5984 commit c0459bd
Show file tree
Hide file tree
Showing 95 changed files with 1,116 additions and 1,054 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
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;
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
18 changes: 9 additions & 9 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../src/styles/index.css';
import "../src/styles/index.css";
import BackToTop from "@components/elements/back-to-top";
import PageFooter from "@components/global/page-footer";
import PageHeader from "@components/global/page-header";
Expand All @@ -22,19 +22,19 @@ const icons: Icon[] = [16, 32, 96, 128, 192, 196].map(size => ({
* Metadata that does not change often.
*/
export const metadata = {
metadataBase: new URL('https://somesite.stanford.edu'),
title: 'Stanford University',
metadataBase: new URL("https://somesite.stanford.edu"),
title: "Stanford University",
openGraph: {
type: 'website',
locale: 'en_IE',
url: 'https://somesite.stanford.edu',
siteName: '[Stanford University]',
type: "website",
locale: "en_IE",
url: "https://somesite.stanford.edu",
siteName: "[Stanford University]",
},
twitter: {
card: 'summary_large_image',
card: "summary_large_image",
},
icons: {
icon: [{url: '/favicon.ico'}, ...icons],
icon: [{url: "/favicon.ico"}, ...icons],
apple: appleIcons
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import BannerParagraph from "@components/paragraphs/stanford-banner/banner-parag

// 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 Home = async () => {
const {entity, error} = await getEntityFromPath<NodeStanfordPage>('/', isPreviewMode());
const {entity, error} = await getEntityFromPath<NodeStanfordPage>("/", isPreviewMode());

if (error) throw new Error(error);
if (!entity) notFound();
Expand All @@ -32,7 +32,7 @@ const Home = async () => {
}

export const generateMetadata = async (): Promise<Metadata> => {
const {entity} = await getEntityFromPath<NodeUnion>('/')
const {entity} = await getEntityFromPath<NodeUnion>("/")
return entity ? getNodeMetadata(entity) : {};
}

Expand Down
13 changes: 3 additions & 10 deletions app/preview/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ import UnpublishedBanner from "@components/elements/unpublished-banner";
import {NodeUnion} from "@lib/gql/__generated__/drupal.d";
import {getEntityFromPath} from "@lib/gql/gql-queries";
import {notFound} from "next/navigation";
import Editori11y from "@components/tools/editorially";
import {getPathFromContext, isPreviewMode, PageProps} from "@lib/drupal/utils";

const Page = async ({params}: PageProps) => {
const path = getPathFromContext({params})
const PreviewPage = async ({params}: PageProps) => {
if (!isPreviewMode()) notFound();

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

if (error) throw new Error(error);
if (!entity) notFound();

return (
<>
<Editori11y/>
<UnpublishedBanner status={false}>
Preview Mode
</UnpublishedBanner>
<UnpublishedBanner status={entity.status}>
Unpublished Page
</UnpublishedBanner>
Expand All @@ -29,4 +22,4 @@ const Page = async ({params}: PageProps) => {
)
}

export default Page;
export default PreviewPage;
21 changes: 21 additions & 0 deletions app/preview/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {isPreviewMode} from "@lib/drupal/utils";
import Editori11y from "@components/tools/editorially";
import UnpublishedBanner from "@components/elements/unpublished-banner";

const Layout = ({children}: { children: React.ReactNode }) => {
const inPreview = isPreviewMode();
return (
<>
{inPreview &&
<>
<Editori11y/>
<UnpublishedBanner status={false}>
Preview Mode
</UnpublishedBanner>
</>
}
{children}
</>
)
}
export default Layout;
10 changes: 10 additions & 0 deletions app/preview/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {notFound} from "next/navigation";
import {isPreviewMode} from "@lib/drupal/utils";
import Page from "../page";

const PreviewPage = async () => {
if (!isPreviewMode()) notFound();
return <Page/>
}

export default PreviewPage;
Loading

0 comments on commit c0459bd

Please sign in to comment.