
struct FeedGeneratorSource: PostListPageGeneratorSource {

    let language: ContentLanguage
    
    let content: Content
    
    let results: PageGenerationResults
    
    var postsPerPage: Int {
        content.settings.posts.postsPerPage
    }

    var pageTitle: String? {
        nil // Don't show title in page
    }

    private var linkPreview: LinkPreview {
        content.settings.posts.localized(in: language).linkPreview
    }

    var linkTitle: String? {
        linkPreview.title
    }

    var linkDescription: String? {
        linkPreview.description
    }

    var linkImage: FileResource? {
        linkPreview.image
    }

    /**
     The url to the page, including a leading slash
     */
    func pageUrlPrefix(for language: ContentLanguage) -> String {
        let prefix = content.settings.posts.localized(in: language).feedUrlPrefix
        if prefix.hasPrefix( "/" ) {
            return prefix
        }
        return "/" + prefix
    }
}
