-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
151 additions
and
185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,29 @@ | ||
import Rows from "@components/paragraphs/rows/rows"; | ||
import Paragraph from "@components/paragraphs/paragraph"; | ||
import {notFound} from "next/navigation"; | ||
import {graphqlClient} from "@lib/gql/fetcher"; | ||
import {getEntityFromPath} from "@lib/gql/fetcher"; | ||
import {NodeStanfordPage} from "@lib/gql/__generated__/drupal"; | ||
import {isDraftMode} from "@lib/drupal/utils"; | ||
import {getAccessToken} from "@lib/drupal/get-access-token"; | ||
|
||
// Cache the home page for 24 hours. It should be the most modified and probably changes more frequent. | ||
// Cache the home page for 24 hours. It should be the most modified and probably changes most frequent. | ||
export const revalidate = 86400; | ||
|
||
const Home = async () => { | ||
const node = await getHomePageNode(); | ||
if (!node) notFound(); | ||
const routeInfo = await getEntityFromPath<NodeStanfordPage>('/', isDraftMode()); | ||
if (!routeInfo?.entity) notFound(); | ||
|
||
return ( | ||
<article> | ||
{node.suPageBanner && | ||
{routeInfo.entity.suPageBanner && | ||
<header aria-label="Home Page banner"> | ||
<Paragraph paragraph={node.suPageBanner}/> | ||
<Paragraph paragraph={routeInfo.entity.suPageBanner}/> | ||
</header> | ||
} | ||
{node.suPageComponents && | ||
<Rows components={node.suPageComponents}/> | ||
{routeInfo.entity.suPageComponents && | ||
<Rows components={routeInfo.entity.suPageComponents}/> | ||
} | ||
</article> | ||
) | ||
} | ||
|
||
const getHomePageNode = async (): Promise<NodeStanfordPage | undefined> => { | ||
let node: NodeStanfordPage | false; | ||
const token = await getAccessToken(isDraftMode()); | ||
try { | ||
const query = await graphqlClient(token?.access_token).Route({path: '/'}); | ||
node = query.route?.__typename === 'RouteInternal' && query.route.entity as NodeStanfordPage | ||
} catch (e) { | ||
console.error('Error fetching home node. ' + (e instanceof Error && e.message)); | ||
return; | ||
} | ||
return node || undefined; | ||
} | ||
|
||
export default Home; |
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
Oops, something went wrong.