Updates for JSON Feed 1.1

- Add `authors` now that `author` is deprecated

- Add `language` with the value en-CA

- Change MIME type to application/feed+json
This commit is contained in:
Sami Samhuri 2020-10-26 10:45:07 -07:00
parent be47fc2974
commit 905ccfa674
3 changed files with 21 additions and 9 deletions

View file

@ -6,6 +6,10 @@ AddType text/html net
SetOutputFilter DEFLATE SetOutputFilter DEFLATE
AddDefaultCharset utf-8 AddDefaultCharset utf-8
<Files feed.json>
AddType application/feed+json json
</Files>
# Turn on Expires and set default expires to 3 days # Turn on Expires and set default expires to 3 days
ExpiresActive On ExpiresActive On
ExpiresDefault A259200 ExpiresDefault A259200
@ -18,7 +22,7 @@ ExpiresDefault A259200
</FilesMatch> </FilesMatch>
# Set up 2 week caching on commonly updated files # Set up 2 week caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css|rss)$"> <FilesMatch "\.(xml|txt|html|js|css|rss|json)$">
ExpiresDefault A1209600 ExpiresDefault A1209600
Header append Cache-Control "private, must-revalidate" Header append Cache-Control "private, must-revalidate"
</FilesMatch> </FilesMatch>

View file

@ -10,7 +10,7 @@ import Foundation
struct Permissions: OptionSet { struct Permissions: OptionSet {
let rawValue: Int16 let rawValue: Int16
static let none = Permissions(rawValue: 0) static let none: Permissions = []
// These raw values match those used by Unix file systems and must not be changed. // These raw values match those used by Unix file systems and must not be changed.

View file

@ -37,15 +37,17 @@ final class JSONFeedWriter {
private extension JSONFeedWriter { private extension JSONFeedWriter {
func buildFeed(site: Site, posts: [Post], renderer: JSONFeedRendering) throws -> Feed { func buildFeed(site: Site, posts: [Post], renderer: JSONFeedRendering) throws -> Feed {
Feed( let author = FeedAuthor(
name: site.author,
avatar: jsonFeed.avatarPath.map(site.url.appendingPathComponent)?.absoluteString,
url: site.url.absoluteString
)
return Feed(
title: site.title, title: site.title,
home_page_url: site.url.absoluteString, home_page_url: site.url.absoluteString,
feed_url: site.url.appendingPathComponent(jsonFeed.path).absoluteString, feed_url: site.url.appendingPathComponent(jsonFeed.path).absoluteString,
author: FeedAuthor( author: author,
name: site.author, authors: [author],
avatar: jsonFeed.avatarPath.map(site.url.appendingPathComponent)?.absoluteString,
url: site.url.absoluteString
),
icon: jsonFeed.iconPath.map(site.url.appendingPathComponent)?.absoluteString, icon: jsonFeed.iconPath.map(site.url.appendingPathComponent)?.absoluteString,
favicon: jsonFeed.faviconPath.map(site.url.appendingPathComponent)?.absoluteString, favicon: jsonFeed.faviconPath.map(site.url.appendingPathComponent)?.absoluteString,
items: try posts.map { post in items: try posts.map { post in
@ -66,11 +68,17 @@ private extension JSONFeedWriter {
} }
private struct Feed: Codable { private struct Feed: Codable {
let version = "https://jsonfeed.org/version/1" var version = "https://jsonfeed.org/version/1.1"
var language = "en-CA"
let title: String let title: String
let home_page_url: String let home_page_url: String
let feed_url: String let feed_url: String
// `author` has been deprecated in favour of `authors`, but `author` remains for backwards
// compatibility.
let author: FeedAuthor let author: FeedAuthor
let authors: [FeedAuthor]
let icon: String? let icon: String?
let favicon: String? let favicon: String?
let items: [FeedItem] let items: [FeedItem]