menu from api
This commit is contained in:
1 parent
7e856bce18
commit
bc2f1f78fd
5 files changed
+45
-12
No files matched your search
+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 { 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[]) {
|
||||
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)
|
||||
if (!item) {
|
||||
return null
|
||||
|
||||
+10
-2
@@ -90,7 +90,7 @@ export type StrapiTag = {
|
||||
id: number,
|
||||
slug: string,
|
||||
name: string,
|
||||
// "page": 114,
|
||||
page: StrapiPage,
|
||||
// "created_at": "2021-01-31T20:38:39.373Z",
|
||||
// "updated_at": "2021-02-17T07:37:54.749Z"
|
||||
}
|
||||
@@ -119,9 +119,17 @@ export type StrapiHome = {
|
||||
// "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 = {
|
||||
__component: 'hudozka.page-card',
|
||||
id: number,
|
||||
page: StrapiPage,
|
||||
layout: 'small' | 'medium' | 'big',
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user