Nuxt Content: Use custom subdomain in sitemap
Hello,
I'm using the nuxt/content and nuxt/sitemap modules. I've got a list of markdown files under the directory "content/publications" which contains meta data for some PDF files.
The PDF files are hosted under a separate subdomain (
media.mydomain.com
). The metadata for the publications are serverd under mydomain.com/publications
.
So for example I've got the publications "Article1". I can find the meta-data like a short description, author and a img via mydomain.com/publications/article1
. Additionally a link to download the PDF file, which is served under media.mydomain.com/article1
.
Using the Sitemap-module generates a sitemap with the link for mydomain.com/publications/article1
. However I do not want the URL for the metadata but instead the conrecte PDF URL in my sitemap. For example:
How can i implement this?Nuxt Content
The git-based CMS for Nuxt projects
Nuxt Content is a module for Nuxt that provides a simple way to manage content for your application. It allows developers to write their content in Markdown, YAML, or JSON files and then query and display it in their application.
3 Replies
Hi @Theiaz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To achieve a sitemap that lists the PDF URLs (e.g.,
You must override the default sitemap URLs by providing your own list of PDF URLs, typically by querying your content and mapping to the correct subdomain. The knowledge sources do not provide a ready-made code snippet for this, but they confirm that this is the recommended approach for dynamic or external URLs. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<http://media.mydomain.com/article1
>) instead of the metadata page URLs (e.g., <http://mydomain.com/publications/article1
>), you need to customize the URLs that the Nuxt Sitemap module includes.
The knowledge sources do not provide a direct, step-by-step example for this exact use case. However, they do indicate that for dynamic or custom URLs—especially when using Nuxt Content or when your sitemap needs to include URLs not directly mapped to your Nuxt routes—you should provide a custom source for the sitemap entries.
Specifically, the Nuxt Sitemap documentation (as referenced in a Stack Overflow answer) suggests that you need to supply your own list of URLs for dynamic or external resources. For Nuxt Content, there is also an integration guide for generating sitemaps from content data, but the knowledge sources do not include its details.
What you should do:
- Query your content collection (e.g., publications) to get the list of publication slugs or identifiers.
- Map these to the correct PDF URLs on your media subdomain.
- Provide this list to the sitemap module as custom entries.
While the exact code is not present in the sources, the general approach is:
Note: The above code is a conceptual example based on the guidance that you need to provide an API source for dynamic URLs in the sitemap. The actual implementation may vary depending on your Nuxt Content structure and the sitemap module version you use. For more details, refer to the dynamic URLs guide for Nuxt Sitemap as suggested in the Stack Overflow answer nuxt-sitemap does not find pre-rendered pages.
If you need to fetch data from a custom source (like an API or external files), Nuxt Content supports custom sources, which you can then use in your sitemap logic.
Summary:You must override the default sitemap URLs by providing your own list of PDF URLs, typically by querying your content and mapping to the correct subdomain. The knowledge sources do not provide a ready-made code snippet for this, but they confirm that this is the recommended approach for dynamic or external URLs. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@518773625537560576> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Writing a custom endpoint which is called from the nuxt config did the trick