feat: add CmnUtil class and kimochi.info RSS feed generator service
This commit is contained in:
1 parent
d18ed28eda
commit
46808590c6
2 files changed
+14
-4
No files matched your search
@@ -386,7 +386,12 @@ public class CmnUtil
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Feed を非同期でファイルに出力します。画像 Base64 変換が有効な場合は自動で変換を行います。
|
/// Feed を非同期でファイルに出力します。画像 Base64 変換が有効な場合は自動で変換を行います。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task ExportXMLFileAsync(string fileName, SyndicationFeed feed, HttpClient? client = null, string addDir = "")
|
/// <param name="fileName">出力先ファイル名</param>
|
||||||
|
/// <param name="feed">SyndicationFeed</param>
|
||||||
|
/// <param name="client">画像ダウンロード用 HttpClient</param>
|
||||||
|
/// <param name="addDir">サブディレクトリ</param>
|
||||||
|
/// <param name="embedBase64">画像を Base64 変換するかどうか(false の場合は通常の画像リンクを維持)</param>
|
||||||
|
public static async Task ExportXMLFileAsync(string fileName, SyndicationFeed feed, HttpClient? client = null, string addDir = "", bool embedBase64 = true)
|
||||||
{
|
{
|
||||||
// 24時間以上前の古い記事を除外
|
// 24時間以上前の古い記事を除外
|
||||||
if (feed.Items != null)
|
if (feed.Items != null)
|
||||||
@@ -395,7 +400,7 @@ public class CmnUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 画像の Base64 埋め込み処理
|
// 画像の Base64 埋め込み処理
|
||||||
if (EmbedAllImagesBase64 && client != null)
|
if (embedBase64 && EmbedAllImagesBase64 && client != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ internal class kimochiinfo
|
|||||||
foreach (var linkElement in elements)
|
foreach (var linkElement in elements)
|
||||||
{
|
{
|
||||||
var imgElement = linkElement.QuerySelector("img");
|
var imgElement = linkElement.QuerySelector("img");
|
||||||
var imageSrc = (imgElement as IHtmlImageElement)!.Source;
|
var imageSrc = (imgElement as IHtmlImageElement)?.Source ?? imgElement?.GetAttribute("src");
|
||||||
var linkHref = linkElement.GetAttribute("href") ?? string.Empty;
|
var linkHref = linkElement.GetAttribute("href") ?? string.Empty;
|
||||||
if (linkHref != string.Empty && !linkList.Contains(linkHref))
|
if (linkHref != string.Empty && !linkList.Contains(linkHref))
|
||||||
{
|
{
|
||||||
@@ -103,6 +103,10 @@ internal class kimochiinfo
|
|||||||
a.SetAttribute("rel", "noopener noreferrer");
|
a.SetAttribute("rel", "noopener noreferrer");
|
||||||
a.SetAttribute("referrerpolicy", "no-referrer");
|
a.SetAttribute("referrerpolicy", "no-referrer");
|
||||||
}
|
}
|
||||||
|
foreach (var img in divDetail.QuerySelectorAll("img"))
|
||||||
|
{
|
||||||
|
img.SetAttribute("referrerpolicy", "no-referrer");
|
||||||
|
}
|
||||||
body.Append(CmnUtil.GetHtmlWithoutJavaScript(divDetail));
|
body.Append(CmnUtil.GetHtmlWithoutJavaScript(divDetail));
|
||||||
|
|
||||||
var item = new SyndicationItem(
|
var item = new SyndicationItem(
|
||||||
@@ -122,7 +126,8 @@ internal class kimochiinfo
|
|||||||
}
|
}
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("kimochiinfo.xml", feed, client);
|
// kimochiinfo は画像リンクを Base64 変換せず、通常の画像リンクとして出力する
|
||||||
|
await CmnUtil.ExportXMLFileAsync("kimochiinfo.xml", feed, client, embedBase64: false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user