Copied to clipboard

Flag this post as spam?

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


  • Christian Hansen 34 posts 204 karma points
    May 02, 2019 @ 12:13
    Christian Hansen
    0

    Sitemap only show when url is response code 200

    Hey, i have created a sitemap with help from: https://our.umbraco.com/documentation/Tutorials/Creating-an-XML-Site-Map/

    I ended up with this:

    How can i only show the urls that returns response code 200 ?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    @{Layout = null;

    string blacklistedDocumentTypeList = Model.Content.GetPropertyValue<string>("blacklistedDocumentTypes");
    string[] blackListedDocumentTypes = (!String.IsNullOrEmpty(blacklistedDocumentTypeList)) ? blacklistedDocumentTypeList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { };
    int maxSiteMapDepth = Model.Content.HasValue("maxSiteMapDepth") ? Model.Content.GetPropertyValue<int>("maxSiteMapDepth") : int.MaxValue;
    IPublishedContent siteHomePage = Model.Content.Parent;
    

    }

    @{ @helper RenderSiteMapUrlEntry(IPublishedContent node) { // with the relative priority, this is a per page setting, so we're not passing true var priority = node.GetPropertyValue

        if (String.IsNullOrEmpty(priority))
        {
            priority = "0.4";
        }
        <url>
            <loc>@EnsureUrlStartsWithDomain(node.UrlWithDomain())</loc>
            <lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod>
            <priority>@priority.Replace(",", ".")</priority>
        </url>
    }
    
    @helper RenderSiteMapUrlEntriesForChildren(IPublishedContent parentPage, int maxSiteMapDepth, string[] documentTypeBlacklist)
    {
        foreach (var page in parentPage.Children.Where(f => !documentTypeBlacklist.Contains(f.DocumentTypeAlias) && !f.GetPropertyValue<bool>("hideFromSiteMap")))
        {
            @RenderSiteMapUrlEntry(page)
            if (page.Level < maxSiteMapDepth && page.Children.Any(f => !documentTypeBlacklist.Contains(f.DocumentTypeAlias) && !f.GetPropertyValue<bool>("hideFromSiteMap")))
            {
                @RenderSiteMapUrlEntriesForChildren(page, maxSiteMapDepth, documentTypeBlacklist)
            }
        }
    }
    

    }

    @functions { private static string EnsureUrlStartsWithDomain(string url) { if (url.StartsWith("http")) { return url; } else { // whatever makes sense for your site here... var domainPrefix = string.Format("https://{0}/", HttpContext.Current.Request.ServerVariables["HTTP_HOST"]); return domainPrefix + url; } } }

Please Sign in or register to post replies

Write your reply to:

Draft