Exemple #1
0
        internal static string GetTitle(Dom.Document dom)
        {
            var TitleTag = DomService.GetTitleElement(dom);

            return(TitleTag != null ? TitleTag.InnerHtml : null);
        }
Exemple #2
0
        internal static List <SourceUpdate> GetUpdateWithDomHeader(HtmlHeader header, Document dom, string OnlyEnableCulture)
        {
            List <SourceUpdate> updates = new List <SourceUpdate>();

            string appendChanges = string.Empty;

            var titlevalue = GetOnlyOrDefault(header.Titles, OnlyEnableCulture);

            if (!string.IsNullOrEmpty(titlevalue))
            {
                var    titletag    = DomService.GetTitleElement(dom);
                string newtitletag = $"<Title>{titlevalue}</Title>\r\n";
                if (titletag == null)
                {
                    appendChanges += newtitletag;
                }
                else
                {
                    if (titletag.InnerHtml != titlevalue)
                    {
                        updates.Add(new SourceUpdate()
                        {
                            StartIndex = titletag.location.openTokenStartIndex, EndIndex = titletag.location.endTokenEndIndex, NewValue = newtitletag
                        });
                    }
                }
            }

            foreach (var item in header.Metas)
            {
                var checkresult = MetaCheck(item, OnlyEnableCulture);

                var sametags = GetSameMetaTags(dom, item);

                string metatag = GenerateMetaTag(item, checkresult.ContentValue);

                if (sametags != null && sametags.Count() > 0)
                {
                    var tag = sametags[0];
                    if (!IsSameMeta(tag, item, checkresult.ContentValue))
                    {
                        updates.Add(new SourceUpdate()
                        {
                            StartIndex = tag.location.openTokenStartIndex, EndIndex = tag.location.endTokenEndIndex, NewValue = metatag
                        });
                    }

                    if (sametags.Count() > 1)
                    {
                        int len = sametags.Count();
                        for (int i = 1; i < len; i++)
                        {
                            updates.Add(new SourceUpdate()
                            {
                                StartIndex = sametags[i].location.openTokenStartIndex, EndIndex = sametags[i].location.endTokenEndIndex, NewValue = null
                            });
                        }
                    }
                }
                else
                {
                    appendChanges += metatag;
                }
            }

            WriteStyleScript(header, dom, updates, ref appendChanges);

            if (!string.IsNullOrEmpty(appendChanges))
            {
                var afterheaderlocation = dom.head.location.openTokenEndIndex + 1;

                updates.Add(new SourceUpdate()
                {
                    StartIndex = afterheaderlocation, EndIndex = -1, NewValue = appendChanges
                });
            }
            return(updates);
        }