ローカルのdocker用設定など
This commit is contained in:
1 parent
4a93843d3f
commit
b01665423e
10 files changed
+566
-131
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using AngleSharp.Html.Parser;
|
||||
using AngleSharp.Html.Parser;
|
||||
using System.ServiceModel.Syndication;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -24,8 +24,8 @@ internal class momonga_magazine
|
||||
var results = await Task.WhenAll(tasks);
|
||||
var allItems = results.SelectMany(items => items).ToList();
|
||||
|
||||
// 簡潔なRSSに整形
|
||||
var simplifiedItems = allItems.OrderByDescending(x => x.PublishDate).Select(originalItem =>
|
||||
// 簡潔なRSSに非同期で整形
|
||||
var itemTasks = allItems.OrderByDescending(x => x.PublishDate).Select(async originalItem =>
|
||||
{
|
||||
List<SyndicationCategory> getAddCategory()
|
||||
{
|
||||
@@ -48,38 +48,26 @@ internal class momonga_magazine
|
||||
// ----------------------------------------------------
|
||||
// 正規表現で各項目の値を抽出する
|
||||
// ----------------------------------------------------
|
||||
// パターン解説:
|
||||
// 【[^】]+】 : 「【」で始まり、「】以外の文字」が続き、「】」で終わる文字列 (例: 【パロディ】)
|
||||
// ([^【]*) : その後、「【」以外の文字が続く限り取得する (Group1としてキャプチャ)
|
||||
string pattern = @"【[^】]+】([^【]*)";
|
||||
var matches = Regex.Matches(targetText, pattern);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
// match.Groups[1].Value には "パロ1, パロ 2 " などの値が入ります
|
||||
// (項目の中身が空の場合は空文字になります)
|
||||
string valuesStr = match.Groups[1].Value;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(valuesStr))
|
||||
{
|
||||
continue; // 中身が空の場合はスキップ
|
||||
continue;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// 3. カンマで分割し、前後の空白を除去してカテゴリに追加
|
||||
// ----------------------------------------------------
|
||||
// ※もし全角カンマ「、」も考慮したい場合は new[] { ',', '、' } と記述します
|
||||
string[] splitValues = valuesStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var val in splitValues)
|
||||
{
|
||||
// 前後の半角・全角スペースを取り除く
|
||||
string categoryName = val.Trim();
|
||||
|
||||
// 空でなければカテゴリとして追加
|
||||
if (!string.IsNullOrEmpty(categoryName))
|
||||
{
|
||||
// domain属性なし(前回回答の手法)でカテゴリを追加
|
||||
result.Add(new SyndicationCategory(categoryName));
|
||||
}
|
||||
}
|
||||
@@ -90,15 +78,9 @@ internal class momonga_magazine
|
||||
|
||||
var newItem = new SyndicationItem()
|
||||
{
|
||||
// タイトルは TextSyndicationContent でラップする必要があります
|
||||
Title = new TextSyndicationContent(originalItem.Title?.Text ?? "No Title")
|
||||
, Id = CmnUtil.CreateGuid(originalItem.Id)
|
||||
, PublishDate = originalItem.PublishDate
|
||||
, LastUpdatedTime = originalItem.LastUpdatedTime
|
||||
|
||||
// 元のコンテンツをそのまま引き継ぐ
|
||||
// , Content = originalItem.Content
|
||||
// , Summary = originalItem.Summary
|
||||
Title = new TextSyndicationContent(originalItem.Title?.Text ?? "No Title"),
|
||||
PublishDate = originalItem.PublishDate,
|
||||
LastUpdatedTime = originalItem.LastUpdatedTime
|
||||
};
|
||||
|
||||
// リンクを引き継ぐ
|
||||
@@ -123,14 +105,15 @@ internal class momonga_magazine
|
||||
newItem.Authors.Add(author);
|
||||
}
|
||||
|
||||
// ID
|
||||
newItem.Id = CmnUtil.CreateGuid($"{link}");
|
||||
|
||||
var body = new StringBuilder();
|
||||
var originalSummary = originalItem.Summary.Text;
|
||||
body.Append(originalSummary);
|
||||
if (link != null)
|
||||
{
|
||||
var task = CmnUtil.GetDocument(client, link.ToString());
|
||||
task.Wait();
|
||||
var docContents = task.Result;
|
||||
var docContents = await CmnUtil.GetDocument(client, link.ToString());
|
||||
var imgElements = docContents.QuerySelectorAll("#post-hentai img");
|
||||
foreach (var img in imgElements)
|
||||
{
|
||||
@@ -140,7 +123,15 @@ internal class momonga_magazine
|
||||
// 相対URLの場合も考慮して、絶対URLに解決する
|
||||
if (Uri.TryCreate(link, src, out var absoluteUri))
|
||||
{
|
||||
string encoded = ToBase64Url(link.AbsoluteUri);
|
||||
string downloadUrl = $"https://apicien.armonica-vps.work/fanzine/{encoded}";
|
||||
|
||||
body.Append($"<div>");
|
||||
body.Append($"<a href=\"{downloadUrl}\">[Download]</a>");
|
||||
body.Append($"</div>");
|
||||
body.Append($"<div>");
|
||||
body.Append($"<img src=\"{absoluteUri}\" />");
|
||||
body.Append($"</div>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -149,7 +140,10 @@ internal class momonga_magazine
|
||||
newItem.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
|
||||
|
||||
return newItem;
|
||||
});
|
||||
}).ToList();
|
||||
|
||||
var simplifiedItems = await Task.WhenAll(itemTasks);
|
||||
|
||||
// 新しい統合フィードを作成
|
||||
var mergedFeed = new SyndicationFeed(
|
||||
"momon-ga.com",
|
||||
@@ -165,4 +159,17 @@ internal class momonga_magazine
|
||||
LogManager.AddLog($"[エラー] momonga-magazine:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文字列をURLセーフなBase64(Base64URL)に変換します (RFC 4648 準拠)
|
||||
/// </summary>
|
||||
static string ToBase64Url(string plainText)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(plainText);
|
||||
return Convert.ToBase64String(bytes)
|
||||
.Replace('+', '-') // '+' を '-' に置換
|
||||
.Replace('/', '_') // '/' を '_' に置換
|
||||
.TrimEnd('='); // 末尾のパディング '=' を削除
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user