From 4f5f3bb9d74699f6053c1f1f5c68c775ed1009b4 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Wed, 17 Feb 2021 10:41:42 +0300 Subject: [PATCH] tags from strapi --- src/remote/factory.ts | 11 +++++++++-- src/remote/types.ts | 28 ++++++++++------------------ src/types.ts | 1 + 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/remote/factory.ts b/src/remote/factory.ts index b78569f6..93d37823 100644 --- a/src/remote/factory.ts +++ b/src/remote/factory.ts @@ -1,5 +1,5 @@ import { getResizedUrl, imageSrc } from "@/lib/image"; -import { IPage, PageCardDto, Token } from "@/types"; +import { IPage, ITag, PageCardDto, Token } from "@/types"; import { asItem } from "./lib"; import { StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard } from "./types"; @@ -69,6 +69,13 @@ export function createPage(res: StrapiPage | StrapiPage[]): IPage { return null } + const tags: ITag[] = item.tags.map(tag => ({ + id: tag.id, + name: tag.name, + slug: tag.slug, + href: `/tags/${tag.slug}`, + })) + return { title: item.title, description: item.excerpt, @@ -91,7 +98,7 @@ export function createPage(res: StrapiPage | StrapiPage[]): IPage { ...createPageTokens(item.content) .filter(Boolean), ], - tags: [], + tags, // breadcrumb?: [], featured: false, } diff --git a/src/remote/types.ts b/src/remote/types.ts index 5f289890..62e4fa0c 100644 --- a/src/remote/types.ts +++ b/src/remote/types.ts @@ -79,6 +79,15 @@ export type StrapiComponent = | StrapiComponentDocument | StrapiComponentEmbed +export type StrapiTag = { + id: number, + slug: string, + name: string, + // "page": 114, + // "created_at": "2021-01-31T20:38:39.373Z", + // "updated_at": "2021-02-17T07:37:54.749Z" +} + export type StrapiPage = { id: number, title: string, @@ -90,24 +99,7 @@ export type StrapiPage = { created_at: string, updated_at: string, content: StrapiComponent[], - // "tags": [ - // { - // "id": 5, - // "slug": "hudozka", - // "name": "Художка", - // "page": 114, - // "created_at": "2021-01-31T20:38:39.373Z", - // "updated_at": "2021-02-04T04:04:34.943Z" - // }, - // { - // "id": 6, - // "slug": "public-space", - // "name": "Среда", - // "page": 114, - // "created_at": "2021-01-31T20:38:39.722Z", - // "updated_at": "2021-02-04T04:04:34.943Z" - // } - // ], + tags: StrapiTag[], // "breadcrumbs": [], // "breadcrumbRelations": [] } diff --git a/src/types.ts b/src/types.ts index ffb3ca26..9f5aa87a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -87,6 +87,7 @@ export interface IImage { } export interface ITag { + id: number name: string slug: string href: string