Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds landing-page & notion pages to sitemap #381

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
31 changes: 29 additions & 2 deletions scripts/sitemap.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -14,6 +17,8 @@ const { storyblokApi } = storyblokInit({

const storyblok = storyblokApi as NonNullable<ReturnType<typeof storyblokInit>['storyblokApi']>;

const chapters = createFileTree(handbook as Array<PageObjectResponse>);

type SitemapEntry = {
loc: string;
lastmod: string;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -122,15 +128,36 @@ 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;
})
);
}, []);

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];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the file isn't in the system? does the sitemap generation fails? or no pages appear in the sitemap? if it's the first, we should add some defensive programming for that

// build a ../static/sitemap.xml file
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${entries
${entriesWithHandbook
.map(
(entry) => `
<url>
Expand Down
Loading