private Manifest BuildCore(DocumentBuildParameters parameters)
        {
            using (new LoggerPhaseScope(PhaseName, LogLevel.Verbose))
            {
                Logger.LogInfo($"Max parallelism is {parameters.MaxParallelism}.");
                Directory.CreateDirectory(parameters.OutputBaseDir);

                var context = new DocumentBuildContext(parameters);

                // Start building document...
                List <HostService>  hostServices       = null;
                IHostServiceCreator hostServiceCreator = null;
                PhaseProcessor      phaseProcessor     = null;
                try
                {
                    using var templateProcessor = parameters.TemplateManager?.GetTemplateProcessor(context, parameters.MaxParallelism)
                                                  ?? new TemplateProcessor(new EmptyResourceReader(), context, 16);
                    using (new LoggerPhaseScope("Prepare", LogLevel.Verbose))
                    {
                        if (MarkdownService == null)
                        {
                            using (new LoggerPhaseScope("CreateMarkdownService", LogLevel.Verbose))
                            {
                                MarkdownService         = CreateMarkdownService(parameters, templateProcessor.Tokens.ToImmutableDictionary());
                                context.MarkdownService = MarkdownService;
                            }
                        }
                        Prepare(
                            parameters,
                            context,
                            templateProcessor,
                            (MarkdownService as IHasIncrementalContext)?.GetIncrementalContextHash(),
                            out hostServiceCreator,
                            out phaseProcessor);
                    }
                    using (new LoggerPhaseScope("Load", LogLevel.Verbose))
                    {
                        hostServices = GetInnerContexts(parameters, Processors, templateProcessor, hostServiceCreator);
                    }

                    BuildCore(phaseProcessor, hostServices, context);

                    var manifest = new Manifest(context.ManifestItems.Where(m => m.OutputFiles?.Count > 0))
                    {
                        Homepages       = GetHomepages(context),
                        XRefMap         = ExportXRefMap(parameters, context),
                        SourceBasePath  = StringExtension.ToNormalizedPath(EnvironmentContext.BaseDirectory),
                        IncrementalInfo = context.IncrementalBuildContext != null ? new List <IncrementalInfo> {
                            context.IncrementalBuildContext.IncrementalInfo
                        } : null,
                        VersionInfo = string.IsNullOrEmpty(context.VersionName) ?
                                      new Dictionary <string, VersionInfo>() :
                                      new Dictionary <string, VersionInfo>
                        {
                            {
                                context.VersionName,
                                new VersionInfo {
                                    VersionFolder = context.VersionFolder
                                }
                            }
                        }
                    };
                    manifest.Groups = new List <ManifestGroupInfo>
                    {
                        new ManifestGroupInfo(parameters.GroupInfo)
                        {
                            XRefmap = (string)manifest.XRefMap
                        }
                    };
                    return(manifest);
                }
                finally
                {
                    if (hostServices != null)
                    {
                        foreach (var item in hostServices)
                        {
                            Cleanup(item);
                            item.Dispose();
                        }
                    }
                }
            }
        }
Example #2
0
 public void Process(Manifest manifest, string outputFolder)
 {
     _postProcessorsHandler.Handle(_postProcessors, manifest, outputFolder);
 }
Example #3
0
 private static void SaveManifest(Manifest manifest)
 {
     JsonUtility.Serialize(Constants.ManifestFileName, manifest, Formatting.Indented);
     Logger.LogInfo($"Manifest file saved to {Constants.ManifestFileName}.");
 }
Example #4
0
        public Manifest Process(Manifest manifest, string outputFolder)
        {
            if (outputFolder == null)
            {
                throw new ArgumentNullException("Base directory can not be null");
            }
            var indexData         = new Dictionary <string, SearchIndexItem>();
            var indexDataFilePath = Path.Combine(outputFolder, IndexFileName);
            var htmlFiles         = (from item in manifest.Files ?? Enumerable.Empty <ManifestItem>()
                                     from output in item.OutputFiles
                                     where item.DocumentType != "Toc" && output.Key.Equals(".html", StringComparison.OrdinalIgnoreCase)
                                     select output.Value.RelativePath).ToList();

            if (htmlFiles.Count == 0)
            {
                return(manifest);
            }

            Logger.LogInfo($"Extracting index data from {htmlFiles.Count} html files");
            foreach (var relativePath in htmlFiles)
            {
                var filePath = Path.Combine(outputFolder, relativePath);
                var html     = new HtmlDocument();
                Logger.LogDiagnostic($"Extracting index data from {filePath}");

                if (EnvironmentContext.FileAbstractLayer.Exists(filePath))
                {
                    try
                    {
                        using (var stream = EnvironmentContext.FileAbstractLayer.OpenRead(filePath))
                        {
                            html.Load(stream, Encoding.UTF8);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogWarning($"Warning: Can't load content from {filePath}: {ex.Message}");
                        continue;
                    }
                    var indexItem = ExtractItem(html, relativePath);
                    if (indexItem != null)
                    {
                        indexData[relativePath] = indexItem;
                    }
                }
            }
            JsonUtility.Serialize(indexDataFilePath, indexData, Formatting.Indented);

            // add index.json to mainfest as resource file
            var manifestItem = new ManifestItem
            {
                DocumentType = "Resource",
            };

            manifestItem.OutputFiles.Add("resource", new OutputFileInfo
            {
                RelativePath = PathUtility.MakeRelativePath(outputFolder, indexDataFilePath),
            });

            manifest.Files?.Add(manifestItem);
            return(manifest);
        }