menu from api
This commit is contained in:
1 parent
7e856bce18
commit
bc2f1f78fd
5 files changed
+45
-12
No files matched your search
+7
-2
@@ -8,10 +8,10 @@ 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 { GetStaticProps, NextPage } from 'next'
|
import { GetStaticProps, NextPage } from 'next'
|
||||||
import { IBreadcumbsPart, IMeta, ITag, Sign, Token } from '@/types'
|
import { IBreadcumbsPart, IMenu, IMeta, ITag, Sign, Token } from '@/types'
|
||||||
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 { createMenu, createPage, createPageUrls } from '@/remote/factory'
|
||||||
import { paramsToSlug } from '@/remote/lib'
|
import { paramsToSlug } from '@/remote/lib'
|
||||||
import { PageGrid } from '@/components/PageGrid'
|
import { PageGrid } from '@/components/PageGrid'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
@@ -42,6 +42,7 @@ type Props = {
|
|||||||
date: string
|
date: string
|
||||||
breadcrumb: IBreadcumbsPart[]
|
breadcrumb: IBreadcumbsPart[]
|
||||||
meta?: IMeta
|
meta?: IMeta
|
||||||
|
menu: IMenu[],
|
||||||
tokens: Token[]
|
tokens: Token[]
|
||||||
documentSignature: Sign
|
documentSignature: Sign
|
||||||
}
|
}
|
||||||
@@ -62,6 +63,7 @@ const Index: NextPage<Props> = props => {
|
|||||||
marginTop: 'var(--size-l)',
|
marginTop: 'var(--size-l)',
|
||||||
marginBottom: 'var(--size-xl)',
|
marginBottom: 'var(--size-xl)',
|
||||||
}}
|
}}
|
||||||
|
menu={props.menu}
|
||||||
breadcrumbs={props.breadcrumb}
|
breadcrumbs={props.breadcrumb}
|
||||||
>
|
>
|
||||||
<Head>
|
<Head>
|
||||||
@@ -165,6 +167,8 @@ export const getStaticProps: GetStaticProps<Props> = async ctx => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const menu = await apiGet(createMenu)('https://hudozka.tmshv.com/menu', [])
|
||||||
|
|
||||||
const description = page.description ?? undefined
|
const description = page.description ?? undefined
|
||||||
const breadcrumbSize = page?.breadcrumb?.length ?? 0
|
const breadcrumbSize = page?.breadcrumb?.length ?? 0
|
||||||
const breadcrumb = breadcrumbSize < 2 ? null : page.breadcrumb
|
const breadcrumb = breadcrumbSize < 2 ? null : page.breadcrumb
|
||||||
@@ -183,6 +187,7 @@ export const getStaticProps: GetStaticProps<Props> = async ctx => {
|
|||||||
tags: page.tags,
|
tags: page.tags,
|
||||||
date: page.date,
|
date: page.date,
|
||||||
meta,
|
meta,
|
||||||
|
menu,
|
||||||
breadcrumb,
|
breadcrumb,
|
||||||
documentSignature: {
|
documentSignature: {
|
||||||
date: '20.01.2021г.',
|
date: '20.01.2021г.',
|
||||||
|
|||||||
+6
-2
@@ -5,13 +5,14 @@ import { PageGrid } from 'src/components/PageGrid'
|
|||||||
import { HudozkaTitle } from 'src/components/HudozkaTitle'
|
import { HudozkaTitle } from 'src/components/HudozkaTitle'
|
||||||
import { MetaBuilder } from 'src/lib/meta'
|
import { MetaBuilder } from 'src/lib/meta'
|
||||||
import { NextPage } from 'next'
|
import { NextPage } from 'next'
|
||||||
import { IMeta, PageCardDto } from 'src/types'
|
import { IMenu, IMeta, PageCardDto } from 'src/types'
|
||||||
import { apiGet } from '@/next-lib'
|
import { apiGet } from '@/next-lib'
|
||||||
import { createHomeCards } from '@/remote/factory'
|
import { createHomeCards, createMenu } from '@/remote/factory'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string
|
title: string
|
||||||
meta: IMeta
|
meta: IMeta
|
||||||
|
menu: IMenu[]
|
||||||
items: PageCardDto[]
|
items: PageCardDto[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ const Index: NextPage<Props> = props => (
|
|||||||
<App
|
<App
|
||||||
showAuthor={true}
|
showAuthor={true}
|
||||||
wide={false}
|
wide={false}
|
||||||
|
menu={props.menu}
|
||||||
>
|
>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{props.title}</title>
|
<title>{props.title}</title>
|
||||||
@@ -41,6 +43,7 @@ const Index: NextPage<Props> = props => (
|
|||||||
export const getStaticProps = async () => {
|
export const getStaticProps = async () => {
|
||||||
const url = 'https://hudozka.tmshv.com/home'
|
const url = 'https://hudozka.tmshv.com/home'
|
||||||
const items = await apiGet(createHomeCards)(url, [])
|
const items = await apiGet(createHomeCards)(url, [])
|
||||||
|
const menu = await apiGet(createMenu)('https://hudozka.tmshv.com/menu', [])
|
||||||
|
|
||||||
const title = 'Шлиссельбургская ДХШ'
|
const title = 'Шлиссельбургская ДХШ'
|
||||||
const meta = (new MetaBuilder())
|
const meta = (new MetaBuilder())
|
||||||
@@ -55,6 +58,7 @@ export const getStaticProps = async () => {
|
|||||||
items,
|
items,
|
||||||
title,
|
title,
|
||||||
meta,
|
meta,
|
||||||
|
menu,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Footer } from '../Footer'
|
|||||||
import { Content } from '../Content'
|
import { Content } from '../Content'
|
||||||
import { Block } from '../Block'
|
import { Block } from '../Block'
|
||||||
import { Breadcrumbs } from '../Breadcrumbs'
|
import { Breadcrumbs } from '../Breadcrumbs'
|
||||||
import { IBreadcumbsPart } from 'src/types'
|
import { IBreadcumbsPart, IMenu } from 'src/types'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useMobile } from 'src/hooks/useMobile'
|
import { useMobile } from 'src/hooks/useMobile'
|
||||||
|
|
||||||
@@ -19,9 +19,10 @@ export interface IAppProps {
|
|||||||
wide?: boolean
|
wide?: boolean
|
||||||
contentStyle?: React.CSSProperties
|
contentStyle?: React.CSSProperties
|
||||||
breadcrumbs?: IBreadcumbsPart[]
|
breadcrumbs?: IBreadcumbsPart[]
|
||||||
|
menu: IMenu[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const App: React.FC<IAppProps> = ({ showAuthor = false, wide = false, ...props }) => {
|
export const App: React.FC<IAppProps> = ({ showAuthor = false, wide = false, menu, ...props }) => {
|
||||||
const hideBreadcrumbs = useMobile()
|
const hideBreadcrumbs = useMobile()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const blockStyle = {
|
const blockStyle = {
|
||||||
@@ -29,7 +30,10 @@ export const App: React.FC<IAppProps> = ({ showAuthor = false, wide = false, ...
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigContext.Provider value={config}>
|
<ConfigContext.Provider value={{
|
||||||
|
...config,
|
||||||
|
menu,
|
||||||
|
}}>
|
||||||
<Wrapper
|
<Wrapper
|
||||||
header={(
|
header={(
|
||||||
<header>
|
<header>
|
||||||
|
|||||||
+15
-3
@@ -1,6 +1,6 @@
|
|||||||
import { ImageDefinition, IPage, ITag, PageCardDto, Token } from "@/types";
|
import { ImageDefinition, IMenu, IPage, ITag, PageCardDto, Token } from "@/types";
|
||||||
import { asItem } from "./lib";
|
import { asItem } from "./lib";
|
||||||
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia } from "./types";
|
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia, StrapiMenu } from "./types";
|
||||||
|
|
||||||
export function createPageUrls(pages: StrapiPage[]) {
|
export function createPageUrls(pages: StrapiPage[]) {
|
||||||
return {
|
return {
|
||||||
@@ -102,7 +102,19 @@ export function createPageTokens(components: StrapiComponent[]): Token[] {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPage(res: StrapiPage | StrapiPage[]): IPage {
|
export function createMenu(res: StrapiMenu): IMenu[] {
|
||||||
|
const items: IMenu[] = res.menu.items.map(x => ({
|
||||||
|
href: x.page.slug,
|
||||||
|
name: x.page.title,
|
||||||
|
}))
|
||||||
|
|
||||||
|
return [{
|
||||||
|
href: '/',
|
||||||
|
name: res.homeLabel,
|
||||||
|
}, ...items]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPage(res: StrapiPage | StrapiPage[]): IPage | null {
|
||||||
const item = asItem(res)
|
const item = asItem(res)
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
+10
-2
@@ -90,7 +90,7 @@ export type StrapiTag = {
|
|||||||
id: number,
|
id: number,
|
||||||
slug: string,
|
slug: string,
|
||||||
name: string,
|
name: string,
|
||||||
// "page": 114,
|
page: StrapiPage,
|
||||||
// "created_at": "2021-01-31T20:38:39.373Z",
|
// "created_at": "2021-01-31T20:38:39.373Z",
|
||||||
// "updated_at": "2021-02-17T07:37:54.749Z"
|
// "updated_at": "2021-02-17T07:37:54.749Z"
|
||||||
}
|
}
|
||||||
@@ -119,9 +119,17 @@ export type StrapiHome = {
|
|||||||
// "updated_at": "2021-02-04T16:28:30.961Z",
|
// "updated_at": "2021-02-04T16:28:30.961Z",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type StrapiMenu = {
|
||||||
|
id: number,
|
||||||
|
homeLabel: string
|
||||||
|
menu: StrapiComponentCardGrid
|
||||||
|
// "created_at": "2021-02-04T04:12:38.291Z",
|
||||||
|
// "updated_at": "2021-02-04T16:28:30.961Z",
|
||||||
|
}
|
||||||
|
|
||||||
export type StrapiPageCard = {
|
export type StrapiPageCard = {
|
||||||
__component: 'hudozka.page-card',
|
__component: 'hudozka.page-card',
|
||||||
id: number,
|
id: number,
|
||||||
page: StrapiPage,
|
page: StrapiPage,
|
||||||
layout: 'small' | 'medium' | 'big',
|
layout: 'small' | 'medium' | 'big',
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user