コード例 #1
0
ファイル: PageModel.cs プロジェクト: jf26028/ocam
 public PageModel()
 {
     // Provide non-null defaults for first pass.
     PageMap = new Dictionary<string, PageInfo>();
     Pages = new PageInfo[0];
     Posts = new PostInfo[0];
     Categories = new string[0];
     Tags = new string[0];
     CategoryPaths = new Dictionary<string, string>();
     TagPaths = new Dictionary<string, string>();
     CategoryPages = new Dictionary<string, List<PageInfo>>();
     TagPages = new Dictionary<string, List<PageInfo>>();
 }
コード例 #2
0
ファイル: SiteProcessor.cs プロジェクト: jf26028/ocam
        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);
            }
        }
コード例 #3
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);
            }
        }