slug page improvements
This commit is contained in:
1 parent
5ccec9e2ba
commit
82c9b88f77
3 files changed
+15
-12
No files matched your search
+6
-12
@@ -7,14 +7,14 @@ import { Markdown } from 'src/components/Markdown'
|
|||||||
import { Meta } from 'src/components/Meta'
|
import { Meta } from 'src/components/Meta'
|
||||||
import { MetaBuilder } from 'src/lib/meta'
|
import { MetaBuilder } from 'src/lib/meta'
|
||||||
import { apiGet } from '@/next-lib'
|
import { apiGet } from '@/next-lib'
|
||||||
import { NextPage } from 'next'
|
import { GetStaticProps, NextPage } from 'next'
|
||||||
import { IBreadcumbsPart, IMeta, ITag, FileTokenData, Token } from '@/types'
|
import { IBreadcumbsPart, IMeta, ITag, FileTokenData, Token } from '@/types'
|
||||||
import { joinTokens } from 'src/lib/tokens'
|
import { joinTokens } from 'src/lib/tokens'
|
||||||
import { size, ext } from 'src/lib/file'
|
import { size, ext } from 'src/lib/file'
|
||||||
import { Html } from 'src/components/Html'
|
import { Html } from 'src/components/Html'
|
||||||
import { Youtube } from '@/components/Youtube'
|
import { Youtube } from '@/components/Youtube'
|
||||||
import { createPage, createPageUrls } from '@/remote/factory'
|
import { createPage, createPageUrls } from '@/remote/factory'
|
||||||
import { asArray } from '@/remote/lib'
|
import { paramsToSlug } from '@/remote/lib'
|
||||||
|
|
||||||
const File: React.SFC<FileTokenData> = props => {
|
const File: React.SFC<FileTokenData> = props => {
|
||||||
const fileSize = size(props.file_size)
|
const fileSize = size(props.file_size)
|
||||||
@@ -137,16 +137,10 @@ const Index: NextPage<Props> = props => (
|
|||||||
</App>
|
</App>
|
||||||
)
|
)
|
||||||
|
|
||||||
export const getStaticProps = async (ctx: any) => {
|
export const getStaticProps: GetStaticProps<any> = async ctx => {
|
||||||
let slug = null
|
const slug = paramsToSlug(ctx.params.slug)
|
||||||
if (ctx.query) {
|
const url = `https://hudozka.tmshv.com/pages?slug=${slug}`
|
||||||
slug = '/' + asArray(ctx.query.slug).join('/')
|
const page = await apiGet(createPage)(url, null)
|
||||||
} else {
|
|
||||||
slug = '/' + asArray(ctx.params.slug).join('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
let apiUrl = `https://hudozka.tmshv.com/pages?slug=${slug}`
|
|
||||||
const page = await apiGet(createPage)(apiUrl, null)
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
return {
|
return {
|
||||||
notFound: true,
|
notFound: true,
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ export function createPageTokens(components: StrapiComponent[]): Token[] {
|
|||||||
|
|
||||||
export function createPage(res: StrapiPage | StrapiPage[]): IPage {
|
export function createPage(res: StrapiPage | StrapiPage[]): IPage {
|
||||||
const item = asItem(res)
|
const item = asItem(res)
|
||||||
|
if (!item) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: item.title,
|
title: item.title,
|
||||||
|
|||||||
@@ -9,3 +9,9 @@ export function asItem<T>(value: T | T[]) {
|
|||||||
? value[0]
|
? value[0]
|
||||||
: value
|
: value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function paramsToSlug(parts: string | string[]): string {
|
||||||
|
const slug = asArray(parts).join('/')
|
||||||
|
|
||||||
|
return `/${slug}`
|
||||||
|
}
|
||||||
Reference in new issue
Block a user