Skip to content

Commit

Permalink
feat(basic-starter): update the basic starter
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn committed Aug 12, 2021
1 parent 37deb8c commit a7efdcd
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 25 deletions.
3 changes: 2 additions & 1 deletion starters/basic-starter/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { useRouter } from "next/dist/client/router"
export function Layout({ children }) {
const { asPath } = useRouter()
const { tree } = useMenu("main")

return (
<div className="max-w-screen-md mx-auto">
<div className="max-w-screen-md mx-auto px-6">
<header>
<div className="container mx-auto flex items-center justify-between py-6">
<Link href="/" passHref>
Expand Down
4 changes: 4 additions & 0 deletions starters/basic-starter/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
4 changes: 2 additions & 2 deletions starters/basic-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@tailwindcss/typography": "^0.4.1",
"next": "^11.0.0",
"next": "^11.1.0",
"next-drupal": "^0.15.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand All @@ -23,6 +23,6 @@
"eslint-config-next": "^11.0.0",
"postcss": "^8.3.5",
"tailwindcss": "^2.1.4",
"typescript": "^4.2.4"
"typescript": "^4.3.5"
}
}
31 changes: 28 additions & 3 deletions starters/basic-starter/pages/[...slug].tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
import * as React from "react"
import Head from "next/head"
import {
getPathsFromContext,
getResourceFromContext,
getResourceTypeFromContext,
} from "next-drupal"
import { GetStaticPropsContext } from "next"
import { NodeArticle } from "@/nodes/node-article"
import { NodeBasicPage } from "@/components/nodes/node-basic-page"

export default function NodePage({ node }) {
/* eslint-disable @typescript-eslint/no-explicit-any */
interface NodePageProps {
preview: GetStaticPropsContext["preview"]
node: Record<string, any>
}

export default function NodePage({ node, preview }: NodePageProps) {
const [showPreviewAlert, setShowPreviewAlert] = React.useState<boolean>(false)

if (!node) return null

React.useEffect(() => {
setShowPreviewAlert(preview && window.top === window.self)
}, [])

return (
<>
<Head>
<title>{node.title}</title>
<meta
name="description"
content="A Next.js site powered by a Drupal backend. Built with paragraphs, views, menus and translations."
content="A Next.js site powered by a Drupal backend."
/>
</Head>
{showPreviewAlert && (
<div className="fixed top-4 right-4">
<a
href="/api/exit-preview"
className="bg-black text-white rounded-md px-4 py-2 text-sm"
>
Exit preview
</a>
</div>
)}
{node.type === "node--page" && <NodeBasicPage node={node} />}
{node.type === "node--article" && <NodeArticle node={node} />}
</>
Expand Down Expand Up @@ -60,8 +84,9 @@ export async function getStaticProps(context) {

return {
props: {
preview: context.preview || false,
node,
revalidate: 60,
},
revalidate: 60,
}
}
6 changes: 6 additions & 0 deletions starters/basic-starter/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { AppProps } from "next/app"
import "tailwindcss/tailwind.css"
import Router from "next/router"
import { syncDrupalPreviewRoutes } from "next-drupal"
import { Layout } from "@/components/layout"

Router.events.on("routeChangeStart", function (path) {
syncDrupalPreviewRoutes(path)
})

export default function App({ Component, pageProps }: AppProps) {
return (
<Layout>
Expand Down
38 changes: 24 additions & 14 deletions starters/basic-starter/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import Head from "next/head"
import { getResourceCollectionFromContext } from "next-drupal"
import { NodeArticleTeaser } from "@/components/nodes/node-article"

export default function IndexPage({ articles }) {
return (
<div>
<h1 className="text-6xl font-black mb-10">Latest Articles.</h1>
<>
<Head>
<title>Next.js for Drupal</title>
<meta
name="description"
content="A Next.js site powered by a Drupal backend."
/>
</Head>
<div>
<h1 className="text-6xl font-black mb-10">Latest Articles.</h1>

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

Expand All @@ -35,7 +45,7 @@ export async function getStaticProps(context) {
return {
props: {
articles,
revalidate: 60,
},
revalidate: 60,
}
}
Binary file added starters/basic-starter/public/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions starters/basic-starter/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Allow: /
Loading

1 comment on commit a7efdcd

@vercel
Copy link

@vercel vercel bot commented on a7efdcd Aug 12, 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.