mirror of
https://git.sr.ht/~adnano/kiln
synced 2025-01-19 13:56:02 +00:00
Remove support for deprecated feeds
This commit is contained in:
parent
1d78b726d5
commit
d3fddff4e6
28
dir.go
28
dir.go
|
@ -208,35 +208,17 @@ func (d Dir) buildFeed(cfg *Site, feed Feed) ([]byte, error) {
|
||||||
Pages []*Page
|
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)
|
tmpl, ok := cfg.templates.FindTemplate(d.Permalink, feed.Template)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("failed to generate feed %q: missing feed template %q", feed.Title, feed.Template)
|
return nil, fmt.Errorf("failed to generate feed %q: missing feed template %q", feed.Title, feed.Template)
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
var data interface{}
|
data := Feed{
|
||||||
if !feed.deprecated {
|
Title: feed.Title,
|
||||||
data = Feed{
|
Permalink: d.Permalink,
|
||||||
Title: feed.Title,
|
Updated: time.Now(),
|
||||||
Permalink: d.Permalink,
|
Pages: d.Pages,
|
||||||
Updated: time.Now(),
|
|
||||||
Pages: d.Pages,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data = DeprecatedFeed{
|
|
||||||
Title: feed.Title,
|
|
||||||
Permalink: d.Permalink,
|
|
||||||
Updated: time.Now(),
|
|
||||||
Entries: d.Pages,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := tmpl.Execute(&b, data); err != nil {
|
if err := tmpl.Execute(&b, data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
42
site.go
42
site.go
|
@ -2,10 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
|
@ -16,7 +13,6 @@ type Site struct {
|
||||||
Title string `toml:"title"`
|
Title string `toml:"title"`
|
||||||
URLs []string `toml:"urls"`
|
URLs []string `toml:"urls"`
|
||||||
Tasks []*Task `toml:"tasks"`
|
Tasks []*Task `toml:"tasks"`
|
||||||
Feeds map[string]string `toml:"feeds"` // Deprecated. Use Task.Feeds instead
|
|
||||||
Params map[string]string `toml:"params"`
|
Params map[string]string `toml:"params"`
|
||||||
Permalinks map[string]string `toml:"permalinks"`
|
Permalinks map[string]string `toml:"permalinks"`
|
||||||
permalinks map[string]*template.Template
|
permalinks map[string]*template.Template
|
||||||
|
@ -43,9 +39,6 @@ type Feed struct {
|
||||||
Title string `toml:"title"`
|
Title string `toml:"title"`
|
||||||
Template string `toml:"template"`
|
Template string `toml:"template"`
|
||||||
Output string `toml:"output"`
|
Output string `toml:"output"`
|
||||||
|
|
||||||
// if true, the feed was specified using deprecated configuration options.
|
|
||||||
deprecated bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) Match(ext string) 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
|
return site, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue