From fa3ec1034517bad80e9cffd7b6b3c34ba9665391 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Wed, 11 Dec 2019 00:00:44 -0800 Subject: [PATCH] Make site email optional --- .../Sources/SiteGenerator/Feeds/RSSFeedWriter.swift | 10 +++++++++- .../Sources/SiteGenerator/Generator/HumanSite.swift | 2 +- .../Sources/SiteGenerator/Generator/Site.swift | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/SiteGenerator/Sources/SiteGenerator/Feeds/RSSFeedWriter.swift b/SiteGenerator/Sources/SiteGenerator/Feeds/RSSFeedWriter.swift index f9ac971..2a9fe46 100644 --- a/SiteGenerator/Sources/SiteGenerator/Feeds/RSSFeedWriter.swift +++ b/SiteGenerator/Sources/SiteGenerator/Feeds/RSSFeedWriter.swift @@ -53,11 +53,19 @@ final class RSSFeedWriter { ) let renderedPosts: [FeedPost] = try posts.map { post in let title = post.isLink ? "→ \(post.title)" : post.title + let author: String = { + if let email = site.email { + return "\(email) (\(post.author))" + } + else { + return post.author + } + }() let url = site.url.appendingPathComponent(post.path) return FeedPost( title: title.htmlEscape(useNamedReferences: true), date: post.date.rfc822.htmlEscape(useNamedReferences: true), - author: "\(site.email) (\(post.author))".htmlEscape(useNamedReferences: true), + author: author.htmlEscape(useNamedReferences: true), link: (post.link ?? url).absoluteString.htmlEscape(useNamedReferences: true), guid: url.absoluteString.htmlEscape(useNamedReferences: true), body: try templateRenderer.renderTemplate(name: "feed-post.html", context: [ diff --git a/SiteGenerator/Sources/SiteGenerator/Generator/HumanSite.swift b/SiteGenerator/Sources/SiteGenerator/Generator/HumanSite.swift index b98778e..6ac09d0 100644 --- a/SiteGenerator/Sources/SiteGenerator/Generator/HumanSite.swift +++ b/SiteGenerator/Sources/SiteGenerator/Generator/HumanSite.swift @@ -10,7 +10,7 @@ import Foundation /// This is used to make the JSON simpler to write with optionals. struct HumanSite: Codable { let author: String - let email: String + let email: String? let title: String let description: String? let url: URL diff --git a/SiteGenerator/Sources/SiteGenerator/Generator/Site.swift b/SiteGenerator/Sources/SiteGenerator/Generator/Site.swift index a66426c..19ecf7d 100644 --- a/SiteGenerator/Sources/SiteGenerator/Generator/Site.swift +++ b/SiteGenerator/Sources/SiteGenerator/Generator/Site.swift @@ -9,7 +9,7 @@ import Foundation public struct Site { public let author: String - public let email: String + public let email: String? public let title: String public let description: String? public let url: URL