From a030a84652805323536da4038c017d60019a81b3 Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala <60499540+chiragchhatrala@users.noreply.github.com> Date: Tue, 27 May 2025 14:01:11 +0530 Subject: [PATCH] Enhance Sitemap Configuration with Dynamic URL Generation (#769) - Introduced functions to dynamically generate URLs for template industries and types in `sitemap.js`, improving the sitemap's adaptability to changes in templates. - Added an asynchronous function to fetch integration pages from an external API, enhancing the sitemap's content with integration links. - Updated cache duration to 2 hours for better performance. These changes aim to improve the sitemap's functionality and ensure it reflects the latest available templates and integrations. Co-authored-by: Julien Nahum --- client/sitemap.js | 73 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/client/sitemap.js b/client/sitemap.js index d15e1212..f943ffde 100644 --- a/client/sitemap.js +++ b/client/sitemap.js @@ -1,5 +1,72 @@ +import templateIndustries from './data/forms/templates/industries.json' +import templateTypes from './data/forms/templates/types.json' +import opnformConfig from './opnform.config.js' + export default { - exclude: ["/settings/**", "/subscriptions/**", "/templates/my-templates"], - sources: [process.env.NUXT_PUBLIC_API_BASE + "/sitemap-urls"], - cacheMaxAgeSeconds: 3600, + exclude: ['/settings/**', '/subscriptions/**', '/templates/my-templates'], + sources: [`${process.env.NUXT_PUBLIC_API_BASE}sitemap-urls`], + cacheMaxAgeSeconds: 60 * 60 * 2, // 2 hours + xslColumns: [ + { label: 'URL', width: '50%' }, + { label: 'Last Modified', select: 'sitemap:lastmod', width: '25%' }, + { label: 'Priority', select: 'sitemap:priority', width: '12.5%' }, + { label: 'Change Frequency', select: 'sitemap:changefreq', width: '12.5%' } + ], + urls: async () => { + return [ + ...getTemplateIndustriesUrls(), + ...getTemplateTypesUrls(), + ...(await getIntegrationsPages().catch(() => [])), + ] + } +} + +function getTemplateTypesUrls () { + return Object.values(templateTypes).map((feature) => { + return { + url: `/templates/types/${feature.slug}`, + changefreq: 'monthly', + priority: 0.8 + } + }) +} + +function getTemplateIndustriesUrls () { + return Object.values(templateIndustries).map((feature) => { + return { + url: `/templates/industries/${feature.slug}`, + changefreq: 'monthly', + priority: 0.8 + } + }) +} + +async function getIntegrationsPages () { + try { + const databaseId = '1eda631bec208005bd8ed9988b380263' + const apiUrl = opnformConfig.notion.worker + if (!apiUrl) return [] + + const response = await fetch(`${apiUrl}/table/${databaseId}`, { + timeout: 5000, + headers: { 'Cache-Control': 'no-cache' } + }) + + if (!response.ok) return [] + + const pages = await response.json() + return pages.map((page) => { + const slug = page.Slug ?? page.slug ?? null + const published = page.Published ?? page.published ?? false + if (!slug || !published) return null + return { + url: `/integrations/${slug}`, + changefreq: 'monthly', + priority: 0.9 + } + }).filter((page) => page) + } catch (error) { + console.warn('Error fetching integrations pages for sitemap:', error.message) + return [] + } }