Пример #1
0
        private string RenderHeaderMetaItem(HeaderRenderItem item, List <HeaderBindings> bindings, RenderContext context)
        {
            if (bindings == null || bindings.Count() == 0)
            {
                return(item.OriginalHtml);
            }

            HeaderBindings finditem = null;

            if (!string.IsNullOrEmpty(item.MetaName))
            {
                finditem = bindings.Find(o => Lib.Helper.StringHelper.IsSameValue(item.MetaName, o.MetaName));
            }
            else if (!string.IsNullOrEmpty(item.HttpEquive))
            {
                finditem = bindings.Find(o => Lib.Helper.StringHelper.IsSameValue(item.HttpEquive, o.HttpEquiv));
            }
            else if (!string.IsNullOrEmpty(item.CharSet))
            {
                finditem = bindings.Find(o => !string.IsNullOrEmpty(o.CharSet));
            }

            if (finditem != null)
            {
                bindings.Remove(finditem);
                return(RenderBindingItem(finditem, context));
            }
            else
            {
                return(item.OriginalHtml);
            }
        }
Пример #2
0
        private string RenderTitle(HeaderRenderItem item, string newContent = null)
        {
            if (item == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(newContent))
            {
                return(item.OriginalHtml);
            }

            string att = string.Empty;

            foreach (var oneatt in item.Attributes)
            {
                att += " " + oneatt.Key + "=\"" + oneatt.Value + "\"";
            }

            return("<Title" + att + ">" + newContent + "</Title>");
        }
Пример #3
0
        public List <HeaderRenderItem> ProcessItems(Element head)
        {
            List <HeaderRenderItem> result = new List <HeaderRenderItem>();

            foreach (var item in head.childNodes.item)
            {
                if (item.nodeType == enumNodeType.ELEMENT)
                {
                    var element = item as Element;

                    if (element.tagName.ToLower() == "title")
                    {
                        HeaderRenderItem headerItem = new HeaderRenderItem();
                        headerItem.OriginalHtml = element.OuterHtml;
                        headerItem.isTitle      = true;
                        headerItem.Content      = element.InnerHtml;
                        foreach (var att in element.attributes)
                        {
                            headerItem.Attributes[att.name] = att.value;
                        }
                        result.Add(headerItem);
                    }

                    else if (element.tagName.ToLower() == "meta")
                    {
                        HeaderRenderItem headerItem = new HeaderRenderItem();
                        headerItem.OriginalHtml = element.OuterHtml;

                        headerItem.MetaName   = element.getAttribute("name");
                        headerItem.HttpEquive = element.getAttribute("http-equiv");
                        headerItem.CharSet    = element.getAttribute("charset");
                        headerItem.Content    = element.getAttribute("content");

                        headerItem.IsMeta = true;

                        foreach (var att in element.attributes)
                        {
                            headerItem.Attributes[att.name] = att.value;
                        }
                        result.Add(headerItem);
                    }
                    else if (element.tagName == "script" || element.tagName == "link")
                    {
                        // get the render task.
                        //var plan = Kooboo.Sites.Render.RenderEvaluator.Evaluate(element.OuterHtml, new EvaluatorOption());
                        //if (plan != null)
                        //{
                        HeaderRenderItem headeritem = new HeaderRenderItem();
                        headeritem.IsRenderTask = true;
                        headeritem.OriginalHtml = element.OuterHtml;
                        // headeritem.renderTasks = plan;
                        result.Add(headeritem);
                        //}
                        //else
                        //{
                        //    HeaderRenderItem headeritem = new HeaderRenderItem();
                        //    headeritem.OriginalHtml = element.OuterHtml;
                        //    headeritem.NoRender = true;
                        //    result.Add(headeritem);
                        //}
                    }
                    else
                    {
                        HeaderRenderItem headeritem = new HeaderRenderItem();
                        headeritem.OriginalHtml = element.OuterHtml;
                        headeritem.NoRender     = true;
                        result.Add(headeritem);
                    }
                }

                else if (item.nodeType == enumNodeType.TEXT)
                {
                    var textndoe = item as Kooboo.Dom.Text;

                    HeaderRenderItem headeritem = new HeaderRenderItem();
                    headeritem.OriginalHtml = textndoe.data;
                    headeritem.NoRender     = true;
                    result.Add(headeritem);
                }
            }
            return(result);
        }
Пример #4
0
        public List <HeaderRenderItem> ProcessItems(Element head)
        {
            List <HeaderRenderItem> result = new List <HeaderRenderItem>();

            foreach (var item in head.childNodes.item)
            {
                if (item.nodeType == enumNodeType.ELEMENT)
                {
                    var element = item as Element;

                    if (element.tagName.ToLower() == "title")
                    {
                        HeaderRenderItem headerItem = new HeaderRenderItem();
                        headerItem.OriginalHtml = element.OuterHtml;
                        headerItem.isTitle      = true;
                        headerItem.Content      = element.InnerHtml;
                        foreach (var att in element.attributes)
                        {
                            headerItem.Attributes[att.name] = att.value;
                        }
                        result.Add(headerItem);
                    }

                    else if (element.tagName.ToLower() == "meta")
                    {
                        HeaderRenderItem headerItem = new HeaderRenderItem();
                        headerItem.OriginalHtml = element.OuterHtml;

                        headerItem.MetaName   = element.getAttribute("name");
                        headerItem.HttpEquive = element.getAttribute("http-equiv");
                        headerItem.CharSet    = element.getAttribute("charset");
                        headerItem.Content    = element.getAttribute("content");

                        headerItem.IsMeta = true;

                        foreach (var att in element.attributes)
                        {
                            headerItem.Attributes[att.name] = att.value;
                        }
                        result.Add(headerItem);
                    }
                    else
                    {
                        HeaderRenderItem headeritem = new HeaderRenderItem();
                        headeritem.OriginalHtml = element.OuterHtml;
                        headeritem.NoRender     = true;
                        result.Add(headeritem);
                    }
                }

                else if (item.nodeType == enumNodeType.TEXT)
                {
                    var textndoe = item as Kooboo.Dom.Text;

                    HeaderRenderItem headeritem = new HeaderRenderItem();
                    headeritem.OriginalHtml = textndoe.data;
                    headeritem.NoRender     = true;
                    result.Add(headeritem);
                }
            }
            return(result);
        }