Esempio n. 1
0
 public PostInfo(PathInfo pathInfo)
 {
     Year = pathInfo.Year;
     Month = pathInfo.Month;
     Day = pathInfo.Day;
     PathDate = pathInfo.Date;
     Slug = pathInfo.Title;
 }
Esempio n. 2
0
        void ProcessFile(string src, string dst, string file, bool write, StartTemplate <StartModel> startTemplate, IPageProcessor processor)
        {
#if DEBUG
//            Console.Write(".");
#endif
            string srcfile = Path.Combine(src, file);
            string dstfile = null;
            Action <string, string> writer = null;
            if (write)
            {
                if (!_context.PageMap.ContainsKey(srcfile))
                {
                    // This file is unpublished.
                    return;
                }

                PageInfo pageInfo = _context.PageMap[srcfile];

                dstfile = pageInfo.GetDestinationPath(_context, src, dst, file);

                string dstdir = Path.GetDirectoryName(dstfile);
                Directory.CreateDirectory(dstdir);

                if (_context.Options.Verbose)
                {
                    Console.WriteLine(dstfile);
                }

                writer = (d, r) => {
                    // Write the output file if a destination is specified.
                    if (!String.IsNullOrWhiteSpace(d))
                    {
                        File.WriteAllText(d, r);
                    }
                };
            }

            PageTemplate <PageModel> pageTemplate = processor.ProcessFile(srcfile, dstfile, srcfile, _pageModel, startTemplate, writer);

            if (!write && pageTemplate.Published)
            {
                // Force the use of an empty layout to get the just the content.
                var contentStart = new StartTemplate <StartModel>()
                {
                    ForceLayout = true
                };

                string content = null;
                PageTemplate <PageModel> excerptTemplate = processor.ProcessFile(srcfile, null, srcfile + "*", _pageModel, contentStart, (d, r) =>
                {
                    content = r;
                });

                if (pageTemplate.Excerpt == null)
                {
                    pageTemplate.Excerpt = ExtractExcerpt(content);
                }

                // If this file is named like a post, get the info.
                PathInfo pathInfo = PathInfo.GetpathInfo(src, file);

                DateTime date = pageTemplate.Date.HasValue
                    ? pageTemplate.Date.Value
                    : (pathInfo == null
                        ? DateTime.MinValue
                        : pathInfo.Date);

                if (date == DateTime.MinValue)
                {
                    // Note: It's probably OK for pages not to have dates,
                    // since they won't often be listed by date.
                    // Console.WriteLine("Warning: No date specified for {0}.", srcfile);
                }

                PageInfo pageInfo;
                if (pathInfo != null)
                {
                    pageInfo = new PostInfo(pathInfo);
                }
                else
                {
                    pageInfo = new PageInfo();
                }

                pageInfo.Permalink  = pageTemplate.Permalink;
                pageInfo.Rebase     = pageTemplate.Rebase;
                pageInfo.Title      = pageTemplate.Title;
                pageInfo.Content    = content;
                pageInfo.Excerpt    = pageTemplate.Excerpt;
                pageInfo.Categories = pageTemplate.Categories;   // TODO: Copy
                pageInfo.Tags       = pageTemplate.Tags;         // TODO: Copy
                pageInfo.Date       = date;

                dstfile = pageInfo.GetDestinationPath(_context, src, dst, file);

                // Build a URL fragment for internal linking.
                pageInfo.Url = FileUtility.GetInternalUrl(_context, dstfile);

                AddCategories(pageInfo, pageTemplate.Categories);
                AddTags(pageInfo, pageTemplate.Tags);

                _context.PageMap.Add(srcfile, pageInfo);
            }
        }