/// <summary> /// Load Scriban templates and build HTML. /// </summary> /// <param name="layout">Header, footer and other layout fragments.</param> public HtmlBuilder Build(IDictionary <String, Document?> layout) { _logger.LogInformation($"Building {{h}} in {_project.PathTo(".").FullPathString()}/{{path}}...", "HTML", _outPath); var start = DateTime.Now; var inFile = _inPath.Combine("page.scriban-html").FullPath; var templateContext = new TemplateContext { TemplateLoader = new ScribanTemplateLoader(_inPath), MemberRenamer = _ => _.Name }; var json = new ScriptObject(); json.Import(typeof(Json), null, member => member.Name); var model = new ScriptObject { { "Project", this._project }, // { "HtmlConfigJson", JsonConvert.SerializeObject(config) }, { "Scripts", _jsBuilder.ScriptPaths }, { "Timestamp", DateTime.Now.Ticks }, { "Json", json }, { "MainMenu", layout["main_menu"] }, { "Footer", layout["footer"] }, }; templateContext.PushGlobal(model); var template = Template.Parse(File.ReadAllText(inFile)); var docs = this._project.Pages.Append( new Document { ProjectFilePath = "components/settings.md" } ); foreach (Document doc in docs) { var outFile = doc.ProjectFilePath.TrimSuffix(".md") + ".html"; Path outPath = _outPath.Combine(outFile); outPath.Parent().CreateDirectories(); this._logger.LogDebug("Rendering {page}...", outFile); model["ComponentName"] = doc.ProjectFilePath.StartsWith("components/") ? outFile.TrimPrefix("components/").TrimSuffix(".html") : ""; model["Document"] = doc; model["PathToRoot"] = "../".Repeat(doc.Depth).TrimSuffix("/"); var html = template.Render(templateContext); File.WriteAllText(outPath.ToString(), html); } var elapsed = (DateTime.Now - start).TotalSeconds; _logger.LogInformation( "{pages} HTML page(s), including layout files, built in {s:0.00} seconds.", this._project.Pages.Count + layout.Count, elapsed ); return(this); }
/// <inheritdoc cref="AssetBuilder"/> public void Build(params String[] folders) { folders.ForEach(folder => { _logger.LogInformation("Copying {s}...", folder); var builtinSource = Program.InPath.Combine(folder); builtinSource.AllFiles().ForEach(file => { var outFile = _outPath.Combine(folder).Combine(file.MakeRelativeTo(builtinSource).ToString()); _logger.LogDebug("Copying {source} to {target}...", file.FullPath, outFile.FullPath); outFile.Parent().CreateDirectories(); File.Copy(file.FullPath, outFile.FullPath, overwrite: true); }); }); }