Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#1 implement header #6

Merged
merged 3 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"semi": "off",
"object-curly-newline": ["error", { "multiline": true }],
"jsx-a11y/anchor-is-valid": "off",
"no-use-before-define": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-filename-extension": [
"warn",
Expand Down
41 changes: 36 additions & 5 deletions components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/router';

export default function Header() {
export default function Header({ siteName, menus }: HeaderProps) {
return (
<Head>
<title> nextjs-paper </title>
</Head>
<header className="header">
<h1 className="logo">
<Link href="/">
<a className="site-name">{siteName}</a>
</Link>
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a className="btn-dark" />
</h1>
<MenuNav menus={menus} />
</header>
)
}

type HeaderProps = {
siteName: string,
menus: Menu[]
}

type Menu = {
name: string,
href: string
}

function MenuNav({ menus }: {menus: Menu[]}) {
const router = useRouter()
return (
<nav className="menu">
{menus.map((menu) => (
<Link href={menu.href}>
<a className={router.pathname === menu.href ? 'active' : ''}>{menu.name}</a>
</Link>
))}
</nav>
)
}
7 changes: 2 additions & 5 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const isProduction = process.env.NODE_ENV === 'production'
const name = 'nextjs-paper'

module.exports = {
assetPrefix: isProduction ? `/${name}/` : '',
basePath: isProduction ? `/${name}` : '',
env: {
basePath: isProduction ? `/${name}/` : '',
}
assetPrefix: isProduction ? `/${name}/` : '',
basePath: isProduction ? `/${name}` : '',
}
1 change: 1 addition & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppProps } from 'next/app'
import Head from 'next/head';
import '../public/app.css'

export default function MyApp({ Component, pageProps }: AppProps) {
return (
Expand Down
15 changes: 15 additions & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Document, { Head, Html, Main, NextScript } from 'next/document'

export default class MyDocument extends Document {
render() {
return (
<Html>
<Head />
<body className="not-ready" data-menu="true">
<Main />
<NextScript />
</body>
</Html>
)
}
}
23 changes: 20 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import Header from '../components/Header';

function Index() {
export default function Index({ siteName, menus }: IndexProps) {
return (
<Header />
<Header siteName={siteName} menus={menus} />
)
}

export default Index
type IndexProps = {
siteName: string,
menus: MenuProps[]
}

type MenuProps = {
name: string
href: string
}

export async function getStaticProps() {
return {
props: {
siteName: process.env.SITE_NAME,
menus: [{ name: 'About', href: '/about' }],
},
}
}
1 change: 1 addition & 0 deletions public/an-old-hope.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading