-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
437057f
commit 441cfbf
Showing
7 changed files
with
114 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ContentResponse, Content } from '../../models/content'; | ||
import { findByPath } from '../../api/content'; | ||
import { asInsight } from '../../utils/converters'; | ||
import Renderer from './renderer'; | ||
|
||
export default async function SlugizedPage(req: any) { | ||
const { props } = await get(req); | ||
return <Renderer {...props} />; | ||
} | ||
|
||
export async function get(req: any) { | ||
let path = req.params.slug.join("/"); | ||
// TODO move utils & write testcode | ||
if (!path.startsWith("/")) { | ||
path = "/" + path; | ||
} | ||
// TODO move utils & write testcode | ||
if (path.match(/^\/\d{4}\/\d{2}\/\d{2}\/*/)) { | ||
if (!path.endsWith("/")) { | ||
path = `${path}/` | ||
} | ||
return { | ||
redirect: { | ||
permanent: true, | ||
destination: `/articles${path}` | ||
} | ||
} | ||
} | ||
|
||
const response: Response = await findByPath(path); | ||
// ctx.res.statusCode = response.status; | ||
|
||
let content: Content = null; | ||
if (response.status === 200) { | ||
const contentResponse: ContentResponse = await response.json() as ContentResponse; | ||
content = { | ||
title: contentResponse.title, | ||
robotsAttributes: contentResponse.robotsAttributes, | ||
externalResources: contentResponse.externalResources, | ||
content: contentResponse.content, | ||
length: contentResponse.length, | ||
publishedAt: contentResponse.publishedAt | ||
} as Content | ||
} | ||
return { | ||
props: { | ||
statusCode: response.status, | ||
content: content, | ||
insight: asInsight(response) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
import ContentComponent from '../../components/content'; | ||
import CoverWithNavigationComponent from '../../components/cover/withNavigation'; | ||
import HeadMetaComponent from '../../components/headmeta'; | ||
import MainBottomCodesComponent from '../../components/mainBottomCodes'; | ||
import { Content } from '../../models/content'; | ||
import { ScriptCode } from '../../models/script'; | ||
import { getScriptCodes } from '../../utils/scriptTags'; | ||
import { externalResources as externalResourcesConfig } from '../../../config'; | ||
import { Insight } from '../../models/insight'; | ||
import PlanePage from '../../components/planePage'; | ||
|
||
const Renderer: React.FunctionComponent<{ statusCode: number, content: Content, insight: Insight }> = ({ statusCode, content, insight }) => { | ||
if (statusCode !== 200) { | ||
return <PlanePage | ||
title={statusCode.toString()} | ||
content="Something went to wrong..." | ||
/> | ||
} | ||
|
||
let externalResourceCodes: Array<ScriptCode> = []; | ||
const hasExternalResources = (content.externalResources && externalResourcesConfig); | ||
if (hasExternalResources) { | ||
externalResourceCodes = getScriptCodes(content.externalResources, externalResourcesConfig) | ||
} | ||
return ( | ||
<> | ||
<HeadMetaComponent | ||
robotsMeta={content.robotsAttributes} | ||
externalResources={content.externalResources} | ||
content={content} | ||
/> | ||
<CoverWithNavigationComponent | ||
contentCover={{ | ||
title: content.title, | ||
tags: null, | ||
publishedAt: content.publishedAt, | ||
}} | ||
/> | ||
<main> | ||
<ContentComponent | ||
content={content} | ||
insight={insight} | ||
/> | ||
<MainBottomCodesComponent | ||
scriptCodes={externalResourceCodes} | ||
/> | ||
</main> | ||
</> | ||
) | ||
} | ||
|
||
export default Renderer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters