Skip to content

Commit

Permalink
Revert "Remove server-sitemap.xml and simplify exclude list in next-s…
Browse files Browse the repository at this point in the history
…itemap config"

This reverts commit 359c1b5.
  • Loading branch information
heatlikeheatwave committed Sep 12, 2024
1 parent 8825251 commit 6d06771
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
57 changes: 55 additions & 2 deletions next-sitemap.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions src/pages/server-sitemap.xml/index.tsx
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6d06771

Please sign in to comment.