Skip to content

Commit

Permalink
bezel: Fix metrics on sites using the “nodes” overload
Browse files Browse the repository at this point in the history
Also copy over the update PlausiblePlugin file to cleanpresenter and root.
  • Loading branch information
mac-cain13 committed May 13, 2024
1 parent 9ad9327 commit 250f8f6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 53 deletions.
27 changes: 26 additions & 1 deletion bezel/Sources/BezelWebsite/PlausiblePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<head>` tag within the current context, based
/// on inferred information from the current location and `Website`
/// implementation.
/// - parameter location: The location to generate a `<head>` 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<T: Website>(
for location: Location,
on site: T,
titleSeparator: String = " | ",
stylesheetPaths: [Path] = ["/styles.css"],
rssFeedPath: Path? = .defaultForRSSFeed,
rssFeedTitle: String? = nil,
nodes: [Node<HTML.HeadContext>] = []
) -> Node {
var title = location.title

Expand Down Expand Up @@ -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 })
)
}
}
50 changes: 0 additions & 50 deletions bezel/Sources/BezelWebsite/Theme/Bezel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Website>(
for location: Location,
on site: T,
titleSeparator: String = " | ",
stylesheetPaths: [Path] = ["/styles.css"],
rssFeedPath: Path? = .defaultForRSSFeed,
rssFeedTitle: String? = nil,
nodes: [Node<HTML.HeadContext>] = []
) -> 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 })
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<head>` tag within the current context, based
/// on inferred information from the current location and `Website`
/// implementation.
/// - parameter location: The location to generate a `<head>` 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<T: Website>(
for location: Location,
on site: T,
titleSeparator: String = " | ",
stylesheetPaths: [Path] = ["/styles.css"],
rssFeedPath: Path? = .defaultForRSSFeed,
rssFeedTitle: String? = nil,
nodes: [Node<HTML.HeadContext>] = []
) -> Node {
var title = location.title

Expand Down Expand Up @@ -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 })
)
}
}
27 changes: 26 additions & 1 deletion root/Sources/NonstrictWebsite/PlausiblePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<head>` tag within the current context, based
/// on inferred information from the current location and `Website`
/// implementation.
/// - parameter location: The location to generate a `<head>` 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<T: Website>(
for location: Location,
on site: T,
titleSeparator: String = " | ",
stylesheetPaths: [Path] = ["/styles.css"],
rssFeedPath: Path? = .defaultForRSSFeed,
rssFeedTitle: String? = nil,
nodes: [Node<HTML.HeadContext>] = []
) -> Node {
var title = location.title

Expand Down Expand Up @@ -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 })
)
}
}

0 comments on commit 250f8f6

Please sign in to comment.