mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
Make site email optional
This commit is contained in:
parent
1426b4e75b
commit
fa3ec10345
3 changed files with 11 additions and 3 deletions
|
|
@ -53,11 +53,19 @@ final class RSSFeedWriter {
|
||||||
)
|
)
|
||||||
let renderedPosts: [FeedPost] = try posts.map { post in
|
let renderedPosts: [FeedPost] = try posts.map { post in
|
||||||
let title = post.isLink ? "→ \(post.title)" : post.title
|
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)
|
let url = site.url.appendingPathComponent(post.path)
|
||||||
return FeedPost(
|
return FeedPost(
|
||||||
title: title.htmlEscape(useNamedReferences: true),
|
title: title.htmlEscape(useNamedReferences: true),
|
||||||
date: post.date.rfc822.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),
|
link: (post.link ?? url).absoluteString.htmlEscape(useNamedReferences: true),
|
||||||
guid: url.absoluteString.htmlEscape(useNamedReferences: true),
|
guid: url.absoluteString.htmlEscape(useNamedReferences: true),
|
||||||
body: try templateRenderer.renderTemplate(name: "feed-post.html", context: [
|
body: try templateRenderer.renderTemplate(name: "feed-post.html", context: [
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import Foundation
|
||||||
/// This is used to make the JSON simpler to write with optionals.
|
/// This is used to make the JSON simpler to write with optionals.
|
||||||
struct HumanSite: Codable {
|
struct HumanSite: Codable {
|
||||||
let author: String
|
let author: String
|
||||||
let email: String
|
let email: String?
|
||||||
let title: String
|
let title: String
|
||||||
let description: String?
|
let description: String?
|
||||||
let url: URL
|
let url: URL
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import Foundation
|
||||||
|
|
||||||
public struct Site {
|
public struct Site {
|
||||||
public let author: String
|
public let author: String
|
||||||
public let email: String
|
public let email: String?
|
||||||
public let title: String
|
public let title: String
|
||||||
public let description: String?
|
public let description: String?
|
||||||
public let url: URL
|
public let url: URL
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue