Add project files.
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
using aeqw89.PersistentData;
|
||||
using aeqw89.DataKeys;
|
||||
using Beam.Dynamic;
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
using Beam.Temporary.Cli.Templates.Classic;
|
||||
using Beam.Exports;
|
||||
|
||||
namespace Beam.Temporary.Cli {
|
||||
internal class Program {
|
||||
|
||||
public static JsonSerializerOptions ConversionOptions { get; internal set; } = new();
|
||||
|
||||
public static SharedDataDictionary Shared { get; set; } = [];
|
||||
|
||||
public static IArchitecture Architecture = IArchitecture.Default;
|
||||
|
||||
const string SharedDataPath = "data/.dat";
|
||||
|
||||
static async Task Main(string[] args) {
|
||||
ConversionOptions.Converters.AddPersistentDataRequiredConverters();
|
||||
ConversionOptions.WriteIndented = true;
|
||||
|
||||
var web = new HtmlWeb();
|
||||
|
||||
var lf = LoggerFactory.Create((x) => {
|
||||
x.AddConsole();
|
||||
});
|
||||
|
||||
ILogger logger = lf
|
||||
.CreateLogger("Program");
|
||||
|
||||
await using var sharedContext = await DataDictionaryContext<SharedDataDictionary>.Create(
|
||||
SharedDataPath,
|
||||
DataKind.Shared,
|
||||
logger,
|
||||
ConversionOptions
|
||||
);
|
||||
|
||||
Shared = sharedContext.Data;
|
||||
|
||||
Shared.Clear();
|
||||
NovelStatics.Define_LightNovelWorld(Shared);
|
||||
NovelStatics.Define_LightNovelWorld_Novel_TheLegendaryMechanic(Shared);
|
||||
NovelStatics.Define_LightNovelWorl_Novel_IAloneLevelUp(Shared);
|
||||
ClassicTemplates.Register(Shared);
|
||||
|
||||
var novel = new DataKey<TextResource>("novels:i_alone_level_up");
|
||||
var context_aux = Architecture.GetMeta(web, novel, Shared);
|
||||
var metaDownloader = new DownloadEnumerable<IDocumentMetaData>(
|
||||
new SequentialFragmentDownloader<IDocumentMetaData>(
|
||||
context_aux,
|
||||
(c) => new UnitFragmentDownloader<IDocumentMetaData>(c.Web, c.AsyncTranformer, c.AsyncFailurePredicates, 4, logger),
|
||||
logger)
|
||||
.UnwrapFragmented());
|
||||
var metadata = (await metaDownloader.FirstAsync());
|
||||
|
||||
var context = Architecture.GetTextRecord(web, novel, Shared, metadata.Data);
|
||||
context.DownloadReporter = new Progress<IDocument>((x) => Console.WriteLine(x.Filename));
|
||||
var downloader = new DownloadEnumerable<IDocument>(
|
||||
new SequentialFragmentDownloader<IDocument>(
|
||||
context,
|
||||
(c) => new UnitFragmentDownloader<IDocument>(c.Web, c.AsyncTranformer, c.AsyncFailurePredicates, 4, logger),
|
||||
logger)
|
||||
.UnwrapFragmented());
|
||||
|
||||
List<Ordered<IDocument>> documents = [];
|
||||
|
||||
await foreach (var download in downloader.Take(20)) {
|
||||
if (!download.Data.MetaData.TryGetValue(Architecture.ChapterKey, out var meta))
|
||||
continue;
|
||||
if (meta is not ArticleData articleMetaData)
|
||||
continue;
|
||||
//Console.WriteLine($"Title: {data.Name}");
|
||||
//Console.WriteLine($"Description: {data.Description}");
|
||||
//Console.WriteLine($"Categories: {data.Categories.Aggregate((x, y) => $"{x}; {y}")}");
|
||||
//Console.WriteLine($"Authors: {data.Authors.Aggregate((x,y) => $"{x}; {y}")}");
|
||||
Console.WriteLine($"Chapter title: {articleMetaData.Name}");
|
||||
//Console.WriteLine($"Content: {download}");
|
||||
|
||||
documents.Add(download);
|
||||
}
|
||||
|
||||
string testDir = Path.Combine("txt", Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(testDir);
|
||||
|
||||
int len = documents.MaxBy((x) => x.Order)?.Order ?? -1;
|
||||
foreach (var document in documents.OrderBy((x) => x.Order)) {
|
||||
document.Data.MetaData.TryGetValue(Architecture.ChapterKey, out var chapterMetaData);
|
||||
Dictionary<string, string> linkButtons = new();
|
||||
if (document.Order != 0)
|
||||
linkButtons.Add("Previous", $"{document.Order - 1}.html");
|
||||
if (document.Order != len)
|
||||
linkButtons.Add("Next", $"{document.Order + 1}.html");
|
||||
new HtmlExporter(document.Data, chapterMetaData as ArticleData, linkButtons).Write(Path.Combine(testDir, $"{document.Order}.html"));
|
||||
}
|
||||
|
||||
Console.ReadKey();
|
||||
|
||||
//foreach (var download in documents.OrderBy((x) => x.Order)) {
|
||||
// if (download.Data.TryGetTaggedMetaData<ArticleData>(Architecture.ChapterKey, out var meta))
|
||||
// Console.WriteLine($"{download.Order}:{meta.Name}");
|
||||
//}
|
||||
|
||||
//string[] templates = new DataKey<File>[] {
|
||||
// HtmlBook.Keys.ContentPage,
|
||||
// HtmlBook.Keys.NoContentPage,
|
||||
// HtmlBook.Keys.TitlePage,
|
||||
// HtmlBook.Keys.StylesPage,
|
||||
//}.Select(
|
||||
// (x) => Shared.Files.ReadToString(x.WithNamespace("aeqw89:files:templates:classic"))
|
||||
//).ToArray();
|
||||
|
||||
//HtmlBook book = new(
|
||||
// bookname: Path.Combine(Path.GetRandomFileName(), "I Alone Level Up"),
|
||||
// new CssData(),
|
||||
// new ArticleData(),
|
||||
// new HtmlBookTemplates() {
|
||||
// ContentPageTemplate = templates[0],
|
||||
// NoContentTemplate = templates[1],
|
||||
// TitlePageTemplate = templates[2],
|
||||
// CssTemplate = templates[3],
|
||||
// },
|
||||
// documents: documents.Select((x) => x.Data).ToList()
|
||||
//);
|
||||
|
||||
//book.Update();
|
||||
//Console.WriteLine("One variable!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user