Skip to content

Commit

Permalink
Merge pull request #164 from SU-SWS/1.x
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
imonroe authored Jul 10, 2024
2 parents 2948499 + fccb5c0 commit ce531d5
Show file tree
Hide file tree
Showing 44 changed files with 2,251 additions and 893 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ NEXT_PUBLIC_DRUPAL_BASE_URL=https://library-dev.sites-pro.stanford.edu
NEXT_PUBLIC_SITE_NAME=Local Environment

# Grab these from the Vercel Environment Variables.
#DRUPAL_DRAFT_CLIENT=DRUPAL_DRAFT_CLIENT
#DRUPAL_DRAFT_SECRET=DRUPAL_DRAFT_SECRET
#DRUPAL_PREVIEW_SECRET=DRUPAL_PREVIEW_SECRET
#DRUPAL_REVALIDATE_SECRET=DRUPAL_REVALIDATE_SECRET
#DRUPAL_BASIC_AUTH=foo:bar
#DRUPAL_BASIC_AUTH_ADMIN=bar:foo

# LibApps credentials.
#LIBGUIDE_CLIENT_ID=LIBGUIDE_CLIENT_ID
#LIBGUIDE_CLIENT_SECRET=LIBGUIDE_CLIENT_SECRET

# To build every page when running `yarn build`, change this to 'true' (prod environment).
BUILD_COMPLETE=false
BUILD_COMPLETE=false
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"unused-imports/no-unused-vars": [
"warn",
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
]
],
"no-console": ["error", { "allow": ["warn", "error"] }]
},
"plugins": ["unused-imports"],
"ignorePatterns": ["**/__generated__/**/*", "src/styles/tailwind/**"]
Expand Down
11 changes: 11 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | grep \.tsx$)
[ -z "$FILES" ] && exit 0

# Prettify all selected files
echo "$FILES" | xargs ./node_modules/.bin/prettier --ignore-unknown --write

# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add

