Skip to content

Commit

Permalink
Added internal rss.xml template and config option to turn off rss cre…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
spf13 committed Apr 9, 2014
1 parent bb9bcdc commit c0a046c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
8 changes: 7 additions & 1 deletion commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
}
Expand Down
15 changes: 6 additions & 9 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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"
Expand All @@ -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
}
Expand Down
26 changes: 26 additions & 0 deletions template/bundle/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>`)

}
1 change: 1 addition & 0 deletions template/bundle/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func NewTemplate() Template {

func (t *GoHtmlTemplate) LoadEmbedded() {
t.EmbedShortcodes()
t.EmbedTemplates()
}

func (t *GoHtmlTemplate) AddInternalTemplate(prefix, name, tpl string) error {
Expand Down

0 comments on commit c0a046c

Please sign in to comment.