From d1434c6e15610409e0a280aef90a300da22b23f9 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sun, 23 Jan 2022 21:22:30 +0100 Subject: feat: Fall back to document title if no description is found in site report --- src/server/Api/Internal/GetSiteReportRoute.cs | 12 +++++++++--- 1 file 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 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"); } -- cgit v1.3