Exemplo n.º 1
0
        //generate the navbar after all the pages are added to the site.
        //the navbar is generated per page because the active item is different for each page.
        //can only handle navs with dropdowns one level deep.
        //TODO: Add active item highlight to dropdown pages?
        public void GenerateNav()
        {
            DataElement output = new DataElement("nav.html"); //create the unpopulated navbar

            foreach (NavItem i in ParentSite.NavItems)        //iterate through the navitems list populated when adding pages to the site
            {
                DataElement item;                             //the html element for a particular page or dropdown category
                if (TemplateElement.Id == i.title)
                {
                    item = new DataElement("navItemActive.html");
                }
                else if (i.children.Count > 0)                 //if the item has children, it is a dropdown category rather than a page.
                {
                    item = new DataElement("dropUp.html");
                    foreach (NavItem c in i.children)                     //populate the category with its pages
                    {
                        DataElement child = new DataElement("dropDownItem.html");
                        child.AppendToProperty("#TITLE#", new LiteralElement(c.title));
                        child.AppendToProperty("#HREF#", new LiteralElement(GenerateRelativeURL(c.LinkedPage)));
                        item.AppendToProperty("#CHILDREN#", child);
                    }
                }
                else
                {
                    item = new DataElement("navItem.html");
                }
                item.AppendToProperty("#TITLE#", new LiteralElement(i.title));
                item.AppendToProperty("#HREF#", new LiteralElement(GenerateRelativeURL(i.LinkedPage)));
                output.AppendToProperty("#CHILDREN#", item);               //append the item to the navbar
            }
            TemplateElement.AppendToProperty("#NAV#", output);             //bake the navbar DataElement into html to replace the #NAV# macro or property or whatever with.
        }
Exemplo n.º 2
0
        public Blog(Site site, string title, string contentPath = null, string subDirectory = null, string altTemplatePath = null) : base(site, title, contentPath, subDirectory, altTemplatePath)
        {
            blogPosts = new SortedSet <BlogPost>();
            ProcessBlogPosts(@"BlogPosts\", @"ProcessedBlogPosts\");

            LoadBlogPosts(@"ProcessedBlogPosts\", blogPosts);

            /*
             * foreach (BlogPost b in blogPosts)
             * {
             *      foreach(string s in b.Content)
             *      {
             *              AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<p>{0}</p>", s)));
             *      }
             *
             * }
             */

            //Populate blog with blogpost cards and their respective pages
            foreach (BlogPost b in blogPosts)
            {
                Page postPage = site.CreatePage(b.Title, null, null, "blog");
                postPage.ContentElement = GenerateBlogCard(b);
                postPage.ContentElement.AppendToProperty("#URL#", postPage.GenerateRelativeURL(postPage));

                DataElement blogCard = GenerateBlogCard(b, 5);
                blogCard.AppendToProperty("#URL#", postPage.GenerateURL());
                ContentElement.AppendToProperty("#POSTS#", blogCard);
            }
        }
Exemplo n.º 3
0
        //0 or negative number to have no limit
        private DataElement GenerateBlogCard(BlogPost p, int lineLimit = -1)
        {
            DataElement ret = new DataElement("blogPostCard.html");

            Regex isImage   = new Regex(@"^[a-z0-9\$\-_\.\+\!\*\'\(\)\,\\\/:]*\.(png|jpg|jpeg|gif)$", RegexOptions.IgnoreCase);
            Regex isElement = new Regex(@"^[ \t]*<.*", RegexOptions.IgnoreCase);

            ret.AppendToProperty("#TITLE#", p.Title);
            ret.AppendToProperty("#DATE#", p.Date.ToLongDateString());

            int curLines = 0;

            foreach (string s in p.Content)
            {
                if (s != null && s != "")
                {
                    if (isImage.IsMatch(s))
                    {
                        ret.AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<img src=\"{0}\" class=\"img-fluid\" alt=\"{1}\">\n", s, s)));
                    }
                    else if (isElement.IsMatch(s))
                    {
                        ret.AppendToProperty("#CONTENT#", new LiteralElement(s));
                    }
                    else
                    {
                        ret.AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<p>{0}</p>\n", s)));
                    }
                    curLines++;
                }
                if (lineLimit > 0 && curLines >= lineLimit)
                {
                    ret.AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<a href=\"{0}\"><font color=#FFFFFF>Continue reading</font></a>", "#URL#")));
                    break;
                }
            }

            return(ret);
        }