diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-01-23 21:22:30 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-01-23 21:22:30 +0100 |
| commit | d1434c6e15610409e0a280aef90a300da22b23f9 (patch) | |
| tree | 1da897a7a6d4dc14ca36944d1d010ba3cb010892 /src/server/Api/Internal/GetSiteReportRoute.cs | |
| parent | 2fe56c2d2c2a0d940c819011c55a27f50157c7e9 (diff) | |
| download | bookmark-thing-d1434c6e15610409e0a280aef90a300da22b23f9.tar.xz bookmark-thing-d1434c6e15610409e0a280aef90a300da22b23f9.zip | |
feat: Fall back to document title if no description is found in site report
Diffstat (limited to 'src/server/Api/Internal/GetSiteReportRoute.cs')
| -rw-r--r-- | src/server/Api/Internal/GetSiteReportRoute.cs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/server/Api/Internal/GetSiteReportRoute.cs b/src/server/Api/Internal/GetSiteReportRoute.cs index 58d6637..8b22795 100644 --- a/src/server/Api/Internal/GetSiteReportRoute.cs +++ b/src/server/Api/Internal/GetSiteReportRoute.cs @@ -32,9 +32,15 @@ public class GetSiteReportRoute : RouteBaseInternalAsync.WithRequest<GetSiteRepo try { var document = new HtmlDocument(); document.Load(await http_request.Content.ReadAsStreamAsync(cancellationToken)); - var htmlNodes = document.DocumentNode.Descendants("meta") - .Where(p => p.GetAttributeValue("name", string.Empty).Equals("description", StringComparison.InvariantCultureIgnoreCase)); - report.Description = htmlNodes.FirstOrDefault()?.GetAttributeValue("content", string.Empty); + var descriptions = document.DocumentNode.Descendants("meta") + .Where(p => p.GetAttributeValue("name", string.Empty).Equals("description", StringComparison.InvariantCultureIgnoreCase)); + var description = descriptions.FirstOrDefault()?.GetAttributeValue("content", string.Empty); + if (description.HasValue()) { + report.Description = description; + } else { + var title = document.DocumentNode.Descendants("title").FirstOrDefault()?.InnerText; + report.Description = title; + } } catch (Exception e) { _logger.LogWarning(e, "An error occured when parsing site for site report"); } |
