SEO Sitemaps
This guide explains how to use the WhiteBeard News Suite API to fetch sitemap data and expose the following URLs on your frontend:
/sitemap_index.xml/news-sitemap.xml/section-sitemap.xml/author-sitemap.xml/article-sitemap{number}.xml
These endpoints will allow search engines to crawl your site effectively.
1. API Endpoints Overview
Section titled “1. API Endpoints Overview”The following API paths are used to fetch the required sitemap data:
Sitemap Index
Section titled “Sitemap Index”- API Path:
/publication/{publication_id}/content/sitemap/index.xml - Description: Fetches the sitemap index for a publication.
- Response: Sitemap index in XML format.
- HTTP Method:
GET
News Sitemap
Section titled “News Sitemap”- API Path:
/publication/{publication_id}/content/sitemap/news.xml - Description: Fetches the news sitemap for a publication.
- Response: News sitemap in XML format.
- HTTP Method:
GET
Section Sitemap
Section titled “Section Sitemap”- API Path:
/publication/{publication_id}/content/sitemap/categories.xml - Description: Fetches the section/category sitemap for a publication.
- Response: Section sitemap in XML format.
- HTTP Method:
GET
Article Sitemap (Paginated)
Section titled “Article Sitemap (Paginated)”- API Path:
/publication/{publication_id}/content/sitemap/sitemap{page_number}.xml - Description: Fetches a paginated sitemap of articles for a publication.
- Response: Article sitemap in XML format.
- HTTP Method:
GET
Make sure to include an API-Key header. Refer to the Swagger docs to try out the API.
2. Implementation Steps
Section titled “2. Implementation Steps”Step 1: Expose the URLs on Your Frontend
Section titled “Step 1: Expose the URLs on Your Frontend”Ensure your frontend exposes the following URLs:
/sitemap_index.xml/news-sitemap.xml/section-sitemap.xml/author-sitemap.xml/article-sitemap{number}.xml
These URLs should act as proxies to fetch data from the API.
Step 2: Fetch Data from the API
Section titled “Step 2: Fetch Data from the API”Use the API paths to fetch the required sitemap data. Below is an example implementation for each sitemap type.
Sitemap Index
Section titled “Sitemap Index”import axios from 'axios';
export async function getSitemapIndex(publicationId) { const response = await axios.get(`/publication/${publicationId}/content/sitemap/index.xml`, { headers: { 'API-Key': 'your-api-key-here', // Replace with your actual API key }, }); return response.data; // XML response}News Sitemap
Section titled “News Sitemap”import axios from 'axios';
export async function getNewsSitemap(publicationId) { const response = await axios.get(`/publication/${publicationId}/content/sitemap/news.xml`, { headers: { 'API-Key': 'your-api-key-here', // Replace with your actual API key }, }); return response.data; // XML response}Section Sitemap
Section titled “Section Sitemap”import axios from 'axios';
export async function getSectionSitemap(publicationId) { const response = await axios.get(`/publication/${publicationId}/content/sitemap/categories.xml`, { headers: { 'API-Key': 'your-api-key-here', // Replace with your actual API key }, }); return response.data; // XML response}Authors Sitemap
Section titled “Authors Sitemap”Note that the authors site map currently lists all authors with a filled in “Department” name in the backend.
import axios from 'axios';
export async function getSectionSitemap(publicationId) { const response = await axios.get(`/publication/${publicationId}/content/sitemap/authors.xml`, { headers: { 'API-Key': 'your-api-key-here', // Replace with your actual API key }, }); return response.data; // XML response}Article Sitemap (Paginated)
Section titled “Article Sitemap (Paginated)”import axios from 'axios';
export async function getArticleSitemap(publicationId, pageNumber) { const response = await axios.get(`/publication/${publicationId}/content/sitemap/sitemap${pageNumber}.xml`, { headers: { 'API-Key': 'your-api-key-here', // Replace with your actual API key }, }); return response.data; // XML response}Step 3: Serve the Sitemaps
Section titled “Step 3: Serve the Sitemaps”Set up your backend or server to serve the sitemaps at the required URLs. For example:
Node.js/Express Example
Section titled “Node.js/Express Example”import express from 'express';import { getSitemapIndex, getNewsSitemap, getSectionSitemap, getArticleSitemap } from './sitemap_services';
const app = express();const publicationId = 'your-publication-id'; // Replace with your publication ID
// Cache duration: 1 year (in seconds)const CACHE_DURATION = 365 * 24 * 60 * 60;
app.get('/sitemap_index.xml', async (req, res) => { const sitemap = await getSitemapIndex(publicationId); res.set('Cache-Control', `public, max-age=${CACHE_DURATION}`).type('application/xml').send(sitemap);});
app.get('/news-sitemap.xml', async (req, res) => { const sitemap = await getNewsSitemap(publicationId); res.set('Cache-Control', `public, max-age=${CACHE_DURATION}`).type('application/xml').send(sitemap);});
app.get('/section-sitemap.xml', async (req, res) => { const sitemap = await getSectionSitemap(publicationId); res.set('Cache-Control', `public, max-age=${CACHE_DURATION}`).type('application/xml').send(sitemap);});
app.get('/article-sitemap:pageNumber.xml', async (req, res) => { const { pageNumber } = req.params; const sitemap = await getArticleSitemap(publicationId, pageNumber); res.set('Cache-Control', `public, max-age=${CACHE_DURATION}`).type('application/xml').send(sitemap);});
app.listen(3000, () => console.log('Server running on port 3000'));3. Testing the Implementation
Section titled “3. Testing the Implementation”-
Start your server and ensure the URLs are accessible:
http://localhost:3000/sitemap_index.xmlhttp://localhost:3000/news-sitemap.xmlhttp://localhost:3000/section-sitemap.xmlhttp://localhost:3000/article-sitemap1.xml
-
Verify the XML responses match the expected format.
-
Submit the URLs to search engines (e.g., Google Search Console) for indexing.
4. Notes
Section titled “4. Notes”-
Cache Headers: The Cache-Control header is set to cache the sitemap responses for 1 year (max-age=31536000). This ensures that the sitemaps are cached efficiently by Cloudflare. Make sure your Cloudflare cache rules are set to prevent browser caching.
-
Proactive Purging: The CMS will proactively purge the sitemap URLs on your frontend whenever a related change occurs (e.g., new content, updated articles, or deleted sections). This ensures that the cached sitemaps are always up-to-date without requiring manual intervention.