Skip to content

Commit

Permalink
feat(basic-starter): update dependencies and components
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn committed Nov 5, 2021
1 parent 8c3207b commit 233549b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 185 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"test": "jest",
"dev": "lerna run --parallel --ignore basic-starter dev",
"dev:starter": "lerna run --parallel --scope drupal-site --scope basic-starter dev",
"prepare": "lerna run prepare",
"watch": "lerna run watch",
"lint": "eslint --cache --ext .js,.jsx .",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Image from "next/image"
import Link from "next/link"

import { formatDate } from "../../lib/format-date"
import { formatDate } from "../lib/format-date"

export function NodeArticle({ node, ...props }) {
return (
Expand Down
26 changes: 16 additions & 10 deletions starters/basic-starter/pages/[...slug].tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import * as React from "react"
import Head from "next/head"
import {
DrupalNode,
getPathsFromContext,
getResourceFromContext,
getResourceTypeFromContext,
} from "next-drupal"
import { GetStaticPropsContext } from "next"
import { NodeArticle } from "@/nodes/node-article"
import { NodeBasicPage } from "@/components/nodes/node-basic-page"
import {
GetStaticPathsResult,
GetStaticPropsContext,
GetStaticPropsResult,
} from "next"
import { NodeArticle } from "@/components/node-article"
import { NodeBasicPage } from "@/components/node-basic-page"

/* eslint-disable @typescript-eslint/no-explicit-any */
interface NodePageProps {
preview: GetStaticPropsContext["preview"]
node: Record<string, any>
node: DrupalNode
}

export default function NodePage({ node, preview }: NodePageProps) {
Expand Down Expand Up @@ -49,14 +53,16 @@ export default function NodePage({ node, preview }: NodePageProps) {
)
}

export async function getStaticPaths(context) {
export async function getStaticPaths(context): Promise<GetStaticPathsResult> {
return {
paths: await getPathsFromContext(["node--article", "node--page"], context),
fallback: true,
fallback: "blocking",
}
}

export async function getStaticProps(context) {
export async function getStaticProps(
context
): Promise<GetStaticPropsResult<NodePageProps>> {
const type = await getResourceTypeFromContext(context)

if (!type) {
Expand All @@ -72,7 +78,7 @@ export async function getStaticProps(context) {
}
}

const node = await getResourceFromContext(type, context, {
const node = await getResourceFromContext<DrupalNode>(type, context, {
params,
})

Expand All @@ -87,6 +93,6 @@ export async function getStaticProps(context) {
preview: context.preview || false,
node,
},
revalidate: 60,
revalidate: 10,
}
}
27 changes: 17 additions & 10 deletions starters/basic-starter/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Head from "next/head"
import { getResourceCollectionFromContext } from "next-drupal"
import { NodeArticleTeaser } from "@/components/nodes/node-article"
import { DrupalNode, getResourceCollectionFromContext } from "next-drupal"
import { NodeArticleTeaser } from "@/components/node-article"
import { GetStaticPropsResult } from "next"

export default function IndexPage({ articles }) {
interface IndexPageProps {
nodes: DrupalNode[]
}

export default function IndexPage({ nodes }: IndexPageProps) {
return (
<>
<Head>
Expand All @@ -15,23 +20,25 @@ export default function IndexPage({ articles }) {
<div>
<h1 className="text-6xl font-black mb-10">Latest Articles.</h1>

{articles?.length ? (
articles.map((node) => (
{nodes?.length ? (
nodes.map((node) => (
<div key={node.id}>
<NodeArticleTeaser node={node} />
<hr className="my-20" />
</div>
))
) : (
<p className="py-4">No articles found</p>
<p className="py-4">No nodes found</p>
)}
</div>
</>
)
}

export async function getStaticProps(context) {
const articles = await getResourceCollectionFromContext(
export async function getStaticProps(
context
): Promise<GetStaticPropsResult<IndexPageProps>> {
const nodes = await getResourceCollectionFromContext<DrupalNode[]>(
"node--article",
context,
{
Expand All @@ -44,8 +51,8 @@ export async function getStaticProps(context) {

return {
props: {
articles,
nodes,
},
revalidate: 60,
revalidate: 10,
}
}
Loading

1 comment on commit 233549b

@vercel
Copy link

@vercel vercel bot commented on 233549b Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.