Пример #1
0
 public Html Generate(Site site, Post post)
 {
     var t = new TemplateInstance(this);
     t.LastModified = post.LastModified;
     t["title"] = post.Title;
     t["author"] = post.Author;
     t["url"] = site.URL + post.Path;
     t["updated"] = post.LastModified.ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss\\Z");
     t["excerpt"] = Generator.Markdown.Transform(post.ExcerptMarkdown).Trim();
     t["content"] = Generator.Markdown.Transform(post.Content).Trim();
     return t.ToHtml();
 }
Пример #2
0
 public Html Generate(Site site, Post post)
 {
     var t = new TemplateInstance(this);
     t.LastModified = post.LastModified;
     t["title"] = post.Title;
     t["gmdate"] = post.Date.ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss\\Z");
     t["longdate"] = post.Date.ToString("ddd dd MMM yyyy");
     t["monthyear"] = post.Date.ToString("MMM yyyy");
     t["updated"] = post.LastModified.ToString("ddd dd MMM yyyy");
     t["url"] = site.UrlPath + post.Path;
     t["excerpt"] = Html.Raw(Generator.Markdown.Transform(post.ExcerptMarkdown));
     t["title"] = post.Title;
     return t.ToHtml();
 }
Пример #3
0
 public void Add(Post p)
 {
     Posts.Add(p);
 }
Пример #4
0
        static void LoadData(Site site)
        {
            //Scan for pages
            string[] pageFiles = Directory.GetFiles(site.DataPath, "*.page", SearchOption.AllDirectories);
            foreach (string pageFile in pageFiles)
            {
                Page p = new Page(site.DataPath, pageFile);
                //Ignore news pages
                if (p.HasDate)
                    continue;

                site.Add(p);
                //Console.WriteLine("Page: " + p);
            }
            site.Pages.Sort(Page.ComparerIndex);

            //Scan for posts
            string[] postFiles = Directory.GetFiles(site.DataPath, "*.post", SearchOption.AllDirectories);
            foreach (string postFile in postFiles)
            {
                Post p = new Post(postFile);
                //Ignore non news pages
                if (p.Date == DateTime.MinValue)
                    continue;

                site.Add(p);
                //Console.WriteLine("News: " + p);
            }
            site.Posts.Sort(Post.ComparerLatestFirst);
        }
Пример #5
0
 static Html GenerateTabs(Site site, Page page, Post post)
 {
     //Find out if we have an index page
     Page indexPage = null;
     foreach (Page p in site.Pages)
     {
         if (p.Name == "index")
         {
             indexPage = p;
             break;
         }
     }
     Html tabs = new Html();
     if (indexPage == null)
         tabs += LiTag(site.UrlPath, "", "News", page == null && post == null, DateTime.MinValue);
     else
         tabs += LiTag(site.UrlPath, indexPage.Title, indexPage.LinkTitle, page == indexPage, indexPage.LastModified);
     foreach (Page p in site.Pages)
     {
         if (p.LinkTitle == "")
             continue;
         if (p == indexPage)
             continue;
         tabs += LiTag(p.LinkUrl ?? site.UrlPath + p.Path, p.Title, p.LinkTitle, p == page, p.LastModified);
     }
     return tabs;
 }
Пример #6
0
        static void GeneratePost(Site site, Post p, PostTemplate postTemplate, IndexTemplate indexTemplate)
        {
            string dirPath = Path.Combine(site.WebPath, p.Path);
            string htmlPath = Path.Combine(dirPath, "index.html");
            Directory.CreateDirectory(dirPath);
            if (Directory.Exists(p.SourceDir))
                FileManager.Clone(p.SourceDir, dirPath);

            var inst = indexTemplate.Create(site);
            inst["title"] = p.Title;
            inst["tabs"] = GenerateTabs(site, null, p);
            inst["contents"] = postTemplate.Generate(site, p);
            inst.Write(htmlPath);
        }
Пример #7
0
 public static int ComparerLatestFirst(Post a, Post b)
 {
     return -a.Date.CompareTo(b.Date);
 }