예제 #1
0
        private MetaContent BuildMetaContent(string file)
        {
            MetaContent metaContent;
            var content = File.ReadAllText(file);
            var isPage = file.Contains(Paths.PagesPath);

            Trace.TraceInformation("Reading file {0}", file);
            if (isPage)
            {
                var parsed = pageParser.ParsePage(content);
                metaContent = new MetaContent(file) { Page = parsed };
                metaContent.Page.Url = metaContent.GetTargetFileName(Paths).Replace(Paths.OutputPath, "").Replace('\\', '/');
            }
            else
            {
                var parsed = pageParser.ParsePost(content);
                metaContent = new MetaContent(file) { Post = parsed };
                metaContent.Post.Url = metaContent.GetTargetFileName(Paths).Replace(Paths.OutputPath, "").Replace('\\', '/');
            }
            return metaContent;
        }
예제 #2
0
        public static string GetTargetFileName(this MetaContent content, SitePaths paths)
        {
            var isPage = content.Page != null;

            string targetDirectory;

            if (isPage)
            {
                targetDirectory = Path.GetDirectoryName(content.FileName.Replace(paths.PagesPath, paths.OutputPath));
            }
            else
            {
                targetDirectory =
                    Path.GetDirectoryName(content.FileName.Replace(paths.PostsPath,
                                                                   Path.Combine(paths.OutputPath, SitePaths.PostsDirectoryName)));
            }
            var targetFileName = Path.GetFileNameWithoutExtension(content.FileName) + ".html";

            var targetPath = Path.Combine(targetDirectory, targetFileName);

            return(targetPath);
        }
예제 #3
0
        private void Export(MetaContent metaContent, dynamic metadata)
        {
            var targetPath = metaContent.GetTargetFileName(Paths);

            if (!metaContent.HasValidTemplate())
            {
                Trace.TraceWarning("No template given for file {0}", metaContent.FileName);
                return;
            }

            FileSystem.EnsureDirectory(targetPath);

            var result = internalTemplater.Transform (Paths.TemplatePath, metaContent.GetTemplate(), metadata);

            File.WriteAllText (targetPath, result);
        }