From 09b54563e8a78b4a37272b6c673e7663eb0c85bd Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Fri, 5 Jan 2024 23:13:05 +0900 Subject: [PATCH] update --- src/app/[...slug]/page.tsx | 3 +- src/app/[...slug]/renderer.tsx | 3 +- src/app/archives/page.tsx | 2 +- src/app/archives/renderer.tsx | 9 +- src/app/articles/[...slug]/page.tsx | 34 ++++++- src/app/articles/[...slug]/renderer.tsx | 9 +- src/app/articles/[number]/page.tsx | 3 +- src/app/articles/[number]/renderer.tsx | 7 +- src/app/articles/renderer.tsx | 9 +- src/app/layout.tsx | 30 ++++++- src/app/page.tsx | 2 +- src/app/renderer.tsx | 9 +- src/app/search/renderer.tsx | 6 -- src/app/series/[slug]/page.tsx | 3 +- src/app/series/[slug]/renderer.tsx | 9 +- src/app/series/page.tsx | 3 +- src/app/series/renderer.tsx | 9 +- src/app/settings/page.tsx | 6 -- src/app/status/page.tsx | 3 +- src/app/status/renderer.tsx | 47 +++++----- src/app/tags/[...slug]/page.tsx | 3 +- src/app/tags/[...slug]/renderer.tsx | 9 +- src/app/tags/page.tsx | 3 +- src/app/tags/renderer.tsx | 9 +- src/components/headmeta.tsx | 114 ++++++++++++++++++++---- 25 files changed, 199 insertions(+), 145 deletions(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index 6d08b9d..e0ce9a1 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -5,7 +5,6 @@ import { permanentRedirect } from "next/navigation"; import { ContentResponse, Content } from '../../models/models'; import { findByPath } from '../../api/content'; import { asInsight } from '../../utils/converters'; -import { sluggize } from "../../utils/slug"; import { Renderer } from './renderer'; import { runOrHandleErrorIf, throwIfError } from "../handler"; @@ -48,7 +47,7 @@ async function get(req: any) { return { props: { - slug: sluggize(req.params.slug), + // slug: sluggize(req.params.slug), content: content, insight: asInsight(response) } diff --git a/src/app/[...slug]/renderer.tsx b/src/app/[...slug]/renderer.tsx index ab76211..a944c6e 100644 --- a/src/app/[...slug]/renderer.tsx +++ b/src/app/[...slug]/renderer.tsx @@ -11,10 +11,9 @@ import { externalResources as externalResourcesConfig } from '../../../config'; import { InjectScriptComponent } from '../../components/injectScriptComponent'; export const Renderer: React.FunctionComponent<{ - slug: string, content: Content, insight: Insight -}> = ({ slug, content, insight }) => { +}> = ({ content, insight }) => { let externalResourceSrc: Array = []; const hasExternalResources = (content.externalResources && externalResourcesConfig); if (hasExternalResources) { diff --git a/src/app/archives/page.tsx b/src/app/archives/page.tsx index 02afbe4..a2c05ac 100644 --- a/src/app/archives/page.tsx +++ b/src/app/archives/page.tsx @@ -30,7 +30,7 @@ async function get(req: any) { return { props: { - slug: 'archives', + // slug: 'archives', archives: archives } } diff --git a/src/app/archives/renderer.tsx b/src/app/archives/renderer.tsx index a36c579..1038370 100644 --- a/src/app/archives/renderer.tsx +++ b/src/app/archives/renderer.tsx @@ -1,19 +1,12 @@ -import HeadMetaComponent from '../../components/headmeta'; import CoverWithNavigationComponent from '../../components/cover/withNavigation'; import ArchivesComponent from '../../components/archives'; import { Archive } from '../../models/models'; -import { defaultRobotsMeta } from '../../../config'; export const Renderer: React.FunctionComponent<{ - slug: string, archives: Array -}> = ({ slug, archives }) => { +}> = ({ archives }) => { return ( <> - { + const c = content; + const robotsAttributes = content.robotsAttributes === undefined ? defaultRobotsMeta : content.robotsAttributes; + return { + /* + NOT WORK??? + title: c.title, + authors: [{ name: c.authorName }], + description: c.description, + */ + robots: { + noarchive: robotsAttributes.includes('noarchive'), + follow: !robotsAttributes.includes('nofollow'), + noimageindex: robotsAttributes.includes('noimageindex'), + index: !robotsAttributes.includes('noindex'), + } + /* + openGraph: { + type: 'article', + publishedTime: convertUnixTimeToISODateSrting(content.publishedAt), + modifiedTime: convertUnixTimeToISODateSrting(content.updatedAt) + }, + */ + }; +} export default async function Page(req: any) { return runOrHandleErrorIf(await run(req)); @@ -14,6 +41,10 @@ export default async function Page(req: any) { async function run(req: any): Promise { const { props } = await get(req); + await generateMetadata( + // sluggize(req.params.slug, 'articles'), + props.content + ) return ; } @@ -46,7 +77,6 @@ async function get(req: any) { return { props: { - slug: sluggize(req.params.slug, 'articles'), content: content, insight: asInsight(response) } diff --git a/src/app/articles/[...slug]/renderer.tsx b/src/app/articles/[...slug]/renderer.tsx index 295c7f1..fae72ae 100644 --- a/src/app/articles/[...slug]/renderer.tsx +++ b/src/app/articles/[...slug]/renderer.tsx @@ -1,6 +1,5 @@ import ContentComponent from '../../../components/content'; import CoverWithNavigationComponent from '../../../components/cover/withNavigation'; -import HeadMetaComponent from '../../../components/headmeta'; import { Content, Insight, @@ -11,10 +10,9 @@ import { externalResources as externalResourcesConfig } from '../../../../config import { InjectScriptComponent } from '../../../components/injectScriptComponent'; export const Renderer: React.FunctionComponent<{ - slug: string, content: Content, insight: Insight -}> = ({ slug, content, insight }) => { +}> = ({ content, insight }) => { let externalResourceSrc: Array = []; const hasExternalResources = (content.externalResources && externalResourcesConfig); @@ -23,11 +21,6 @@ export const Renderer: React.FunctionComponent<{ } return ( <> - -}> = ({ slug, current, count, articles }) => { +}> = ({ current, count, articles }) => { return ( <> - diff --git a/src/app/articles/renderer.tsx b/src/app/articles/renderer.tsx index bc33064..97bbb43 100644 --- a/src/app/articles/renderer.tsx +++ b/src/app/articles/renderer.tsx @@ -1,20 +1,13 @@ -import HeadMetaComponent from '../../components/headmeta'; import CoverWithNavigationComponent from '../../components/cover/withNavigation'; import ArticlesComponent from '../../components/articles'; import PaginationComponent from '../../components/pagination'; -import { defaultRobotsMeta } from '../../../config'; export const Renderer: React.FunctionComponent<{ - slug: string, count, articles -}> = ({ slug, count, articles }) => { +}> = ({ count, articles }) => { return ( <> - diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 3ebc8c9..bf7b7a5 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,7 +1,34 @@ import React from 'react'; +import { Metadata } from 'next' import ClientLayout from './clientLayout'; import { getThemeSetting } from '../services/theme'; -import { lang } from '../../config'; +import { + siteName, + mainAuthor, + lang, +} from '../../config'; +import HeadMetaComponent from '../components/headmeta'; + +export const metadata: Metadata = { + title: siteName, + authors: [{ name: mainAuthor }], + robots: { + noarchive: true, + follow: false, + noimageindex: true, + index: false + } + /* NOTE: Not supports OpenGraph + Reasons: + - If enable openGraph, `twitter:` will be generate automatically. + - I don't want insert `twitter:` to head. + + openGraph: { + title: siteName, + }, + twitter: {} // Twitter og will be generate automatically, evenif I set empty object. + */ +} export default function RootLayout({ children @@ -12,6 +39,7 @@ export default function RootLayout({ // https://github.com/vercel/next.js/discussions/44506#discussioncomment-7901181 return ( + { children } diff --git a/src/app/page.tsx b/src/app/page.tsx index 4f97842..39797ea 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -32,7 +32,7 @@ async function get(req: any) { return { props: { - slug: undefined, + // slug: undefined, articles: articles } } diff --git a/src/app/renderer.tsx b/src/app/renderer.tsx index 42d31f7..118fea5 100644 --- a/src/app/renderer.tsx +++ b/src/app/renderer.tsx @@ -1,22 +1,15 @@ import { Article } from '../models/models'; -import HeadMetaComponent from '../components/headmeta'; import CoverWithNavigationComponent from '../components/cover/withNavigation'; import RecentArticlesComponent from '../components/recentArticles'; import styles from '../styles/home.module.scss'; import containerStyles from '../styles/components/container.module.scss'; -import { defaultRobotsMeta } from '../../config'; export const Renderer: React.FunctionComponent<{ - slug: string, articles: Array
-}> = ({ slug, articles }) => { +}> = ({ articles }) => { return ( <> - diff --git a/src/app/search/renderer.tsx b/src/app/search/renderer.tsx index ca407c2..22f7e06 100644 --- a/src/app/search/renderer.tsx +++ b/src/app/search/renderer.tsx @@ -3,9 +3,7 @@ import React, { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; -import HeadMetaComponent from '../../components/headmeta'; import CoverWithNavigationComponent from '../../components/cover/withNavigation'; -import { defaultRobotsMeta } from '../../../config'; import { SearchResponse, SearchResponseWithCount } from '../../models/models'; import inputStyles from '../../styles/input.module.scss'; import containerStyles from '../../styles/components/container.module.scss'; @@ -42,10 +40,6 @@ export const Renderer: React.FunctionComponent<{ return ( <> - = ({ slug, seriresWithArticles }) => { +}> = ({ seriresWithArticles }) => { return ( <> - -}> = ({ slug, series }) => { +}> = ({ series }) => { return ( <> - - = ({ slug, statusCode }) => { +}> = ({ statusCode }) => { // TODO: improvement (add bc-color, style, statusCode, etc) return( <> - - { - (() => { - if (statusCode === 200) { - return( - - ) - } else { - return( - - ) - } - })() - } + { + (() => { + if (statusCode === 200) { + return( + + ) + } else { + return( + + ) + } + })() + } ); } diff --git a/src/app/tags/[...slug]/page.tsx b/src/app/tags/[...slug]/page.tsx index dd5c6d6..b08ea09 100644 --- a/src/app/tags/[...slug]/page.tsx +++ b/src/app/tags/[...slug]/page.tsx @@ -3,7 +3,6 @@ import { getArticlesByTagName } from '../../../api/articles'; import { Article, ArticleResponseWithCount } from '../../../models/models'; import { getRequestContext } from '../../../utils/requestContext'; -import { sluggize } from "../../../utils/slug"; import { Renderer } from './renderer'; import { runOrHandleErrorIf, throwIfError } from "../../handler"; @@ -39,7 +38,7 @@ async function get(req: any) { return { props: { - slug: sluggize(req.params.slug), + // slug: sluggize(req.params.slug), tagName: tagName, currentPage: currentPage, count: articlesResponseWithCount.count, diff --git a/src/app/tags/[...slug]/renderer.tsx b/src/app/tags/[...slug]/renderer.tsx index 804c5ed..38ce9ae 100644 --- a/src/app/tags/[...slug]/renderer.tsx +++ b/src/app/tags/[...slug]/renderer.tsx @@ -1,22 +1,15 @@ -import HeadMetaComponent from '../../../components/headmeta'; import CoverWithNavigationComponent from '../../../components/cover/withNavigation'; import ArticlesComponent from '../../../components/articles'; import PaginationComponent from '../../../components/pagination'; -import { defaultRobotsMeta } from '../../../../config'; export const Renderer: React.FunctionComponent<{ - slug: string, tagName, currentPage, count, articles -}> = ({ slug, tagName, currentPage, count, articles }) => { +}> = ({ tagName, currentPage, count, articles }) => { return ( <> - } } diff --git a/src/app/tags/renderer.tsx b/src/app/tags/renderer.tsx index ae1ae3f..939b055 100644 --- a/src/app/tags/renderer.tsx +++ b/src/app/tags/renderer.tsx @@ -1,21 +1,14 @@ 'use client'; import { Tag } from '../../models/models'; -import HeadMetaComponent from '../../components/headmeta'; import CoverWithNavigationComponent from '../../components/cover/withNavigation'; import TagsComponent from '../../components/tags'; -import { defaultRobotsMeta } from '../../../config'; export const Renderer: React.FunctionComponent<{ - slug: string, tags: Array -}> = ({ slug, tags }) => { +}> = ({ tags }) => { return ( <> - import('./headerScriptSrcs'), { ssr: false }) -import { convertUnixTimeToISODateSrting } from '../utils/time'; +const HeadMetaComponent: React.FunctionComponent<{}> = ({}) => { + // TODO: JSON + LD + return( + + {/* + { + (() => { + if (hasContent) { + return( + <> + - Dynamic fields should be inserted by Next.js (excludes og:) + {content.title} + + + + + - Dynamic og should not be inserted to head. + + + + + + + ); + } else { + return( + <> + - Dynamic fields should be inserted by Next.js (excludes og:) + {siteName} + + - Generate by Next.js Metadata + + + + - Dynamic og should not be inserted to head. + + + ); + } + })() + } + */} + {/* + - Dynamic og should not be inserted to head. + + + + + + + + */} + {/* + { + (() => { + if (hasContent && content.tags) { + return( + content.tags.map((t => { + return( + + ) + })) + ) + } + })() + } + */} + {/* + - Generate by Next.js Metadata + + + - Dynamic fields should be inserted by Next.js (excludes og:) + + + */} + { + (() => { + if (injectMetas) { + return( + injectMetas.map((m => { + return( + + ) + })) + ) + } + })() + } + + + ) +} + +export default HeadMetaComponent; + +/* NOTE: Before migrate to AppRouter's head metas const HeadMetaComponent: React.FunctionComponent<{ robotsMeta?: string content?: Content, @@ -34,9 +118,8 @@ const HeadMetaComponent: React.FunctionComponent<{ robotsMeta = defaultRobotsMeta; } const hasContent = content ? true : false; - /* - TODO: JSON+LD - */ + + // TODO: JSON + LD return( @@ -106,3 +189,4 @@ const HeadMetaComponent: React.FunctionComponent<{ } export default HeadMetaComponent; +*/