Пример #1
0
 /// <summary>
 /// Sets the title of the page. Uses the GetField method of the Page instructions interface
 /// to get  the value.
 /// </summary>
 protected virtual void SetTitle()
 {
     if (CurrentPageHead != null)
     {
         string title = PageAssemblyInstruction.GetField(PageAssemblyInstructionFields.HTML_Title);
         CurrentPageHead.Title = title.Replace("<i>", "").Replace("</i>", "");
     }
 }
Пример #2
0
        /// <summary>
        /// Adds the specified link rel item to the head of the page.
        /// </summary>
        /// <param name="htmlHead">The html head of the current page.</param>
        /// <param name="htmlLinkRelType">The type ofrel item to add.</param>
        private void addLinkRelItem(HtmlHead htmlHead, HtmlLinkRelType htmlLinkRelType)
        {
            List <HtmlLink> linkList = new List <HtmlLink>();

            if (htmlLinkRelType == HtmlLinkRelType.SchemaDcTerms)
            {
                HtmlLink hl = new HtmlLink();
                hl.Attributes.Add("rel", "schema.dcterms");
                hl.Href = "http://purl.org/dc/terms/";

                linkList.Add(hl);
            }
            else if (htmlLinkRelType == HtmlLinkRelType.Alternate)
            {
                // only add any alternate links if some translation exists
                if (PageAssemblyContext.Current.PageAssemblyInstruction.TranslationKeys.Length > 0)
                {
                    // retrieve the current language and hostname
                    string pageLang         = PageAssemblyContext.Current.PageAssemblyInstruction.GetField("Language");
                    bool   hasShortLangCode = pageLang.Length <= 2;
                    bool   foundPageLang    = false;

                    foreach (string key in PageAssemblyContext.Current.PageAssemblyInstruction.TranslationKeys)
                    {
                        // use the two-character code for this language if the page's language is also two characters
                        string translationLang = hasShortLangCode ? CultureInfo.GetCultureInfoByIetfLanguageTag(key).TwoLetterISOLanguageName : key;

                        // track if the page's language has been found
                        if (!foundPageLang && translationLang.Equals(pageLang, StringComparison.OrdinalIgnoreCase))
                        {
                            foundPageLang = true;
                        }

                        // retrieve the translation URL
                        NciUrl url = PageAssemblyContext.Current.PageAssemblyInstruction.GetTranslationUrl(key);

                        // build and add htmllink to list
                        HtmlLink hl = new HtmlLink();
                        hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + url.ToString();
                        hl.Attributes.Add("hreflang", translationLang);
                        hl.Attributes.Add("rel", "alternate");

                        linkList.Add(hl);
                    }

                    if (!foundPageLang)
                    {
                        // add the canonical url as the rel link for the page's language
                        string CanonicalUrl = PageAssemblyInstruction.GetUrl(PageAssemblyInstructionUrls.CanonicalUrl).ToString();
                        if (!string.IsNullOrEmpty(CanonicalUrl))
                        {
                            // build and add htmllink
                            HtmlLink hl = new HtmlLink();
                            hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + CanonicalUrl;
                            hl.Attributes.Add("hreflang", pageLang);
                            hl.Attributes.Add("rel", "alternate");

                            linkList.Add(hl);
                        }
                    }
                }
            }
            else if (htmlLinkRelType == HtmlLinkRelType.Next)
            {
                string nextUrl = PageAssemblyInstruction.GetUrl("RelNext").ToString();

                if (!String.IsNullOrEmpty(nextUrl))
                {
                    HtmlLink hl = new HtmlLink();
                    hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + nextUrl;
                    hl.Attributes.Add("rel", "next");

                    linkList.Add(hl);
                }
            }
            else if (htmlLinkRelType == HtmlLinkRelType.Prev)
            {
                string prevUrl = PageAssemblyInstruction.GetUrl("RelPrev").ToString();

                if (!String.IsNullOrEmpty(prevUrl))
                {
                    HtmlLink hl = new HtmlLink();
                    hl.Href = ContentDeliveryEngineConfig.CanonicalHostName.CanonicalUrlHostName.CanonicalHostName + prevUrl;
                    hl.Attributes.Add("rel", "prev");

                    linkList.Add(hl);
                }
            }

            foreach (HtmlLink hl in linkList)
            {
                htmlHead.Controls.Add(hl);
            }
        }