diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-02 18:36:09 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-02 18:36:09 +0200 |
| commit | ca921d7536cfe950b5a7d442977bbf900b48faf4 (patch) | |
| tree | 2e8bb3f4b81414ee881c3d92d9bdfed411c569db /src/ts | |
| parent | 9308a6dce03bd0c616e0ba6fec227473aaa44b33 (diff) | |
chore: fetch posts for rss feed
Diffstat (limited to 'src/ts')
| -rw-r--r-- | src/ts/types/app.ts | 86 | ||||
| -rw-r--r-- | src/ts/types/raw-data.ts | 103 |
2 files changed, 189 insertions, 0 deletions
diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts new file mode 100644 index 0000000..b09f3d5 --- /dev/null +++ b/src/ts/types/app.ts @@ -0,0 +1,86 @@ +export type AuthorKind = 'page' | 'comment'; + +export type Author<T extends AuthorKind> = { + avatar?: Image; + description?: T extends 'page' ? string | undefined : never; + name: string; + website?: string; +}; + +export type CommentMeta = { + author: Author<'comment'>; + date: string; +}; + +export type Comment = { + approved: boolean; + content: string; + id: number; + meta: CommentMeta; + parentId: number; + replies: Comment[]; +}; + +export type Dates = { + publication: string; + update: string; +}; + +export type Image = { + alt: string; + height: number; + src: string; + title?: string; + width: number; +}; + +export type Repos = { + github?: string; + gitlab?: string; +}; + +export type SEO = { + description: string; + title: string; +}; + +export type PageKind = 'article' | 'project' | 'thematic' | 'topic'; + +export type Meta<T extends PageKind> = { + articles?: T extends 'thematic' | 'topic' ? Article[] : never; + author: Author<'page'>; + commentsCount?: T extends 'article' ? number : never; + cover?: Image; + dates: Dates; + license?: T extends 'projects' ? string : never; + readingTime: number; + repos?: T extends 'projects' ? Repos : never; + seo: SEO; + technologies?: T extends 'projects' ? string[] : never; + thematics?: T extends 'article' | 'topic' ? PageLink[] : never; + topics?: T extends 'article' | 'thematic' ? PageLink[] : never; + website?: T extends 'topic' ? string : never; + wordsCount: number; +}; + +export type Page<T extends PageKind> = { + content: string; + id: number; + intro: string; + meta?: Meta<T>; + slug: string; + title: string; +}; + +export type PageLink = { + id: number; + name: string; + slug: string; +}; + +export type Article = Page<'article'>; +export type ArticleCard = Pick<Article, 'id' | 'slug' | 'title'> & + Pick<Meta<'article'>, 'cover' | 'dates'>; +export type Project = Page<'project'>; +export type Thematic = Page<'thematic'>; +export type Topic = Page<'topic'>; diff --git a/src/ts/types/raw-data.ts b/src/ts/types/raw-data.ts new file mode 100644 index 0000000..43a2453 --- /dev/null +++ b/src/ts/types/raw-data.ts @@ -0,0 +1,103 @@ +/** + * Types for raw data coming from GraphQL API. + */ + +import { NodeResponse, PageInfo } from '@services/graphql/api'; +import { AuthorKind } from './app'; + +export type ACFPosts = { + postsInThematic?: RawThematicPreview[]; + postsInTopic?: RawTopicPreview[]; +}; + +export type ACFThematics = { + postsInThematic: RawArticle[]; +}; + +export type ACFTopics = { + officialWebsite: string; + postsInTopic: RawArticle[]; +}; + +export type ContentParts = { + afterMore: string; + beforeMore: string; +}; + +export type Info = { + readingTime: number; + wordsCount: number; +}; + +export type RawAuthor<T extends AuthorKind> = { + description?: T extends 'page' ? string | undefined : never; + gravatarUrl?: string; + name: string; + url?: string; +}; + +export type RawComment = { + approved: boolean; + author: NodeResponse<RawAuthor<'comment'>>; + content: string; + databaseId: number; + date: string; + parentDatabaseId: number; +}; + +export type RawCover = { + altText: string; + mediaDetails: { + width: number; + height: number; + }; + sourceUrl: string; + title?: string; +}; + +export type RawArticle = RawPage & { + acfPosts: ACFPosts; + commentCount: number | null; +}; + +export type RawArticlePreview = Pick< + RawArticle, + 'databaseId' | 'date' | 'featuredImage' | 'slug' | 'title' +>; + +export type RawPage = { + author: NodeResponse<RawAuthor<'page'>>; + contentParts: ContentParts; + databaseId: number; + date: string; + featuredImage: NodeResponse<RawCover> | null; + info: Info; + modified: string; + seo?: RawSEO; + slug: string; + title: string; +}; + +export type RawSEO = { + metaDesc: string; + title: string; +}; + +export type RawThematic = RawPage & { + acfThematics: ACFThematics; +}; + +export type RawThematicPreview = Pick< + RawThematic, + 'databaseId' | 'slug' | 'title' +>; + +export type RawTopic = RawPage & { + acfTopics: ACFTopics; +}; + +export type RawTopicPreview = Pick<RawTopic, 'databaseId' | 'slug' | 'title'>; + +export type TotalItems = { + pageInfo: Pick<PageInfo, 'total'>; +}; |
