From a511f900dd9a4709f2c4304be438b05d04543949 Mon Sep 17 00:00:00 2001 From: Damillora Date: Mon, 2 Dec 2024 01:12:32 +0700 Subject: [PATCH] fix: sitemap last updated --- src/lib/content/contentApi.ts | 4 ++-- src/lib/content/directusUtils.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/content/contentApi.ts b/src/lib/content/contentApi.ts index 97e3704..ed04028 100644 --- a/src/lib/content/contentApi.ts +++ b/src/lib/content/contentApi.ts @@ -1,6 +1,6 @@ import { createDirectus, readItems, rest } from '@directus/sdk'; -import { DIRECTUS_URL, mapAuthor, mapCategory, mapIndexPosts, mapPost } from './directusUtils'; +import { DIRECTUS_URL, mapAuthor, mapCategory, mapIndexPosts, mapPost, mapSitemapPosts } from './directusUtils'; const POSTS_PER_PAGE = 10; @@ -170,7 +170,7 @@ export const browseAllPost = async (page = 1) => { sort: ["-date_published"] })) - return posts.map(mapIndexPosts); + return posts.map(mapSitemapPosts); } export const browsePostWithTag = async (slug: string, page = 1) => { const filterTag = { diff --git a/src/lib/content/directusUtils.ts b/src/lib/content/directusUtils.ts index 3dd5ccd..83e09b1 100644 --- a/src/lib/content/directusUtils.ts +++ b/src/lib/content/directusUtils.ts @@ -56,6 +56,22 @@ export const mapIndexPosts = (post: any) => { } } +export const mapSitemapPosts = (post: any) => { + const author = mapPostAuthor(post.author); + const category = mapPostCategory(post.category); + + return { + title: post.title, + feature_image: generateAssetUrl(post.feature_image), + authors: [author], + category: category, + excerpt: post.excerpt, + date_published: post.date_published, + date_updated: post.date_updated, + reading_time: null, + url: generatePostUrl(category?.slug, post.slug), + } +} export const mapAuthor = (author: any) => { if (author) { return {