예제 #1
0
        protected virtual void AddFilteredContentElement(CurrentLanguageContent languageContentInfo, IList <XElement> xmlElements)
        {
            if (ContentFilter.ShouldExcludeContent(languageContentInfo, SiteSettings, SitemapData))
            {
                return;
            }

            var    content = languageContentInfo.Content;
            string url;

            var localizableContent = content as ILocalizable;

            if (localizableContent != null)
            {
                string language = string.IsNullOrWhiteSpace(this.SitemapData.Language)
                    ? languageContentInfo.CurrentLanguage.Name
                    : this.SitemapData.Language;

                url = this.UrlResolver.GetUrl(content.ContentLink, language);

                if (string.IsNullOrWhiteSpace(url))
                {
                    return;
                }

                // Make 100% sure we remove the language part in the URL if the sitemap host is mapped to the page's LanguageBranch.
                if (this.HostLanguageBranch != null && localizableContent.Language.Name.Equals(this.HostLanguageBranch, StringComparison.InvariantCultureIgnoreCase))
                {
                    url = url.Replace(string.Format("/{0}/", this.HostLanguageBranch), "/");
                }
            }
            else
            {
                url = this.UrlResolver.GetUrl(content.ContentLink);

                if (string.IsNullOrWhiteSpace(url))
                {
                    return;
                }
            }

            url = GetAbsoluteUrl(url);

            var fullContentUrl = new Uri(url);

            if (this.UrlSet.Contains(fullContentUrl.ToString()) || UrlFilter.IsUrlFiltered(fullContentUrl.AbsolutePath, this.SitemapData))
            {
                return;
            }

            XElement contentElement = this.GenerateSiteElement(content, fullContentUrl.ToString());

            if (contentElement == null)
            {
                return;
            }

            xmlElements.Add(contentElement);
            this.UrlSet.Add(fullContentUrl.ToString());
        }
        private void AddFilteredPageElement(PageData page, IList <XElement> xmlElements)
        {
            if (PageFilter.ShouldExcludePage(page))
            {
                return;
            }

            string url = this._urlResolver.GetUrl(page.ContentLink, page.LanguageBranch);

            // Make 100% sure we remove the language part in the URL if the sitemap host is mapped to the page's LanguageBranch.
            if (this._hostLanguageBranch != null && page.LanguageBranch.Equals(this._hostLanguageBranch, StringComparison.InvariantCultureIgnoreCase))
            {
                url = url.Replace(string.Format("/{0}/", this._hostLanguageBranch), "/");
            }

            Uri absoluteUri;

            // if the URL is relative we add the base site URL (protocol and hostname)
            if (!IsAbsoluteUrl(url, out absoluteUri))
            {
                url = UriSupport.Combine(this._sitemapData.SiteUrl, url);
            }
            // Force the SiteUrl
            else
            {
                url = UriSupport.Combine(this._sitemapData.SiteUrl, absoluteUri.AbsolutePath);
            }

            var fullPageUrl = new Uri(url);

            if (this._urlSet.Contains(fullPageUrl.ToString()) || UrlFilter.IsUrlFiltered(fullPageUrl.AbsolutePath, this._sitemapData))
            {
                return;
            }

            XElement pageElement = this.GenerateSiteElement(page, fullPageUrl.ToString());

            xmlElements.Add(pageElement);
            this._urlSet.Add(fullPageUrl.ToString());
        }