Skip to content

Commit

Permalink
Update ContentProcessor.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Jan 21, 2024
1 parent 27122dd commit e90f7f2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Moonglade.Utils/ContentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ namespace Moonglade.Utils;

public static class ContentProcessor
{
public static string ReplaceCDNEndpointToImgTags(this string rawHtmlContent, string endpoint)
public static string ReplaceCDNEndpointToImgTags(this string html, string endpoint)
{
if (string.IsNullOrWhiteSpace(rawHtmlContent)) return rawHtmlContent;
if (string.IsNullOrWhiteSpace(html)) return html;

endpoint = endpoint.TrimEnd('/');
var imgSrcRegex = new Regex("<img.+?(src)=[\"'](.+?)[\"'].+?>");
var newStr = imgSrcRegex.Replace(rawHtmlContent,
var newStr = imgSrcRegex.Replace(html,
match => match.Value.Contains("src=\"/image/")
? match.Value.Replace("/image/", $"{endpoint}/")
: match.Value);

return newStr;
}

public static string GetPostAbstract(string rawContent, int wordCount, bool useMarkdown = false)
public static string GetPostAbstract(string content, int wordCount, bool useMarkdown = false)
{
var plainText = useMarkdown ?
MarkdownToContent(rawContent, MarkdownConvertType.Text) :
RemoveTags(rawContent);
MarkdownToContent(content, MarkdownConvertType.Text) :
RemoveTags(content);

var result = plainText.Ellipsize(wordCount);
return result;
Expand Down

0 comments on commit e90f7f2

Please sign in to comment.