Esempio n. 1
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            if (Content == null)
            {
                throw new DependencyException(nameof(Content));
            }

            if (Template == null)
            {
                throw new DependencyException(nameof(Template));
            }

            log.Info("Generating Index file...");
            var    input  = settings.SourceDirectory.Combine(settings.Configuration.Index);
            FsPath?target = settings.OutputDirectory.Combine("index.html");

            using (var pipeline = new BookGenPipeline(BookGenPipeline.Web))
            {
                pipeline.InjectRuntimeConfig(settings);

                Content.Content = pipeline.RenderMarkdown(input.ReadFile(log));
            }

            var html = Template.Render();

            target.WriteFile(log, html);
        }
Esempio n. 2
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            if (Content == null)
            {
                throw new DependencyException(nameof(Content));
            }

            if (Template == null)
            {
                throw new DependencyException(nameof(Template));
            }

            log.Info("Generating Sub Markdown Files...");

            using var pipeline = new BookGenPipeline(BookGenPipeline.Web);
            pipeline.InjectRuntimeConfig(settings);

            var bag = new ConcurrentBag <(string source, FsPath target, string title, string content)>();

            Parallel.ForEach(settings.TocContents.Files, file =>
            {
                (string source, FsPath target, string title, string content)result;

                var input     = settings.SourceDirectory.Combine(file);
                result.target = settings.OutputDirectory.Combine(Path.ChangeExtension(file, ".html"));

                log.Detail("Processing file: {0}", input);

                var inputContent = input.ReadFile(log);

                result.title = MarkdownUtils.GetTitle(inputContent);

                if (string.IsNullOrEmpty(result.title))
                {
                    log.Warning("No title found in document: {0}", file);
                    result.title = file;
                }

                result.source  = file;
                result.content = pipeline.RenderMarkdown(inputContent);

                bag.Add(result);
            });

            log.Info("Writing files to disk...");
            foreach (var item in bag)
            {
                Content.Title    = item.title;
                Content.Metadata = settings.MetataCache[item.source];
                Content.Content  = item.content;
                item.target.WriteFile(log, Template.Render());
            }
        }
Esempio n. 3
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            if (Content == null)
            {
                throw new DependencyException(nameof(Content));
            }

            if (Template == null)
            {
                throw new DependencyException(nameof(Template));
            }

            log.Info("Generating Printable html...");
            FsPath?target = settings.OutputDirectory.Combine("print.html");

            StringBuilder buffer = new StringBuilder();

            using var pipeline = new BookGenPipeline(BookGenPipeline.Print);
            pipeline.InjectRuntimeConfig(settings);

            foreach (var chapter in settings.TocContents.Chapters)
            {
                log.Info("Processing: {0}...", chapter);
                buffer.AppendFormat("<h1>{0}</h1>\r\n\r\n", chapter);
                foreach (var file in settings.TocContents.GetLinksForChapter(chapter).Select(l => l.Url))
                {
                    log.Detail("Processing file for print output: {0}", file);
                    var input = settings.SourceDirectory.Combine(file);

                    var inputContent = input.ReadFile(log);

                    var rendered = pipeline.RenderMarkdown(inputContent);

                    buffer.AppendLine(rendered);
                    buffer.AppendLine(NewPage);
                }
            }

            Content.Content = buffer.ToString();

            target.WriteFile(log, Template.Render());
        }
Esempio n. 4
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            if (Content == null)
            {
                throw new DependencyException(nameof(Content));
            }

            if (Template == null)
            {
                throw new DependencyException(nameof(Template));
            }

            log.Info("Generating index files for sub content folders...");

            using var pipeline = new BookGenPipeline(BookGenPipeline.Web);
            pipeline.InjectRuntimeConfig(settings);

            foreach (var file in settings.TocContents.Files)
            {
                var dir = Path.GetDirectoryName(file);

                if (dir == null)
                {
                    continue;
                }

                FsPath?target = settings.OutputDirectory.Combine(dir).Combine("index.html");
                if (!target.IsExisting)
                {
                    var mdcontent = CreateContentLinks(settings, dir);

                    Content.Title    = dir;
                    Content.Content  = pipeline.RenderMarkdown(mdcontent);
                    Content.Metadata = "";
                    var html = Template.Render();

                    log.Detail("Creating file: {0}", target);
                    target.WriteFile(log, html);
                }
            }
        }
