Skip to content

Commit

Permalink
feat(announcements): add frontmatter types
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj committed Sep 14, 2023
1 parent 03545ea commit ee8c124
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/types/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface InfopicSection {
description?: string
button?: string
url?: string
images?: string
image?: string
alt?: string
}

Expand All @@ -59,6 +59,18 @@ export interface ResourcesSection {
button?: string
}

export interface AnnouncementsSection {
title?: string
subtitle?: string
announcement_items?: Array<{
title?: string
date?: string
announcement?: string
link_text?: string
link_url?: string
}>
}

export interface HomepageDto {
content: {
frontMatter: {
Expand All @@ -73,6 +85,7 @@ export interface HomepageDto {
| InfobarSection
| InfopicSection
| ResourcesSection
| AnnouncementsSection
)[]
}
pageBody?: string
Expand All @@ -91,27 +104,26 @@ export type HomepageEditorHeroSection =
| EditorHeroHighlightsSection

export type HeroFrontmatterSection = { hero: HomepageEditorHeroSection }
// TODO: add properties here instead of typing as `Record<string, unknown>`
// we can find them in `HomepagePreview`
export type ResourcesFrontmatterSection = { resources: Record<string, unknown> }
export type ResourcesFrontmatterSection = { resources: ResourcesSection }

// TODO: add properties here instead of typing as `Record<string, unknown>`
// we can find them in `HomepagePreview`
export type InfopicFrontmatterSection = {
infopic: Record<string, unknown>
infopic: InfopicSection
}

// TODO: add properties here instead of typing as `Record<string, unknown>`
// we can find them in `HomepagePreview`
export type InfobarFrontmatterSection = {
infobar: Record<string, unknown>
infobar: InfobarSection
}

export type AnnouncementsFrontmatterSection = {
announcements: AnnouncementsSection
}

export type EditorHomepageFrontmatterSection =
| HeroFrontmatterSection
| ResourcesFrontmatterSection
| InfopicFrontmatterSection
| InfobarFrontmatterSection
| AnnouncementsFrontmatterSection

export const EditorHomepageFrontmatterSection = {
isHero: (
Expand All @@ -130,6 +142,10 @@ export const EditorHomepageFrontmatterSection = {
section: EditorHomepageFrontmatterSection
): section is InfobarFrontmatterSection =>
!!(section as InfobarFrontmatterSection).infobar,
isAnnouncements: (
section: EditorHomepageFrontmatterSection
): section is AnnouncementsFrontmatterSection =>
!!(section as AnnouncementsFrontmatterSection).announcements,
}

export interface EditorHomepageState {
Expand Down

0 comments on commit ee8c124

Please sign in to comment.