Added internal rss.xml template and config option to turn off rss creation

This commit is contained in:
spf13 2014-04-09 17:45:34 -04:00
parent bb9bcdcf30
commit c0a046cbfb
4 changed files with 40 additions and 10 deletions

View file

@ -48,7 +48,7 @@ Complete documentation is available at http://hugo.spf13.com`,
}
var hugoCmdV *cobra.Command
var BuildWatch, Draft, UglyUrls, Verbose, Logging, VerboseLog bool
var BuildWatch, Draft, UglyUrls, Verbose, Logging, VerboseLog, DisableRSS bool
var Source, Destination, BaseUrl, CfgFile, LogFile string
func Execute() {
@ -65,6 +65,7 @@ func AddCommands() {
func init() {
HugoCmd.PersistentFlags().BoolVarP(&Draft, "build-drafts", "D", false, "include content marked as draft")
HugoCmd.PersistentFlags().BoolVar(&DisableRSS, "disableRSS", false, "Do not build RSS files")
HugoCmd.PersistentFlags().StringVarP(&Source, "source", "s", "", "filesystem path to read files relative from")
HugoCmd.PersistentFlags().StringVarP(&Destination, "destination", "d", "", "filesystem path to write files to")
HugoCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
@ -86,6 +87,7 @@ func InitializeConfig() {
viper.RegisterAlias("taxonomies", "indexes")
viper.SetDefault("DisableRSS", false)
viper.SetDefault("ContentDir", "content")
viper.SetDefault("LayoutDir", "layouts")
viper.SetDefault("StaticDir", "static")
@ -106,6 +108,10 @@ func InitializeConfig() {
viper.Set("UglyUrls", UglyUrls)
}
if hugoCmdV.PersistentFlags().Lookup("disableRSS").Changed {
viper.Set("DisableRSS", DisableRSS)
}
if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}

View file

@ -457,11 +457,10 @@ func (s *Site) RenderTaxonomiesLists() (err error) {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
if !viper.GetBool("DisableRSS") {
// XML Feed
s.setUrls(n, base+".xml")
err := s.render(n, base+".xml", "rss.xml")
// TODO add "taxonomy.xml", "_internal/rss.xml"
err := s.render(n, base+".xml", "rss.xml", "_internal/_default/rss.xml")
if err != nil {
return err
}
@ -515,12 +514,11 @@ func (s *Site) RenderSectionLists() error {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
if !viper.GetBool("DisableRSS") {
// XML Feed
s.setUrls(n, section+".xml")
err = s.render(n, section+".xml", "rss.xml")
err = s.render(n, section+".xml", "rss.xml", "_internal/_default/rss.xml")
//TODO add section specific rss
// TODO add internal rss
if err != nil {
return err
}
@ -539,7 +537,7 @@ func (s *Site) RenderHomePage() error {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
if !viper.GetBool("DisableRSS") {
// XML Feed
n.Url = helpers.Urlize("index.xml")
n.Title = "Recent Content"
@ -552,8 +550,7 @@ func (s *Site) RenderHomePage() error {
if len(s.Pages) > 0 {
n.Date = s.Pages[0].Date
}
err := s.render(n, ".xml", "rss.xml")
// TODO add internal RSS
err := s.render(n, ".xml", "rss.xml", "_internal/_default/rss.xml")
if err != nil {
return err
}

View file

@ -40,3 +40,29 @@ func (t *GoHtmlTemplate) EmbedShortcodes() {
</figure>
<!-- image -->`)
}
func (t *GoHtmlTemplate) EmbedTemplates() {
t.AddInternalTemplate("_default", "rss.xml", `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ .Title }} on {{ .Site.Title }} </title>
<generator uri="https://hugo.spf13.com">Hugo</generator>
<link>{{ .Permalink }}</link>
{{ with .Site.LanguageCode }}<language>{{.}}</language>{{end}}
{{ with .Site.Author }}<author>{{.}}</author>{{end}}
{{ with .Site.Copyright }}<copyright>{{.}}</copyright>{{end}}
<updated>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</updated>
{{ range first 15 .Data.Pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</pubDate>
{{with .Site.Author}}<author>{{.}}</author>{{end}}
<guid>{{ .Permalink }}</guid>
<description>{{ .Content | html }}</description>
</item>
{{ end }}
</channel>
</rss>`)
}

View file

@ -187,6 +187,7 @@ func NewTemplate() Template {
func (t *GoHtmlTemplate) LoadEmbedded() {
t.EmbedShortcodes()
t.EmbedTemplates()
}
func (t *GoHtmlTemplate) AddInternalTemplate(prefix, name, tpl string) error {