Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WakuwakuP committed Apr 1, 2024
1 parent b860205 commit dc1a0d1
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 70 deletions.
14 changes: 5 additions & 9 deletions src/app/content/detail/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { notFound } from 'next/navigation'

import * as cheerio from 'cheerio'
import hljs from 'highlight.js'
import { createTableOfContents, processer } from 'microcms-richedit-processer'
Expand All @@ -21,11 +23,8 @@ export async function generateMetadata({ params: { id } }: { params: { id: strin
})
.catch(() => undefined)

if (!content) {
return {
notFound: true,
revalidate: 60,
}
if (content === undefined) {
return {}
}

return {
Expand Down Expand Up @@ -54,10 +53,7 @@ export default async function ContentDetailPage({ params: { id } }: { params: {
.catch(() => undefined)

if (!content) {
return {
notFound: true,
revalidate: 60,
}
notFound()
}

const body = content.content.reduce((acc: string, cur: { fieldId: string; html: string }) => acc + cur.html, '')
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/latest/[page]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export default async function ContentLatestPage({ params: { page } }: { params:
const totalCount = data.totalCount
const totalPage = Math.ceil(totalCount / PAGE_LIMIT)

return <ContentLatest contents={contents} totalPage={totalPage} />
return <ContentLatest contents={contents} page={Number(page)} totalPage={totalPage} />
}
17 changes: 7 additions & 10 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { Metadata } from 'next'
import { M_PLUS_1p } from 'next/font/google'
import type { ReactNode } from 'react'

import { Footer, Header, SiteTop } from 'components/containers'
import { Footer, Header } from 'components/containers'
import { GoogleAnalytics } from 'libs/gtag'
import SurfaceDuoProvider from 'providers/SurfaceDuoProvider'

const BASE_URL = process.env.BASE_URL
const SITE_TITLE = process.env.SITE_TITLE
Expand All @@ -20,7 +21,7 @@ const globalFont = M_PLUS_1p({
})

export const metadata: Metadata = {
title: { default: 'Home', template: `%s | ${SITE_NAME}` },
title: { default: `Home | ${SITE_NAME}`, template: `%s | ${SITE_NAME}` },
description: SITE_DESCRIPTION,
openGraph: {
type: 'website',
Expand All @@ -35,6 +36,7 @@ export const metadata: Metadata = {
site: TWITTER_SITE,
card: 'summary_large_image',
},
viewport: 'width=device-width, initial-scale=1.0',
}

export default function RootLayout({ children }: { children: ReactNode }) {
Expand All @@ -52,14 +54,9 @@ export default function RootLayout({ children }: { children: ReactNode }) {
<GoogleAnalytics />
</head>
<body className={globalFont.className}>
<div className='surface-duo-left'>
<Header />
<main className='container'>{children}</main>
<Footer />
</div>
<div className='surface-duo-right'>
<SiteTop />
</div>
<SurfaceDuoProvider header={<Header />} footer={<Footer />}>
{children}
</SurfaceDuoProvider>
</body>
</html>
)
Expand Down
4 changes: 4 additions & 0 deletions src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import styles from 'styles/pages/404.module.css'

export const metadata = {
title: '404 Not Found',
}

export default function NotFound() {
return (
<div className={styles.box}>
Expand Down
102 changes: 54 additions & 48 deletions src/components/containers/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,64 @@ export const Pagination = ({ totalPage, page }: PaginationProps) => {
return (
<div>
<ul className={styles.pagination}>
{2 <= currentPage && (
<li>
<Link href={`${path}/1`} passHref>
<div className={styles.btn}>
<span>1</span>
<>
{2 <= currentPage && (
<li>
<Link href={`${path}/1`}>
<div className={styles.btn}>
<span>1</span>
</div>
</Link>
</li>
)}
{3 <= currentPage && (
<li>
<div className={styles.dots}>
<span></span>
</div>
</Link>
</li>
)}
{3 <= currentPage && (
<li>
<div className={styles.dots}>
<span></span>
</div>
</li>
)}
{range(1, Math.ceil(totalPage)).map((number, index) => {
if (currentPage - 1 <= index && index <= currentPage + 1) {
return (
<li key={index}>
{index === currentPage ? (
<div className={styles.current}>
<span>{number}</span>
</div>
) : (
<Link href={`${path}/${number}`} passHref>
<div className={styles.btn}>
</li>
)}
</>
<>
{range(1, Math.ceil(totalPage)).map((number, index) => {
if (currentPage - 1 <= index && index <= currentPage + 1) {
return (
<li key={index}>
{index === currentPage ? (
<div className={styles.current}>
<span>{number}</span>
</div>
</Link>
)}
</li>
)
}
return <></>
})}
{totalPage - 4 >= currentPage && (
<li>
<div className={styles.dots}>
<span></span>
</div>
</li>
)}
{totalPage - 3 >= currentPage && (
<li>
<Link href={`${path}//${totalPage}`} passHref>
<div className={styles.btn}>
<span>{totalPage}</span>
) : (
<Link href={`${path}/${number}`}>
<div className={styles.btn}>
<span>{number}</span>
</div>
</Link>
)}
</li>
)
}
return <></>
})}
</>
<>
{totalPage - 4 >= currentPage && (
<li>
<div className={styles.dots}>
<span></span>
</div>
</Link>
</li>
)}
</li>
)}
{totalPage - 3 >= currentPage && (
<li>
<Link href={`${path}//${totalPage}`}>
<div className={styles.btn}>
<span>{totalPage}</span>
</div>
</Link>
</li>
)}
</>
</ul>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/templates/ContentDetail/ContentDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ContentDetail = ({ content, toc }: ContentDetailProps) => {
<div className={styles.tocWrapper} ref={elemTocWrapper}>
<div className={styles.tocArea} ref={elemTocArea}>
{toc && toc.length > 0 && <Toc toc={toc} />}
{process.env.NODE_ENV !== 'development' && <AdSense adSlot='3817713745' />}
{process.env.NODE_ENV == 'development' && <AdSense adSlot='3817713745' />}
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useMutationObserver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import type { RefObject } from 'react'
import { useEffect } from 'react'

Expand Down
49 changes: 49 additions & 0 deletions src/providers/SurfaceDuoProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use client'

import { useRef, type ReactNode } from 'react'

import { SiteTop } from 'components/containers'
import { useMutationObserver } from 'hooks/useMutationObserver'

import type { MutationCallback } from 'hooks/useMutationObserver'

export default function SurfaceDuoProvider({
children,
header,
footer,
}: {
children: ReactNode
header: ReactNode
footer: ReactNode
}) {
const elemSurfaceDuoLeft = useRef<HTMLDivElement>(null)
const elemContainer = useRef<HTMLDivElement>(null)

const handleUnsetStyling: MutationCallback = (mutations) => {
mutations.forEach((mutation) => {
if (mutation.target instanceof HTMLElement) {
mutation.target.setAttribute('style', '')
}
})
}

useMutationObserver([elemSurfaceDuoLeft, elemContainer], handleUnsetStyling, {
attributes: true,
attributeFilter: ['style'],
})

return (
<>
<div className='surface-duo-left' ref={elemSurfaceDuoLeft}>
<div>
{header}
<main className='container'>{children}</main>
{footer}
</div>
</div>
<div className='surface-duo-right'>
<SiteTop />
</div>
</>
)
}
7 changes: 6 additions & 1 deletion src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ a.btn:hover {
}
}
@media (horizontal-viewport-segments: 2) {
body > div {
body {
height: 100vh;
display: flex;
}
Expand All @@ -112,6 +112,11 @@ a.btn:hover {
margin-inline-end: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
overflow-y: scroll;
}

.surface-duo-left main {
margin-top: 4rem;
}

.surface-duo-right {
position: relative;
display: block;
Expand Down

0 comments on commit dc1a0d1

Please sign in to comment.