Remove support for deprecated feeds

This commit is contained in:
Adnan Maolood 2021-10-02 16:19:08 -04:00
parent aa9f0cd840
commit 5a674c0ea5
2 changed files with 5 additions and 65 deletions

28
dir.go
View file

@ -208,35 +208,17 @@ func (d Dir) buildFeed(cfg *Site, feed Feed) ([]byte, error) {
Pages []*Page
}
// DeprecatedFeed represents a deprecated feed.
type DeprecatedFeed struct {
Title string
Permalink string
Updated time.Time
Entries []*Page
}
tmpl, ok := cfg.templates.FindTemplate(d.Permalink, feed.Template)
if !ok {
return nil, fmt.Errorf("failed to generate feed %q: missing feed template %q", feed.Title, feed.Template)
}
var b bytes.Buffer
var data interface{}
if !feed.deprecated {
data = Feed{
Title: feed.Title,
Permalink: d.Permalink,
Updated: time.Now(),
Pages: d.Pages,
}
} else {
data = DeprecatedFeed{
Title: feed.Title,
Permalink: d.Permalink,
Updated: time.Now(),
Entries: d.Pages,
}
data := Feed{
Title: feed.Title,
Permalink: d.Permalink,
Updated: time.Now(),
Pages: d.Pages,
}
if err := tmpl.Execute(&b, data); err != nil {
return nil, err

42
site.go
View file

@ -2,10 +2,7 @@ package main
import (
"fmt"
"log"
"os"
"path"
"strings"
"text/template"
"github.com/pelletier/go-toml"
@ -16,7 +13,6 @@ type Site struct {
Title string `toml:"title"`
URLs []string `toml:"urls"`
Tasks []*Task `toml:"tasks"`
Feeds map[string]string `toml:"feeds"` // Deprecated. Use Task.Feeds instead
Params map[string]string `toml:"params"`
Permalinks map[string]string `toml:"permalinks"`
permalinks map[string]*template.Template
@ -43,9 +39,6 @@ type Feed struct {
Title string `toml:"title"`
Template string `toml:"template"`
Output string `toml:"output"`
// if true, the feed was specified using deprecated configuration options.
deprecated bool
}
func (t *Task) Match(ext string) bool {
@ -104,41 +97,6 @@ func LoadSite(config string) (*Site, error) {
}
}
// Populate task feeds map with deprecated feeds
for dir, title := range site.Feeds {
// Deprecated feeds apply to every task
for _, task := range site.Tasks {
if _, ok := task.feeds[dir]; !ok {
dir = strings.TrimSuffix(dir, "/")
task.feeds[dir] = append(task.feeds[dir], Feed{
InputDir: dir,
Title: title,
Template: "atom.xml",
Output: path.Join(dir, "atom.xml"),
deprecated: true,
})
}
}
}
// Print deprecation warning for [feeds]
if len(site.Feeds) > 0 {
log.Println("WARNING: The [feeds] configuration is deprecated. Please use [[tasks.feeds]] instead:")
for permalink, title := range site.Feeds {
dir := strings.Trim(permalink, "/")
output := path.Join(dir, "atom.xml")
fmt.Fprintf(log.Writer(), `[[tasks.feeds]]
input_dir = %q
title = %q
template = "atom.xml"
output = %q
`, dir, title, output)
}
fmt.Fprintf(log.Writer(), "# NOTE: You will also need to use .Pages instead of .Entries in your feed templates\n")
}
return site, nil
}