diff --git a/next-sitemap.config.js b/next-sitemap.config.js index 65129c8f35..41358d3c48 100644 --- a/next-sitemap.config.js +++ b/next-sitemap.config.js @@ -4,14 +4,67 @@ */ /** @type {import('next-sitemap').IConfig} */ +const siteUrl = process.env.SITE_URL || 'https://developer.hashicorp.com' + module.exports = { - siteUrl: 'https://developer.hashicorp.com', + siteUrl, generateRobotsTxt: true, robotsTxtOptions: { + additionalSitemaps: [ + `${siteUrl}/hcp-sitemap.xml`, + // sitemap generated from ./pages/server-sitemap.xml/index.tsx + `${siteUrl}/server-sitemap.xml`, + ], policies: [ { userAgent: 'GPTBot', disallow: '/validated-designs' }, { userAgent: '*', allow: '/' }, // default policy ], }, - exclude: ['/profile*', 'sitemap.xml', '/validated-designs'], + /* + * Exhaustive exclude list to remove duplicate sitemap paths. + * This list will not exist once all phases of the Sitemap Improvements project is complete + * Sitemap Improvements Asana https://app.asana.com/0/1203590180322427/overview + */ + exclude: [ + '/onboarding/*', + '/profile*', + 'sitemap.xml', + '/server-sitemap.xml', + '/boundary/docs*', + '/boundary/tutorials*', + '/consul/docs*', + '/consul/commands*', + '/consul/api-docs*', + '/consul/tutorials*', + '/nomad/docs*', + '/nomad/plugins*', + '/nomad/intro*', + '/nomad/tools*', + '/nomad/tutorials*', + '/packer/docs*', + '/packer/guides*', + '/packer/intro*', + '/packer/plugins*', + '/packer/tutorials*', + '/terraform/docs*', + '/terraform/cli*', + '/terraform/internals*', + '/terraform/intro*', + '/terraform/language*', + '/terraform/tutorials*', + '/vagrant/docs*', + '/vagrant/intro*', + '/vagrant/vagrant-cloud*', + '/vagrant/tutorials*', + '/waypoint/docs*', + '/waypoint/commands*', + '/waypoint/plugins*', + '/waypoint/tutorials*', + '/vault/docs*', + '/vault/api-docs*', + '/vault/tutorials*', + '/well-architected-framework/*', + '/hcp/tutorials*', + '/hcp/docs', + ], } diff --git a/package.json b/package.json index a66b6afbfb..d9aaef95de 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "prestart": "hc-tools ./scripts/generate-tutorial-variant-map.ts && hc-tools ./scripts/extract-hvd-content.ts", "prettier:check": "prettier --check .", "prettier:write": "prettier --write .", - "postbuild": "hc-tools ./scripts/capture-build-metrics.ts dev-portal && hc-tools ./scripts/upload-source-maps.ts && next-sitemap", + "postbuild": "hc-tools ./scripts/capture-build-metrics.ts dev-portal && next-sitemap && hc-tools ./scripts/upload-source-maps.ts", "rewrite-docs-content-links": "hc-tools ./scripts/docs-content-link-rewrites/rewrite-links.ts", "sitemap": "next-sitemap", "start:local-preview": "./scripts/content-repo-preview/start.sh", diff --git a/src/pages/server-sitemap.xml/index.tsx b/src/pages/server-sitemap.xml/index.tsx new file mode 100644 index 0000000000..c7d13bb33e --- /dev/null +++ b/src/pages/server-sitemap.xml/index.tsx @@ -0,0 +1,28 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { getServerSideSitemap } from 'next-sitemap' +import { GetServerSideProps, GetServerSidePropsContext } from 'next' +import { allDocsFields, allTutorialsFields } from 'lib/sitemap' + +export const getServerSideProps: GetServerSideProps = async ( + ctx: GetServerSidePropsContext +) => { + try { + // returns an array of docs content sitemap fields per slug + const docsFields = await allDocsFields() + // returns an array of tutorials content sitemap fields per slug + const tutorialsFields = await allTutorialsFields() + + return getServerSideSitemap(ctx, [...docsFields, ...tutorialsFields]) + } catch (error) { + throw new Error('Error generating server-sitemap.xml', error) + } +} + +// Default export to prevent next.js errors +export default function Sitemap() { + return null +}