Skip to content

Commit

Permalink
Make updated on and published on CMS field required
Browse files Browse the repository at this point in the history
  • Loading branch information
mirhamasala committed Feb 13, 2025
1 parent fc55c48 commit dc353b2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
3 changes: 0 additions & 3 deletions apps/site/public/admin/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ updated_on: &updated_on
name: "updated-on"
label: "Updated On"
widget: "datetime"

default: "{{now}}"
required: false
picker_utc: true

published_on: &published_on
name: "published-on"
label: "Published On"
widget: "datetime"
default: "{{now}}"
required: false
picker_utc: true

header_config: &header_config
Expand Down
4 changes: 2 additions & 2 deletions apps/site/src/app/_schemas/DynamicDataBaseSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { SeoMetadataWithOptionalTitleSchema } from '@/schemas/SeoMetadataSchema'
export const DynamicBaseDataSchema = z
.object({
'created-on': z.coerce.date(),
'updated-on': z.coerce.date().optional(),
'published-on': z.coerce.date().optional(),
'updated-on': z.coerce.date(),
'published-on': z.coerce.date(),
image: ImagePropsSchema.optional(),
seo: SeoMetadataWithOptionalTitleSchema,
})
Expand Down
4 changes: 2 additions & 2 deletions apps/site/src/app/blog/[slug]/utils/generateStructuredData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export function generateStructuredData(
name: ORGANIZATION_NAME,
url: BASE_URL,
},
datePublished: publishedOn?.toISOString(),
dateModified: updatedOn?.toISOString() || publishedOn?.toISOString(),
datePublished: publishedOn.toISOString(),
dateModified: updatedOn.toISOString(),
mainEntityOfPage: {
'@type': 'WebPage',
'@id': `${BASE_URL}${PATHS.BLOG.path}/${slug}`,
Expand Down
29 changes: 13 additions & 16 deletions apps/site/src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { formatISO } from 'date-fns'

import { PATHS } from '@/constants/paths'
import { BASE_URL } from '@/constants/siteMetadata'

Expand All @@ -10,20 +8,9 @@ import { getDigestArticlesData } from '@/digest/utils/getDigestArticleData'
import { getEcosystemProjectsData } from '@/ecosystem-explorer/utils/getEcosystemProjectData'
import { getEventsData } from '@/events/utils/getEventData'

type GenericEntryData = Pick<DynamicBaseData, 'updated-on'> & { slug: string }

function generateDynamicRoutes<T extends GenericEntryData>(
data: Array<T>,
basePath: string,
) {
return data.map((item) => {
const lastModifiedDate = formatISO(item['updated-on'] || new Date())

return {
url: `${BASE_URL}${basePath}/${item.slug}`,
lastModified: lastModifiedDate,
}
})
type GenericEntryData = {
updatedOn: DynamicBaseData['updated-on']
slug: string
}

export default async function sitemap() {
Expand Down Expand Up @@ -58,3 +45,13 @@ export default async function sitemap() {
...dynamicEventRoutes,
]
}

function generateDynamicRoutes<T extends GenericEntryData>(
data: Array<T>,
basePath: string,
) {
return data.map(({ slug, updatedOn }) => ({
url: `${BASE_URL}${basePath}/${slug}`,
lastModified: updatedOn.toISOString(),
}))
}

0 comments on commit dc353b2

Please sign in to comment.