a7d148a96f
Added new Beam.Fluent and Beam.Models projects with staged download builder and data context models. Refactored and moved model classes from Beam.Temporary.Cli to Beam.Models. Added new data providers and extended DataBindings in Beam.Dynamic. Renamed Beam.Puppeteer to Beam.Playwright and updated related classes. Updated project references and package versions. Removed obsolete and unused files from Beam.Temporary.Cli.
47 lines
2.3 KiB
C#
47 lines
2.3 KiB
C#
using aeqw89.DataKeys;
|
|
using Beam.Dynamic;
|
|
using HtmlAgilityPack;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Beam.Temporary.Cli {
|
|
public static class CommonTransformers {
|
|
public static AsyncTransformer<HtmlDocument, ArticleData> ArticleDataTransformer(DataBindings? binding) => (x) => {
|
|
return Task.FromResult(new ArticleData() {
|
|
Authors = binding?.Authors?.Get(x)?.Select(OnlineCleaner.Clean)?.ToArray() ?? [],
|
|
Name = OnlineCleaner.Clean(binding?.Title?.Get(x) ?? ""),
|
|
Categories = binding?.Tags?.Get(x)?.Select(OnlineCleaner.Clean)?.ToArray() ?? [],
|
|
Description = OnlineCleaner.Clean(binding?.Description?.Get(x) ?? "")
|
|
});
|
|
};
|
|
|
|
public static AsyncTransformer<HtmlDocument, TableOfContentsData> TableOfContentsTransformer(DataBindings? binding) => (x) => {
|
|
return Task.FromResult(new TableOfContentsData() {
|
|
Authors = binding?.Authors?.Get(x)?.Select(OnlineCleaner.Clean)?.ToArray() ?? [],
|
|
Name = OnlineCleaner.Clean(binding?.Title?.Get(x) ?? ""),
|
|
Categories = binding?.Tags?.Get(x)?.Select(OnlineCleaner.Clean)?.ToArray() ?? [],
|
|
Description = OnlineCleaner.Clean(binding?.Description?.Get(x) ?? ""),
|
|
ContentLinks = binding?.TableOfContents?.Get(x) ?? [],
|
|
PagesLinks = binding?.PagesDropDown?.Get(x) ?? []
|
|
});
|
|
};
|
|
|
|
public static AsyncTransformer<HtmlDocument, StringDocument> DocumentTransformer(DataBindings? binding, IDocumentMetaData? metaData = null) => (x) => {
|
|
var resolved = binding?.Resolve(x);
|
|
var articleData = new ArticleData() {
|
|
Name = OnlineCleaner.Clean(resolved?.Title),
|
|
};
|
|
Dictionary<DataKey<IDocumentMetaData>, IDocumentMetaData> meta = [];
|
|
meta.Add(IArchitecture.Default.ChapterKey, articleData);
|
|
if (metaData is not null)
|
|
meta.Add(IArchitecture.Default.BookKey, metaData);
|
|
return Task.FromResult(new StringDocument(Path.GetRandomFileName(), OnlineCleaner.Clean(resolved?.Content)) {
|
|
MetaData = meta
|
|
});
|
|
};
|
|
}
|
|
}
|