Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sander van de Pas 74 posts 147 karma points
    Jun 14, 2018 @ 12:53
    Sander van de Pas
    0

    Get all urls from all languages in Vorto for sitemap.xml

    What is the best way to get all pages/url's from a Vorto website? I need to create a custom sitemap.xml.

    Anyone an idea or suggestion?

    Thanks in advance.

    Grtz Sander

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Jun 14, 2018 @ 14:34
    Nik
    100

    Hey Sander,

    In a recent project doing something similar I took the approach of having a custom controller for my XML site map.

    In the action I use this line to get all the domains for my root node (which has all the language elements)

    var domains = Services.DomainService.GetAssignedDomains(rootItem.Id, false).ToList();
    

    Then I call this recursive method:

    private void AddItemToList(ICollection<SitemapUrl> urlList, IPublishedContent item, IList<IDomain> domains)
        {
            if(item.IsVisible() && item.TemplateId != 0 && item.DocumentTypeAlias.Equals("xmlSitemap") == false)
            {
                urlList.Add(new SitemapUrl
                {
                    Url = item.UrlWithDomain().Trim('/'),
                    LastModified = item.UpdateDate.ToString("yyyy-MM-dd"),
                    Alternatives = domains?.Select(d => new SitemapUrlAlternative
                        {
                            Language = d.LanguageIsoCode,
                            Url = $"{Request.Url.Scheme}://{d.DomainName.TrimEnd('/')}{item.Url}".TrimEnd('/')
                        }).ToList()
                });
            }
    
            foreach(var child in item.Children())
            {
                AddItemToList(urlList, child, domains);
            }
        }
    

    This works pretty well if you ask me :-)

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft