From d242e00f4ab81b9404f4de5769d56410c1f09fbe Mon Sep 17 00:00:00 2001 From: kaaps Date: Fri, 5 Apr 2024 11:46:29 +0100 Subject: [PATCH 1/3] fix: sitemap with handbook and landing pages --- package.json | 2 +- scripts/sitemap.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0f35b8c0..23bd0fa4 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "sb": "npm run sb:pull && npm run sb:types", "handbook": "svelte-kit sync && npx ts-node@latest --project ./node.tsconfig.json ./scripts/handbook.ts", "datasources": "svelte-kit sync && npx ts-node@latest --project ./node.tsconfig.json ./scripts/datasources.ts", - "sitemap": "svelte-kit sync && npx ts-node@latest --project ./node.tsconfig.json ./scripts/sitemap.ts", + "sitemap": "svelte-kit sync && npx tsx --tsconfig ./node.tsconfig.json ./scripts/sitemap.ts", "prepare": "husky install" }, "devDependencies": { diff --git a/scripts/sitemap.ts b/scripts/sitemap.ts index aa6fe242..aa21b6e4 100644 --- a/scripts/sitemap.ts +++ b/scripts/sitemap.ts @@ -1,6 +1,9 @@ import fs from 'fs'; import * as dotenv from 'dotenv'; import { ISbResult, ISbStoryData, apiPlugin, storyblokInit } from '@storyblok/js'; +import { createFileTree } from '../src/lib/utils/notion'; +import type { PageObjectResponse } from '@notionhq/client/build/src/api-endpoints'; +import handbook from '../handbook-data.json'; dotenv.config(); @@ -14,6 +17,8 @@ const { storyblokApi } = storyblokInit({ const storyblok = storyblokApi as NonNullable['storyblokApi']>; +const chapters = createFileTree(handbook as Array); + type SitemapEntry = { loc: string; lastmod: string; @@ -89,7 +94,8 @@ async function main() { story.content.component === 'career' || story.content.component === 'page' || story.content.component === 'project' || - story.content.component === 'team-member' + story.content.component === 'team-member' || + story.content.component === 'landing-page' ); }) .map((story: ISbStoryData) => { @@ -127,10 +133,26 @@ async function main() { ); }, []); + const chaptersArray = Object.values(chapters) + .flat() + .map((chapter) => ({ + lastmod: chapter.lastUpdatedAt, + slug: chapter.slug + })); + + const entriesHandbook = chaptersArray.map((val) => ({ + loc: `https://significa.co/handbook/${val.slug}`, + lastmod: val.lastmod || new Date().toISOString(), + changefreq: 'monthly', + priority: 0.7 + })); + + const entriesWithHandbook = [...entries, ...entriesHandbook]; + // build a ../static/sitemap.xml file const xml = ` - ${entries + ${entriesWithHandbook .map( (entry) => ` From fb76666f236eca4c2ad3e56a8880bdd728d413d7 Mon Sep 17 00:00:00 2001 From: kaaps Date: Fri, 5 Apr 2024 11:52:29 +0100 Subject: [PATCH 2/3] fix: sitemap --- scripts/sitemap.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/sitemap.ts b/scripts/sitemap.ts index aa21b6e4..b9220859 100644 --- a/scripts/sitemap.ts +++ b/scripts/sitemap.ts @@ -128,6 +128,11 @@ async function main() { entry.priority = 0.8; } + if (story.content.component === 'landing-page') { + entry.changefreq = story.content.change_frequency || 'monthly'; + entry.priority = story.content.priority || 0.7; + } + return entry; }) ); From 18f43c3f5f61b2d8a5043476f3bc59722e793ca8 Mon Sep 17 00:00:00 2001 From: kaaps Date: Fri, 5 Apr 2024 15:09:47 +0100 Subject: [PATCH 3/3] fix: prebuild --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23bd0fa4..69dad83b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "vite dev", - "prebuild": "npm run datasources && npm run sitemap && npm run handbook -- -d", + "prebuild": "npm run datasources && npm run handbook -- -d && npm run sitemap", "build": "vite build", "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",