133 lines
5.5 KiB
C#
133 lines
5.5 KiB
C#
//using aeqw89.DataKeys;
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using System.Text;
|
|
//using System.Threading.Tasks;
|
|
|
|
//namespace Beam.Temporary.Cli {
|
|
// internal class HtmlBook : Document {
|
|
// public class Keys {
|
|
// public static DataKey<File> ContentPage => new DataKey<File>("content_page");
|
|
// public static DataKey<File> NoContentPage => new DataKey<File>("no_content_page");
|
|
// public static DataKey<File> TitlePage => new DataKey<File>("title_page");
|
|
// public static DataKey<File> StylesPage => new DataKey<File>("styles_page");
|
|
// }
|
|
|
|
// public List<Tracked<IDocument>> Documents { get; set; }
|
|
// public IReadOnlyList<string> Pages => _Pages;
|
|
// private List<string> _Pages { get; set; } = [];
|
|
|
|
// private const string EMTPY_PAGE = "EMPTY";
|
|
|
|
// public CssData CssData { get; }
|
|
// public ArticleData BookData { get; set; }
|
|
// public HtmlBookTemplates Templates { get; set; }
|
|
|
|
// public HtmlBook(string bookname, CssData cssData, ArticleData bookData, HtmlBookTemplates templates, List<IDocument>? documents = null, Encoding? encoding = null)
|
|
// : base(bookname, encoding) {
|
|
// Documents = [];
|
|
// CssData = cssData;
|
|
// BookData = bookData;
|
|
// Templates = templates;
|
|
// if (documents is not null)
|
|
// Documents = documents.Select((x) => new Tracked<IDocument>(x)).ToList();
|
|
// }
|
|
|
|
// public void Update(bool ignoreDirty = false) {
|
|
// if (!Directory.Exists(Filename))
|
|
// Directory.CreateDirectory(Filename);
|
|
|
|
// //System.IO.File.WriteAllLines(Path.Combine(Filename, "styles.css"), Format())
|
|
|
|
// List<string> newpages = [];
|
|
// if (Pages.Count < Documents.Count)
|
|
// _Pages.AddRange(Enumerable.Repeat(EMTPY_PAGE, Documents.Count - Pages.Count));
|
|
// foreach (var (doc, page) in Documents.Zip(Pages)) {
|
|
// if (!doc.IsDirty)
|
|
// newpages.Add(page);
|
|
// else if (doc.TrackedObject.MetaData.Count == 0)
|
|
// newpages.Add(PlainPage(doc.TrackedObject));
|
|
// else if (doc.TrackedObject.MetaData.TryGetValue(Program.Architecture.ChapterKey, out var meta) && meta is ArticleData articleData)
|
|
// newpages.Add(ArticlePage(doc.TrackedObject, articleData));
|
|
// else {
|
|
// Console.WriteLine("Unhandlable Metadata detected!");
|
|
// newpages.Add(PlainPage(doc.TrackedObject));
|
|
// }
|
|
|
|
// System.IO.File.WriteAllText(Path.Combine(Filename, Path.GetRandomFileName() + ".html"), newpages[^1]);
|
|
// doc.IsDirty = false;
|
|
// }
|
|
|
|
// _Pages = newpages;
|
|
// }
|
|
|
|
// public void UpdateCss() {
|
|
|
|
// }
|
|
|
|
// public void UpateTitle() {
|
|
|
|
// }
|
|
|
|
// private string Format(string template, Dictionary<string, string> table) {
|
|
// ArgumentNullException.ThrowIfNull(template);
|
|
// ArgumentNullException.ThrowIfNull(table);
|
|
|
|
// foreach (var kvp in table) {
|
|
// template = template.Replace(kvp.Key, kvp.Value);
|
|
// }
|
|
// return template;
|
|
// }
|
|
|
|
// private Dictionary<string, string> GetDocumentTable(IDocument doc, bool keepPlaceholders = false) {
|
|
// var table = new Dictionary<string, string>() {
|
|
// { "{" + nameof(doc.Filename) + "}", doc.Filename },
|
|
// { "{Content}", doc.ToString() }
|
|
// };
|
|
|
|
// return SolvePlaceholders(table, keepPlaceholders);
|
|
// }
|
|
|
|
// private Dictionary<string, string> GetArticleDataTable(IDocument doc, ArticleData ad, bool keepPlaceholders = false) {
|
|
// var table = new Dictionary<string, string>() {
|
|
// { "{" + nameof(ad.Language) + "}", ad.Language ?? "" },
|
|
// { "{" + nameof(ad.Authors) + "}", ad.Authors.Aggregate("; ")},
|
|
// { "{" + nameof(ad.Categories) + "}", ad.Categories.Aggregate("; ") },
|
|
// { "{" + nameof(ad.Version) + "}", ad.Version ?? "" },
|
|
// { "{" + nameof(ad.Description) + "}", ad.Description ?? "" },
|
|
// { "{" + nameof(ad.Name) + "}", ad.Name ?? "" },
|
|
// { "{" + nameof(doc.Filename) + "}", doc.Filename },
|
|
// { "{Content}", doc.ToString() }
|
|
// };
|
|
|
|
// return SolvePlaceholders(table, keepPlaceholders);
|
|
// }
|
|
|
|
// private Dictionary<string, string> SolvePlaceholders(Dictionary<string, string> table, bool keepPlaceholders) {
|
|
// if (keepPlaceholders)
|
|
// return table.Select(
|
|
// (x) => new KeyValuePair<string, string>(x.Key, x.Value == "" ? $"{x.Key}" : x.Value))
|
|
// .ToDictionary();
|
|
// return table;
|
|
// }
|
|
|
|
// private string PlainPage(IDocument doc, bool keepPlaceholders = false) {
|
|
// return Format(Templates.ContentPageTemplate, GetDocumentTable(doc, keepPlaceholders));
|
|
// }
|
|
|
|
// private string ArticlePage(IDocument doc, ArticleData data, bool keepPlaceholders = false) {
|
|
// return Format(Templates.ContentPageTemplate, GetArticleDataTable(doc, data, keepPlaceholders));
|
|
// }
|
|
|
|
// public override byte[] ToBytes() {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override string ToString() {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// }
|
|
//}
|