exit 0
6 changes: 4 additions & 2 deletions .github/workflows/build_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ jobs:
LIBGUIDE_CLIENT_SECRET: ${{ secrets.LIBGUIDE_CLIENT_SECRET }}
NEXT_PUBLIC_DRUPAL_BASE_URL: ${{ secrets.NEXT_PUBLIC_DRUPAL_BASE_URL }}
NEXT_PUBLIC_SITE_NAME: ${{ secrets.NEXT_PUBLIC_SITE_NAME }}
DRUPAL_BASIC_AUTH: ${{ secrets.DRUPAL_BASIC_AUTH }}
DRUPAL_BASIC_AUTH_ADMIN: ${{ secrets.DRUPAL_BASIC_AUTH_ADMIN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Restore Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
node_modules
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
pr-labeler:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# .github/workflows/release.yml
name: Release

on:
pull_request:
types: [closed]

jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
if: github.event.pull_request.merged
steps:
- name: Get Next Release
id: tag
uses: K-Phoen/semver-release-action@master
with:
release_strategy: none
release_branch: main
tag_format: "%major%.%minor%.%patch%"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
if: ${{ steps.tag.outputs.tag }}
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ steps.tag.outputs.tag }}
tag: ${{ steps.tag.outputs.tag }}
commit: ${{ github.sha }}
generateReleaseNotes: true
makeLatest: true
2 changes: 1 addition & 1 deletion .github/workflows/update-dev-test-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
NEXT_PUBLIC_DRUPAL_BASE_URL: ${{ secrets.NEXT_PUBLIC_DRUPAL_BASE_URL }}
NEXT_IMAGE_DOMAIN: ${{ secrets.NEXT_IMAGE_DOMAIN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 1.x
Expand Down
6 changes: 2 additions & 4 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ tasks:
blt drupal:install --site=library -n &&
drush @library.local cset system.theme default stanford_profile_admin_theme -y &&
cd /workspace/front &&
cp .env.example .env.local &&
sed -i 's/#DRUPAL_REVALIDATE_SECRET/DRUPAL_REVALIDATE_SECRET/' .env.local &&
sed -i 's/#DRUPAL_PREVIEW_SECRET/DRUPAL_PREVIEW_SECRET/' .env.local &&
yarn install
command: |
cp .env.example .env.local &&
gp ports await 3306 &&
eval $(gp env -e APACHE_DOCROOT_IN_REPO=../back/docroot) &&
cd /workspace/back &&
Expand All @@ -61,7 +59,7 @@ tasks:
drush @library.local uli --uri=$NEXT_PUBLIC_DRUPAL_BASE_URL | xargs gp preview --external &&
git config core.fileMode false &&
echo 'Connecting Drupal to Frontend' &&
drush @library.local su-next-connect "$(gp url 3000)" --preview-secret=DRUPAL_PREVIEW_SECRET --revalidation-secret=DRUPAL_REVALIDATION_SECRET &&
drush @library.local su-next-connect "$(gp url 3000)" >> /workspace/front/.env.local &&
cd /workspace/front &&
yarn install &&
yarn config set --home enableTelemetry 0 &&
Expand Down
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"arrowParens": "avoid",
"bracketSameLine": false,
"bracketSpacing": false,
"printWidth": 500,
"semi": false,
"singleAttributePerLine": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"plugins": ["prettier-plugin-tailwindcss"]
}
136 changes: 67 additions & 69 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,113 +1,111 @@
import NodePageDisplay from "@/components/node";
import {notFound, redirect} from "next/navigation";
import {Metadata} from "next";
import {getNodeMetadata} from "./metadata";
import LibraryHeader from "@/components/node/sul-library/library-header";
import InternalHeaderBanner from "@/components/patterns/internal-header-banner";
import SecondaryMenu from "@/components/menu/secondary-menu";
import {isPreviewMode} from "@/lib/drupal/is-draft-mode";
import UnpublishedBanner from "@/components/patterns/unpublished-banner";
import {getAllNodePaths, getEntityFromPath, getMenu} from "@/lib/gql/fetcher";
import {NodeUnion} from "@/lib/gql/__generated__/drupal.d";

export const revalidate = false;
export const dynamic = 'force-static';
import NodePageDisplay from "@/components/node"
import {notFound, redirect} from "next/navigation"
import {Metadata} from "next"
import {getNodeMetadata} from "./metadata"
import LibraryHeader from "@/components/node/sul-library/library-header"
import InternalHeaderBanner from "@/components/patterns/internal-header-banner"
import SecondaryMenu from "@/components/menu/secondary-menu"
import {isPreviewMode} from "@/lib/drupal/is-draft-mode"
import {getAllNodePaths, getEntityFromPath, getMenu} from "@/lib/gql/fetcher"
import {NodeUnion} from "@/lib/gql/__generated__/drupal.d"
import EditorAlertBanner from "@/components/patterns/elements/editor-alert-banner"

export const revalidate = false
export const dynamic = "force-static"

const NodePage = async ({params, previewMode}: PageProps) => {
const path = getPathFromContext({params});
const {redirect: routeRedirect, entity} = await getEntityFromPath<NodeUnion>(path, previewMode);
const path = getPathFromContext({params})
const {redirect: routeRedirect, entity} = await getEntityFromPath<NodeUnion>(path, previewMode)

if (routeRedirect) redirect(routeRedirect.url);
if (!entity) notFound();
if (routeRedirect) redirect(routeRedirect.url)
if (!entity) notFound()

const menuItems = await getMenu()

const fullWidth = (entity.__typename === 'NodeStanfordPage' && entity.layoutSelection?.id === 'stanford_basic_page_full') ||
(entity.__typename === 'NodeSulLibrary' && entity.layoutSelection?.id === 'sul_library_full_width');
const fullWidth = (entity.__typename === "NodeStanfordPage" && entity.layoutSelection?.id === "stanford_basic_page_full") || (entity.__typename === "NodeSulLibrary" && entity.layoutSelection?.id === "sul_library_full_width")

return (
<main id="main-content" className="mb-50">
{!entity.status &&
<UnpublishedBanner/>
}
{entity.__typename === 'NodeSulLibrary' &&
<LibraryHeader node={entity}/>
}

{entity.__typename === 'NodeStanfordNews' &&
<main
id="main-content"
className="mb-50"
>
{!entity.status && <EditorAlertBanner message="Unpublished Content" />}
{entity.__typename === "NodeSulLibrary" && <LibraryHeader node={entity} />}

{entity.__typename === "NodeStanfordNews" && (
<InternalHeaderBanner>
<div
className="flex flex-col w-full max-w-[calc(100vw-10rem)] md:max-w-[calc(100vw-20rem)] 3xl:max-w-[calc(1500px-20rem)] mx-auto mt-80 md:mt-100 mb-50 p-0">
<h1
className="text-white order-2">
{entity.title}
</h1>

{entity.suNewsTopics &&
<div className="mb-20 order-1">
{entity.suNewsTopics.slice(0, 1).map(topic =>
<span key={topic.id} className="text-illuminating-dark font-semibold">{topic.name}</span>
)}
<div className="mx-auto mb-50 mt-80 flex w-full max-w-[calc(100vw-10rem)] flex-col p-0 md:mt-100 md:max-w-[calc(100vw-20rem)] 3xl:max-w-[calc(1500px-20rem)]">
<h1 className="order-2 text-white">{entity.title}</h1>

{entity.suNewsTopics && (
<div className="order-1 mb-20">
{entity.suNewsTopics.slice(0, 1).map(topic => (
<span
key={topic.id}
className="font-semibold text-illuminating-dark"
>
{topic.name}
</span>
))}
</div>
}
)}
</div>
</InternalHeaderBanner>
}
)}

{!(entity.__typename === 'NodeSulLibrary' || entity.__typename === 'NodeStanfordNews') &&
{!(entity.__typename === "NodeSulLibrary" || entity.__typename === "NodeStanfordNews") && (
<InternalHeaderBanner>
<h1
className="w-full max-w-[calc(100vw-10rem)] md:max-w-[calc(100vw-20rem)] 3xl:max-w-[calc(1500px-20rem)] mx-auto relative text-white mt-80 md:mt-100 mb-50 p-0">
{entity.title}
</h1>
<h1 className="relative mx-auto mb-50 mt-80 w-full max-w-[calc(100vw-10rem)] p-0 text-white md:mt-100 md:max-w-[calc(100vw-20rem)] 3xl:max-w-[calc(1500px-20rem)]">{entity.title}</h1>
</InternalHeaderBanner>
}
)}

{fullWidth &&
{fullWidth && (
<div>
<NodePageDisplay node={entity}/>
<NodePageDisplay node={entity} />
</div>
}
)}

{!fullWidth &&
<div className="centered flex flex-col lg:flex-row justify-between gap-[8rem]">
<div className="flex-1 order-last">
<NodePageDisplay node={entity}/>
{!fullWidth && (
<div className="centered flex flex-col justify-between gap-[8rem] lg:flex-row">
<div className="order-last flex-1">
<NodePageDisplay node={entity} />
</div>

<SecondaryMenu menuItems={menuItems} currentPath={entity.path}/>
<SecondaryMenu
menuItems={menuItems}
currentPath={entity.path}
/>
</div>
}
)}
</main>
)
}

export const generateMetadata = async ({params}: PageProps): Promise<Metadata> => {
if (isPreviewMode()) return {};
const path = getPathFromContext({params});
const {entity} = await getEntityFromPath<NodeUnion>(path);
if (isPreviewMode()) return {}
const path = getPathFromContext({params})
const {entity} = await getEntityFromPath<NodeUnion>(path)
return entity ? getNodeMetadata(entity) : {}
}

export const generateStaticParams = async (): Promise<PageProps["params"][]> => {
if (process.env.BUILD_COMPLETE !== 'true') return []
const nodePaths = await getAllNodePaths();
return nodePaths.map(path => ({slug: path.split('/').filter(part => !!part)}));
if (process.env.BUILD_COMPLETE !== "true") return []
const nodePaths = await getAllNodePaths()
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(/^\//, '');
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[] }
params: {slug: string | string[]}
searchParams?: Record<string, string | string[] | undefined>
previewMode?: boolean
}


export default NodePage;
export default NodePage
22 changes: 10 additions & 12 deletions app/preview/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import {ReactNode} from "react";
import {isPreviewMode} from "@/lib/drupal/is-draft-mode";
import Editori11y from "@/components/editori11y";
import {ExclamationCircleIcon} from "@heroicons/react/20/solid";
import {ReactNode} from "react"
import {isPreviewMode} from "@/lib/drupal/is-draft-mode"
import Editori11y from "@/components/editori11y"
import EditorAlertBanner from "@/components/patterns/elements/editor-alert-banner"

const RootLayout = ({children}: { children: ReactNode }) => {
const RootLayout = ({children}: {children: ReactNode}) => {
const previewMode = isPreviewMode()
return (
<>
{previewMode &&
{previewMode && (
<>
<div className="bg-illuminating py-10 text-3xl font-bold">
<div className="centered-container flex gap-10"><ExclamationCircleIcon width={20}/>Previewing Content</div>
</div>
<Editori11y/>
<EditorAlertBanner message="Previewing Content" />
<Editori11y />
</>
}
)}
{children}
</>
)
}
export default RootLayout;
export default RootLayout
12 changes: 11 additions & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import {CodegenConfig} from '@graphql-codegen/cli';

const drupalUrl = `${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/graphql`;

const config: CodegenConfig = {
overwrite: true,
schema: `${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/graphql` as string,
schema: [
{
[drupalUrl]: {
headers: {
"Authorization": "Basic " + Buffer.from(process.env.DRUPAL_BASIC_AUTH_ADMIN as string).toString("base64")
}
}
}
],
documents: 'src/lib/gql/*.drupal.gql',
generates: {
'src/lib/gql/__generated__/drupal.d.ts': {
Expand Down
Loading

0 comments on commit ce531d5

Please sign in to comment.