Example #1
0
        public void buildPage(String relativeFile)
        {
            relativeFile = relativeFile.TrimStartingPathChars();

            var outFile = Path.Combine(this.outDir, relativeFile);

            if (OutputExtension != null)
            {
                outFile = Path.ChangeExtension(outFile, OutputExtension);
            }

            ITargetFileInfo     fileInfo    = fileInfoProvider.GetFileInfo(relativeFile, null);
            TemplateEnvironment environment = new TemplateEnvironment(fileInfo.FileNoExtension, fileFinder, overrideValuesProvider.OverrideVars, version, true);
            PageStack           pageStack   = new PageStack(environment, fileFinder);

            pageStack.ContentFile = fileInfo.HtmlFile;
            if (pageStack.Visible)
            {
                var pageSettings = fileFinder.GetProjectPageDefinition(fileInfo);
                var layout       = pageSettings.Layout;
                if (OutputExtension != null)
                {
                    layout = Path.ChangeExtension(layout, OutputExtension);
                }
                pageStack.pushLayout(layout);

                var pathBase = environment.PathBase;

                HtmlDocumentRenderer dr = new HtmlDocumentRenderer(environment);
                dr.addTransform(new HashTreeMenus(fileFinder));
                dr.addTransform(new ExpandRootedPaths(pathBase));
                if (!String.IsNullOrEmpty(pathBase))
                {
                    //Safe to fix relative urls last since it wont replace any that already start with the path base.
                    dr.addTransform(new FixRelativeUrls(pathBase));
                }
                var document = dr.getDocument(pageStack.Pages);
                var outDir   = Path.GetDirectoryName(outFile);
                if (!Directory.Exists(outDir))
                {
                    Directory.CreateDirectory(outDir);
                }
                using (var writer = new StreamWriter(File.Open(outFile, FileMode.Create, FileAccess.Write, FileShare.None)))
                {
                    writer.Write(document.DocumentNode.OuterHtml);
                }
                fileFinder.CopyLinkedFiles(this.outDir, pageStack);
            }
        }
Example #2
0
        private IActionResult getConvertedDocument(PageStack pageStack, HtmlDocumentRenderer dr)
        {
            var document = dr.getDocument(pageStack.Pages);

            return(Content(document.DocumentNode.OuterHtml, new MediaTypeHeaderValue("text/html")));
        }