Added internal rss.xml template and config option to turn off rss creation
authorspf13 <steve.francia@gmail.com>
Wed, 9 Apr 2014 21:45:34 +0000 (17:45 -0400)
committerspf13 <steve.francia@gmail.com>
Wed, 9 Apr 2014 21:45:34 +0000 (17:45 -0400)
commands/hugo.go
hugolib/site.go
template/bundle/embedded.go
template/bundle/template.go

index e08337859ae46cd78c8742c4e3b1103fe6928e42..a6db4d19d5bc8bab426a2a4fc1fccb7b3999a5de 100644 (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)
        }
index c8fc8893ba0e9aed6474c88e6150e7c78532357a..63810c1aa061dbf3a0e280c44aefa56a5a8d625c 100644 (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
                }
index 5beeb8d1f006554f7fef9632e15c7a0ea001f775..45e182b7a7e39e80c413123fbcd341294ac84e48 100644 (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>`)
+
+}
index 5d34bbf808be8c2a275148e94b1093db9c14fdef..20316de4902117b95aabe1d2d673e449fbfd6a8e 100644 (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 {