
Sitemaps can help search engines find content on your website. RSS feeds allow your website users to follow updates from their preferred RSS readers. In this guide, I'll show how to use our new API to create a sitemap for your styleguide and RSS feed of your releases.
Search engines such as Google and Bing use bots to crawl web pages. The crawled content is then compared with web searches so people can find those pages. However, without a map of your website, they might struggle to find all the pages contained within it. That's where Sitemaps come in. They're typically hosted on the website and list all the pages within your website and the last time they were updated. So how can we create sitemaps for our styleguides? That's where the zeroheight API comes into play.
Before continuing, you’ll need to make sure you have access to the API. Currently, the zeroheight API is only available for Enterprise customers. You can upgrade your plan here. You also may need to contact the administrator of your zeroheight instance to either get access or provide API credentials.
Also, we'll be using JavaScript (Node) for this tutorial, so some familiarity will be helpful. However, for those of you who might not be so comfortable writing your own Node script from scratch, do not fear! I've created an open-source project on GitHub that you can fork and repurpose for yourself. You can even use the deployment options in the documentation to deploy it directly to Netlify or Vercel.
If you check out the demo, you'll see that the project creates a very basic landing page with links to the sitemap and RSS feed. These can be directly pointed to or downloaded and used in submissions to search engines via SEO tools. Follow the attached documentation to set it up.
We have a handy guide in our Help Center to help you create a new authentication token for the API. When creating your authentication token, adjust the permissions as needed. For this guide, we'll only need read access. Don't forget to make a note of your Client ID and Access Token during setup, as your Access Token will be hidden after it's created.
The one other key needed is the ID of the styleguide you want to retrieve using the API. Navigate to your styleguide and use the address bar in your web browser to view the whole URL. It should follow a pattern that looks like this:
account.zeroheight.com/styleguide/s/STYLEGUIDEID/p/...
The characters that follow /styleguide/s/ and precede /p/ will be the ID of your styleguide. Make a note of this alongside your authentication token details.
Because we'll be using Node and running this in a deployment process, we can safely store these environment details in an .env and source them in JavaScript without exposing them and risking security issues. Here's an example .env file:
KEY="API_KEY"
CLIENT="API_CLIENT"
STYLEGUIDE="STYLEGUIDE_ID"
STYLEGUIDE_TITLE="My Design System Title"
STYLEGUIDE_URL="https://mystyleguidedomain.com"
Note the additional variables here STYLEGUIDE_TITLE and STYLEGUIDE_URL. These aren't needed to access the API but are needed within the RSS feed and will appear for users within their RSS reader.
While getting page data from the zeroheight API just requires a single request, we're going to be splitting this tutorial into two. The Pages endpoint has two methods, LIST and GET. The first will list all the pages in our styleguide, and the second will get tabbed content on each of those pages. The GET option for the Pages endpoint provides all sorts of more detailed information.
First, let’s get all the pages using the Pages endpoint:
const fetchData = (endpoint) => {
console.log(`Fetching data from endpoint: ${endpoint}`);
return fetch(endpoint, {
method: "GET",
headers: {
"X-API-KEY": KEY,
"X-API-CLIENT": CLIENT,
},
})
.then((res) => res.json())
.then((json) => {
console.log(`Data fetched from endpoint: ${endpoint}`, json);
return json.data;
})
.catch((error) => {
console.error(`Error fetching data from endpoint: ${endpoint}`, error);
throw error;
});
};The above JavaScript makes use of the fetch() API to list all the pages data. Once retrieved as JSON, the pages key is then chosen from the data object in the response. Finally, to help with testing, I've added a few lines to log the data and the errors in case something goes wrong.
Each page in your styleguide can contain multiple tabs. These aren’t returned in the initial list of pages, so we need to make individual requests for each page using the GET method of the Pages endpoint.
Here’s how we can do that:
const fetchSinglePage = async (page) => {
console.log(`Fetching single page: ${page.id}`);
const data = await fetchData(
`https://zeroheight.com/open_api/v2/pages/${page.id}`
);
console.log(`Data fetched for single page: ${page.id}`, data);
return data;
};This function takes a page object (from the list we fetched earlier), retrieves detailed data for that page (including its tabs), and returns it. We’ll later use this to build both our sitemap and RSS feed.
Sitemaps are written in XML and follow a specific structure. Each URL on your site is represented as an individual <url> element with a link and the last modified date.
Let’s look at how we build this XML for each page and tab:
const sitemapPagePartial = ({ url, updated_at }) => {
if (!url || !updated_at) {
console.error(`Invalid page data: url=${url}, updated_at=${updated_at}`);
return '';
}
return `
<url>
<loc>${url}</loc>
<lastmod>${updated_at.slice(0, 10)}</lastmod>
</url>
`;
};
const sitemapTabsPartial = (page) => {
return page.tabs
.filter((tab) => tab.order !== 1) // Avoid duplicating the main page
.map((tab) =>
sitemapPagePartial({ url: tab.url, updated_at: page.updated_at })
);
};
With these two helpers, we can now map through our fetched pages and generate the full sitemap structure using the urlset tag:
const sitemapTemplate = (content) => {
return `
<?xml version="1.0" encoding="UTF-8"?>
<urlset >
${content.join("")}
</urlset>
`.trim();
};To build our RSS feed, we need to retrieve version release data from the zeroheight API. This data includes things like version names, release notes, timestamps, and links to the release itself — all perfect content for an RSS item.
The fetchReleases function handles this:
const fetchReleases = () => {
return fetchData(
`https://zeroheight.com/open_api/v2/styleguides/${STYLEGUIDE}/versions`
);
};This uses our generic fetchData() utility to hit the /versions endpoint for the styleguide. The API response includes an array of version objects, each containing:
name: The name of the version (e.g. “v2.0”)created_at: A timestamp of when the version was publishedrelease_url: A URL pointing to the published releaserelease_notes: Optional text content with notes about the releaseHere's a snippet of what one version object might look like:
{
"name": "v1.2.0",
"created_at": "2024-11-15T12:00:00Z",
"release_url": "https://zeroheight.com/s/example/release/v1.2.0",
"release_notes": "New components added, updated spacing tokens."
}
We’ll later loop over this data to create individual RSS <item> elements, allowing subscribers to track updates to your design system over time — just like they would with a blog or podcast feed. You can also easily import this into something like Slack using tools like Zapier!
For your version releases (found under the Versions endpoint in the API), we’ll generate an RSS feed so users can subscribe to changes in their preferred RSS readers. Each item in the RSS feed includes a title, publication date, and link to the release.
const rssPartial = (version) => {
return `
<item>
<title>${version.name}</title>
<link>${version.release_url}</link>
<guid>${version.release_url}</guid>
<pubDate>${new Date(version.created_at).toUTCString()}</pubDate>
<content:encoded><![CDATA[${version.release_notes || ""}<p><a href="${
version.release_url
}">Browse this version</a></p>]]></content:encoded>
</item>
`;
};
const rssTemplate = (content) => {
return `
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns_content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>${STYLEGUIDE_TITLE || ""}</title>
<link>${STYLEGUIDE_URL || ""}</link>
${content.join("")}
</channel>
</rss>
`.trim();
};Finally, we generate and write the sitemap, RSS feed, and a small HTML index page to a directory. This is the part of the script that brings it all together:
const build = async (directory) => {
console.log(`Building sitemap and RSS feed in directory: ${directory}`);
const sitemapContent = await fetchPages().then((data) => {
return Promise.all(data.pages.map((page) => fetchSinglePage(page))).then(
(pages) => {
return pages.map(({ page }) => {
let contentPartial = sitemapPagePartial(page);
if (page.tabs) {
contentPartial += sitemapTabsPartial(page);
}
return contentPartial;
});
}
);
});
const rssContent = await fetchReleases().then((data) => {
if (!data || !data.versions) return [];
return data.versions.map((version) => rssPartial(version));
});
const sitemap = sitemapTemplate(sitemapContent);
const rss = rssTemplate(rssContent);
const index = indexTemplate();
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
fs.writeFileSync(`${directory}/sitemap.xml`, sitemap);
fs.writeFileSync(`${directory}/rss.xml`, rss);
fs.writeFileSync(`${directory}/index.html`, index);
console.log(`Sitemap and RSS feed written to ${directory}`);
};Run the script with:
node index.js --path ./build/
This will create your sitemap and RSS feed in the specified output directory.
You now have a working sitemap and RSS feed generated from your zeroheight styleguide. You can point SEO tools like Google Search Console or Bing Webmaster Tools to your sitemap.xml, and share your rss.xml feed with stakeholders who want updates on your design system releases. Similarly, you could use this as a basis for stronger search for your styleguide using a service like Algolia.
Want to go a step further? You can: