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 <julien@nahum.net>
This commit is contained in:
parent
434d8b694f
commit
a030a84652
|
|
@ -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 []
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue