Make site email optional

This commit is contained in:
Sami Samhuri 2019-12-11 00:00:44 -08:00
parent 1426b4e75b
commit fa3ec10345
3 changed files with 11 additions and 3 deletions

View file

@ -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: [

View file

@ -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

View file

@ -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