Best way to approach Breadcrumbs and Sitemaps in XbyK

February 6, 2024 8:58 AM

Hi All,

We are building our first XbyK site and have some questions around the best approach to building Breadcrumbs and Sitemaps.

As the documentation recommends, we are using ContentItemQueryBuilder for out data retriva;, but it seems you have to be explicit with the Content type name.

In v13, we generally used the Page Retriever with the TreeNode class to get the generic information, then utilised it's parent etc.

Does anyone have an recommendations on a similar or recommended approach in XbyK?


Environment

Answers

February 6, 2024 9:49 AM

Yes, this is currently a limitation in the API, which I believe is being improved in this planned refresh update for March 2024. I understand it will let you query for pages a bit more generically, without having to specify the content type names.

Until then, to build a sitemap on my blog site I have done the retrieval like this...

        private async Task<List<SitemapNode>> GetSitemapNodesAsync()
        {
            // TODO: redo this when APIs are better
            var homePages = await GetHomePagesAsync();
            var blogListPages = await GetBlogListingPagesAsync();
            var innerPages = await GetInnerPagesAsync();
            var blogPostPages = await GetBlogPostPagesAsync();

            List<SitemapNode> sitemapNodes =
            [
                .. homePages,
                .. blogListPages,
                .. innerPages,
                .. blogPostPages,
            ];

            return sitemapNodes;
        }

Basically I'm doing a ContentItemQueryBuilder query per content type and returning a generic SitemapNode class that will be used in the rendering of the sitemap.

This isn't an ideal approach, but something I'm happy to do until the API is ready. Hope this helps!


February 6, 2024 10:45 PM

Hey @Sean!

@liamgold is right - we'll be improving things related to your use case with that Refresh by adding more APIs for content querying.

Here are some example improvements that should be coming with that Refresh

  • Query for web page items without needing to specify a website channel
  • Query for content items by specifying multiple content types
  • Query for content items without specifying any content type
  • Query for content items by their reusable field schema
  • Query for content items without including the "content type" fields (the custom fields)

@liamgold's approach is basically the same thing we do here on the Community Portal

And you can see what that code generates by looking at the sitemap.xml.


To answer this question, you have to login first.