Esempio n. 5
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            if (Content == null)
            {
                throw new DependencyException(nameof(Content));
            }

            if (Template == null)
            {
                throw new DependencyException(nameof(Template));
            }

            log.Info("Generating epub pages...");

            int index = 1;

            using var pipeline = new BookGenPipeline(BookGenPipeline.Epub);
            pipeline.InjectRuntimeConfig(settings);

            foreach (var file in settings.TocContents.Files)
            {
                _session.GeneratedFiles.Add($"page_{index:D3}");

                FsPath?target = settings.OutputDirectory.Combine($"epubtemp\\OPS\\page_{index:D3}.xhtml");


                log.Detail("Processing file for epub output: {0}", file);
                var input = settings.SourceDirectory.Combine(file);

                var inputContent = input.ReadFile(log);

                Content.Title   = MarkdownUtils.GetTitle(inputContent);
                Content.Content = pipeline.RenderMarkdown(inputContent);

                var html = XhtmlNormalizer.NormalizeToXHTML(Template.Render());

                target.WriteFile(log, html);
                ++index;
            }
        }
Esempio n. 6
0
        public void RunStep(RuntimeSettings settings, ILog log)
        {
            if (Content == null)
            {
                throw new DependencyException(nameof(Content));
            }

            if (Template == null)
            {
                throw new DependencyException(nameof(Template));
            }

            log.Info("Generating Wordpress export content...");
            _session.CurrentChannel.Item = new List <Item>();

            var host = settings.CurrentBuildConfig.TemplateOptions[TemplateOptions.WordpressTargetHost];

            bool parentpageCreate = settings.CurrentBuildConfig.TemplateOptions.TryGetOption(TemplateOptions.WordpressCreateParent, out bool createparent) && createparent;
            bool createfillers    = settings.CurrentBuildConfig.TemplateOptions.TryGetOption(TemplateOptions.WordpressCreateFillerPages, out bool filler) && filler;

            int mainorder    = 0;
            int uid          = 2000;
            int globalparent = 0;

            if (parentpageCreate)
            {
                string fillerPage = createfillers ? CreateFillerPage(settings.TocContents.GetLinksForChapter()) : "";
                string title      = settings.CurrentBuildConfig.TemplateOptions[TemplateOptions.WordpresCreateParentTitle];
                string path       = $"{host}{Encode(title)}";
                Item   parent     = CreateItem(uid, 0, mainorder, fillerPage, title, path, settings.CurrentBuildConfig.TemplateOptions);
                _session.CurrentChannel.Item.Add(parent);
                globalparent = uid;
                ++uid;
            }

            using var pipeline = new BookGenPipeline(BookGenPipeline.Wordpress);
            pipeline.InjectRuntimeConfig(settings);

            foreach (var chapter in settings.TocContents.Chapters)
            {
                string fillerPage = createfillers ? CreateFillerPage(settings.TocContents.GetLinksForChapter(chapter)) : "";
                string path       = $"{host}{Encode(chapter)}";
                int    parent_uid = uid;

                Item parent = CreateItem(uid, globalparent, mainorder, fillerPage, chapter, path, settings.CurrentBuildConfig.TemplateOptions);
                _session.CurrentChannel.Item.Add(parent);
                int suborder = 0;
                uid++;

                foreach (var file in settings.TocContents.GetLinksForChapter(chapter).Select(l => l.Url))
                {
                    log.Detail("Processing {0}...", file);
                    var input = settings.SourceDirectory.Combine(file);
                    var raw   = input.ReadFile(log);
                    Content.Content = pipeline.RenderMarkdown(raw);

                    var title = MarkdownUtils.GetTitle(raw);

                    string subpath = $"{host}{Encode(chapter)}/{Encode(title)}";
                    var    result  = CreateItem(uid, parent_uid, suborder, Template.Render(), title, subpath, settings.CurrentBuildConfig.TemplateOptions);

                    _session.CurrentChannel.Item.Add(result);
                    ++suborder;
                    ++uid;
                }
                ++mainorder;
            }
        }