Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 5, 2024
1 parent 5e244f0 commit 09b5456
Show file tree
Hide file tree
Showing 25 changed files with 199 additions and 145 deletions.
3 changes: 1 addition & 2 deletions src/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/[...slug]/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<InjectScript> = [];
const hasExternalResources = (content.externalResources && externalResourcesConfig);
if (hasExternalResources) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/archives/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function get(req: any) {

return {
props: {
slug: 'archives',
// slug: 'archives',
archives: archives
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/app/archives/renderer.tsx
Original file line number Diff line number Diff line change
@@ -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<Archive>
}> = ({ slug, archives }) => {
}> = ({ archives }) => {
return (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={{
title: "Archives",
Expand Down
34 changes: 32 additions & 2 deletions src/app/articles/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
'use server';

import { Metadata } from 'next'
import { ContentResponse, Content } from '../../../models/models';
import { isIgnoreRequest } from '../../../utils/filterRequests';
import { findByPath } from '../../../api/content';
import { asInsight } from '../../../utils/converters';
import { sluggize } from "../../../utils/slug";
import { Renderer } from './renderer';
import { runOrHandleErrorIf, throwIfError } from "../../handler";
import { defaultRobotsMeta } from '../../../../config';

export async function generateMetadata (content?: Content): Promise<Metadata> {
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));
}

async function run(req: any): Promise<any> {
const { props } = await get(req);
await generateMetadata(
// sluggize(req.params.slug, 'articles'),
props.content
)
return <Renderer {...props} />;
}

Expand Down Expand Up @@ -46,7 +77,6 @@ async function get(req: any) {

return {
props: {
slug: sluggize(req.params.slug, 'articles'),
content: content,
insight: asInsight(response)
}
Expand Down
9 changes: 1 addition & 8 deletions src/app/articles/[...slug]/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ContentComponent from '../../../components/content';
import CoverWithNavigationComponent from '../../../components/cover/withNavigation';
import HeadMetaComponent from '../../../components/headmeta';
import {
Content,
Insight,
Expand All @@ -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<InjectScript> = [];
const hasExternalResources = (content.externalResources && externalResourcesConfig);
Expand All @@ -23,11 +21,6 @@ export const Renderer: React.FunctionComponent<{
}
return (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={content.robotsAttributes}
content={content}
/>
<CoverWithNavigationComponent
contentCover={{
title: content.title,
Expand Down
3 changes: 1 addition & 2 deletions src/app/articles/[number]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { getArticles } 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";

Expand Down Expand Up @@ -37,7 +36,7 @@ async function get(req: any) {

return {
props: {
slug: sluggize(req.params.slug),
// slug: sluggize(req.params.slug),
current: req.params.number,
count: articlesResponseWithCount.count,
articles: articles
Expand Down
7 changes: 1 addition & 6 deletions src/app/articles/[number]/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import HeadMetaComponent from '../../../components/headmeta';
import CoverWithNavigationComponent from '../../../components/cover/withNavigation';
import ArticlesComponent from '../../../components/articles';
import PaginationComponent from '../../../components/pagination';
import { Article } from '../../../models/models';

export const Renderer: React.FunctionComponent<{
slug: string,
current: number,
count: number,
articles: Array<Article>
}> = ({ slug, current, count, articles }) => {
}> = ({ current, count, articles }) => {
return (
<>
<HeadMetaComponent
slug={slug}
/>
<CoverWithNavigationComponent
contentCover={null}
/>
Expand Down
9 changes: 1 addition & 8 deletions src/app/articles/renderer.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={null}
/>
Expand Down
30 changes: 29 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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:<field>` will be generate automatically.
- I don't want insert `twitter:<field>` to head.
openGraph: {
title: siteName,
},
twitter: {} // Twitter og will be generate automatically, evenif I set empty object.
*/
}

export default function RootLayout({
children
Expand All @@ -12,6 +39,7 @@ export default function RootLayout({
// https://github.com/vercel/next.js/discussions/44506#discussioncomment-7901181
return (
<html lang={lang}>
<HeadMetaComponent />
<body data-theme={`${theme}`}>
<ClientLayout>
{ children }
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function get(req: any) {

return {
props: {
slug: undefined,
// slug: undefined,
articles: articles
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/app/renderer.tsx
Original file line number Diff line number Diff line change
@@ -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<Article>
}> = ({ slug, articles }) => {
}> = ({ articles }) => {

return (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={null}
/>
Expand Down
6 changes: 0 additions & 6 deletions src/app/search/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,10 +40,6 @@ export const Renderer: React.FunctionComponent<{

return (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={{
title: "Search (β)",
Expand Down
3 changes: 1 addition & 2 deletions src/app/series/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
SeriresWithArticles
} from '../../../models/models';
import { getRequestContext } from '../../../utils/requestContext';
import { sluggize } from "../../../utils/slug";
import { Renderer } from './renderer';
import { runOrHandleErrorIf, throwIfError } from "../../handler";

Expand Down Expand Up @@ -43,7 +42,7 @@ async function get(req: any) {

return {
props: {
slug: sluggize(req.params.slug),
// slug: sluggize(req.params.slug),
seriresWithArticles: seriresWithArticles
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/app/series/[slug]/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import HeadMetaComponent from '../../../components/headmeta';
import CoverWithNavigationComponent from '../../../components/cover/withNavigation';
import SeriesWithArticlesComponent from '../../../components/seriesWithArticles';
import { defaultRobotsMeta } from '../../../../config';

export const Renderer: React.FunctionComponent<{
slug: string,
seriresWithArticles
}> = ({ slug, seriresWithArticles }) => {
}> = ({ seriresWithArticles }) => {
return (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={{
title: seriresWithArticles.title,
Expand Down
3 changes: 1 addition & 2 deletions src/app/series/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { getSeries } from '../../api/series';
import { Series, SeriesResponse } from '../../models/models';
import { getRequestContext } from '../../utils/requestContext';
import { sluggize } from "../../utils/slug";
import { Renderer } from './renderer';
import { runOrHandleErrorIf, throwIfError } from "../handler";

Expand Down Expand Up @@ -33,7 +32,7 @@ async function get(req: any) {

return {
props: {
slug: sluggize(req.params.slug),
// slug: sluggize(req.params.slug),
series: series
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/app/series/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import HeadMetaComponent from '../../components/headmeta';
import CoverWithNavigationComponent from '../../components/cover/withNavigation';
import SeriesComponent from '../../components/series';
import { Series } from '../../models/models';
import { defaultRobotsMeta } from '../../../config';

export const Renderer: React.FunctionComponent<{
slug: string,
series: Array<Series>
}> = ({ slug, series }) => {
}> = ({ series }) => {
return (
<>
<HeadMetaComponent
slug={slug}
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={{
title: "Series",
Expand Down
Loading

0 comments on commit 09b5456

Please sign in to comment.