From 250f8f6b0cd24802c7f9b1d5ff09f6319584c774 Mon Sep 17 00:00:00 2001 From: Mathijs Kadijk Date: Mon, 13 May 2024 11:02:41 +0200 Subject: [PATCH] =?UTF-8?q?bezel:=20Fix=20metrics=20on=20sites=20using=20t?= =?UTF-8?q?he=20=E2=80=9Cnodes=E2=80=9D=20overload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also copy over the update PlausiblePlugin file to cleanpresenter and root. --- .../BezelWebsite/PlausiblePlugin.swift | 27 +++++++++- bezel/Sources/BezelWebsite/Theme/Bezel.swift | 50 ------------------- .../PlausiblePlugin.swift | 27 +++++++++- .../NonstrictWebsite/PlausiblePlugin.swift | 27 +++++++++- 4 files changed, 78 insertions(+), 53 deletions(-) diff --git a/bezel/Sources/BezelWebsite/PlausiblePlugin.swift b/bezel/Sources/BezelWebsite/PlausiblePlugin.swift index 8050f16..551b4f8 100644 --- a/bezel/Sources/BezelWebsite/PlausiblePlugin.swift +++ b/bezel/Sources/BezelWebsite/PlausiblePlugin.swift @@ -21,6 +21,30 @@ public extension Node where Context == HTML.DocumentContext { stylesheetPaths: [Path] = ["/styles.css"], rssFeedPath: Path? = .defaultForRSSFeed, rssFeedTitle: String? = nil + ) -> Node { + head(for: location, on: site, titleSeparator: titleSeparator, stylesheetPaths: stylesheetPaths, rssFeedPath: rssFeedPath, rssFeedTitle: rssFeedTitle, nodes: []) + } + + /// Add an HTML `` tag within the current context, based + /// on inferred information from the current location and `Website` + /// implementation. + /// - parameter location: The location to generate a `` tag for. + /// - parameter site: The website on which the location is located. + /// - parameter titleSeparator: Any string to use to separate the location's + /// title from the name of the website. Default: `" | "`. + /// - parameter stylesheetPaths: The paths to any stylesheets to add to + /// the resulting HTML page. Default: `styles.css`. + /// - parameter rssFeedPath: The path to any RSS feed to associate with the + /// resulting HTML page. Default: `feed.rss`. + /// - parameter rssFeedTitle: An optional title for the page's RSS feed. + static func head( + for location: Location, + on site: T, + titleSeparator: String = " | ", + stylesheetPaths: [Path] = ["/styles.css"], + rssFeedPath: Path? = .defaultForRSSFeed, + rssFeedTitle: String? = nil, + nodes: [Node] = [] ) -> Node { var title = location.title @@ -54,7 +78,8 @@ public extension Node where Context == HTML.DocumentContext { .unwrap(location.imagePath ?? site.imagePath, { path in let url = site.url(for: path) return .socialImageLink(url) - }) + }), + .forEach(nodes, { $0 }) ) } } diff --git a/bezel/Sources/BezelWebsite/Theme/Bezel.swift b/bezel/Sources/BezelWebsite/Theme/Bezel.swift index 47ec0f9..e9911d4 100644 --- a/bezel/Sources/BezelWebsite/Theme/Bezel.swift +++ b/bezel/Sources/BezelWebsite/Theme/Bezel.swift @@ -188,53 +188,3 @@ extension Theme where Site == BezelWebsite { } } } - - -public extension Node where Context == HTML.DocumentContext { - - // Copy of head function from Plot, with extra node parameter - static func head( - for location: Location, - on site: T, - titleSeparator: String = " | ", - stylesheetPaths: [Path] = ["/styles.css"], - rssFeedPath: Path? = .defaultForRSSFeed, - rssFeedTitle: String? = nil, - nodes: [Node] = [] - ) -> Node { - var title = location.title - - if title.isEmpty { - title = site.name - } else { - title.append(titleSeparator + site.name) - } - - var description = location.description - - if description.isEmpty { - description = site.description - } - - return .head( - .encoding(.utf8), - .siteName(site.name), - .url(site.url(for: location)), - .title(title), - .description(description), - .twitterCardType(location.imagePath == nil ? .summary : .summaryLargeImage), - .forEach(stylesheetPaths, { .stylesheet($0) }), - .viewport(.accordingToDevice), - .unwrap(site.favicon, { .favicon($0) }), - .unwrap(rssFeedPath, { path in - let title = rssFeedTitle ?? "Subscribe to \(site.name)" - return .rssFeedLink(path.absoluteString, title: title) - }), - .unwrap(location.imagePath ?? site.imagePath, { path in - let url = site.url(for: path) - return .socialImageLink(url) - }), - .forEach(nodes, { $0 }) - ) - } -} diff --git a/cleanpresenter/Sources/CleanPresenterWebsite/PlausiblePlugin.swift b/cleanpresenter/Sources/CleanPresenterWebsite/PlausiblePlugin.swift index 8050f16..551b4f8 100644 --- a/cleanpresenter/Sources/CleanPresenterWebsite/PlausiblePlugin.swift +++ b/cleanpresenter/Sources/CleanPresenterWebsite/PlausiblePlugin.swift @@ -21,6 +21,30 @@ public extension Node where Context == HTML.DocumentContext { stylesheetPaths: [Path] = ["/styles.css"], rssFeedPath: Path? = .defaultForRSSFeed, rssFeedTitle: String? = nil + ) -> Node { + head(for: location, on: site, titleSeparator: titleSeparator, stylesheetPaths: stylesheetPaths, rssFeedPath: rssFeedPath, rssFeedTitle: rssFeedTitle, nodes: []) + } + + /// Add an HTML `` tag within the current context, based + /// on inferred information from the current location and `Website` + /// implementation. + /// - parameter location: The location to generate a `` tag for. + /// - parameter site: The website on which the location is located. + /// - parameter titleSeparator: Any string to use to separate the location's + /// title from the name of the website. Default: `" | "`. + /// - parameter stylesheetPaths: The paths to any stylesheets to add to + /// the resulting HTML page. Default: `styles.css`. + /// - parameter rssFeedPath: The path to any RSS feed to associate with the + /// resulting HTML page. Default: `feed.rss`. + /// - parameter rssFeedTitle: An optional title for the page's RSS feed. + static func head( + for location: Location, + on site: T, + titleSeparator: String = " | ", + stylesheetPaths: [Path] = ["/styles.css"], + rssFeedPath: Path? = .defaultForRSSFeed, + rssFeedTitle: String? = nil, + nodes: [Node] = [] ) -> Node { var title = location.title @@ -54,7 +78,8 @@ public extension Node where Context == HTML.DocumentContext { .unwrap(location.imagePath ?? site.imagePath, { path in let url = site.url(for: path) return .socialImageLink(url) - }) + }), + .forEach(nodes, { $0 }) ) } } diff --git a/root/Sources/NonstrictWebsite/PlausiblePlugin.swift b/root/Sources/NonstrictWebsite/PlausiblePlugin.swift index 8050f16..551b4f8 100644 --- a/root/Sources/NonstrictWebsite/PlausiblePlugin.swift +++ b/root/Sources/NonstrictWebsite/PlausiblePlugin.swift @@ -21,6 +21,30 @@ public extension Node where Context == HTML.DocumentContext { stylesheetPaths: [Path] = ["/styles.css"], rssFeedPath: Path? = .defaultForRSSFeed, rssFeedTitle: String? = nil + ) -> Node { + head(for: location, on: site, titleSeparator: titleSeparator, stylesheetPaths: stylesheetPaths, rssFeedPath: rssFeedPath, rssFeedTitle: rssFeedTitle, nodes: []) + } + + /// Add an HTML `` tag within the current context, based + /// on inferred information from the current location and `Website` + /// implementation. + /// - parameter location: The location to generate a `` tag for. + /// - parameter site: The website on which the location is located. + /// - parameter titleSeparator: Any string to use to separate the location's + /// title from the name of the website. Default: `" | "`. + /// - parameter stylesheetPaths: The paths to any stylesheets to add to + /// the resulting HTML page. Default: `styles.css`. + /// - parameter rssFeedPath: The path to any RSS feed to associate with the + /// resulting HTML page. Default: `feed.rss`. + /// - parameter rssFeedTitle: An optional title for the page's RSS feed. + static func head( + for location: Location, + on site: T, + titleSeparator: String = " | ", + stylesheetPaths: [Path] = ["/styles.css"], + rssFeedPath: Path? = .defaultForRSSFeed, + rssFeedTitle: String? = nil, + nodes: [Node] = [] ) -> Node { var title = location.title @@ -54,7 +78,8 @@ public extension Node where Context == HTML.DocumentContext { .unwrap(location.imagePath ?? site.imagePath, { path in let url = site.url(for: path) return .socialImageLink(url) - }) + }), + .forEach(nodes, { $0 }) ) } }