Support uglyURLs per section - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 57e10f174e51cc5e1cf5f37eed30a0f3b153dd64
 (DIR) parent db85e83403913cff4b8737b138932b28e5bf6160
 (HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Thu, 11 Jan 2018 17:46:43 +0100
       
       Support uglyURLs per section
       
       Fixes #4256
       
       Diffstat:
         M hugolib/page_paths.go               |       2 +-
         M hugolib/site.go                     |      25 +++++++++++++++++++++++--
         M hugolib/site_url_test.go            |      37 +++++++++++++++++++++++++++++++
       
       3 files changed, 61 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/hugolib/page_paths.go b/hugolib/page_paths.go
       @@ -86,7 +86,7 @@ func (p *Page) initTargetPathDescriptor() error {
                        PathSpec:    p.s.PathSpec,
                        Kind:        p.Kind,
                        Sections:    p.sections,
       -                UglyURLs:    p.s.Info.uglyURLs,
       +                UglyURLs:    p.s.Info.uglyURLs(p),
                        Dir:         filepath.ToSlash(p.Source.Dir()),
                        URL:         p.URLPath.URL,
                        IsMultihost: p.s.owner.IsMultihost(),
 (DIR) diff --git a/hugolib/site.go b/hugolib/site.go
       @@ -357,7 +357,7 @@ type SiteInfo struct {
                BuildDrafts           bool
                canonifyURLs          bool
                relativeURLs          bool
       -        uglyURLs              bool
       +        uglyURLs              func(p *Page) bool
                preserveTaxonomyNames bool
                Data                  *map[string]interface{}
        
       @@ -413,6 +413,9 @@ func newSiteInfo(cfg siteBuilderCfg) SiteInfo {
                        multilingual:    newMultiLingualForLanguage(cfg.language),
                        PageCollections: cfg.pageCollections,
                        Params:          make(map[string]interface{}),
       +                uglyURLs: func(p *Page) bool {
       +                        return false
       +                },
                }
        }
        
       @@ -1035,6 +1038,24 @@ func (s *Site) initializeSiteInfo() {
                        multilingual = s.owner.multilingual
                }
        
       +        var uglyURLs = func(p *Page) bool {
       +                return false
       +        }
       +
       +        v := s.Cfg.Get("uglyURLs")
       +        if v != nil {
       +                if vv, ok := v.(bool); ok {
       +                        uglyURLs = func(p *Page) bool {
       +                                return vv
       +                        }
       +                } else {
       +                        m := cast.ToStringMapBool(v)
       +                        uglyURLs = func(p *Page) bool {
       +                                return m[p.Section()]
       +                        }
       +                }
       +        }
       +
                s.Info = SiteInfo{
                        Title:                          lang.GetString("title"),
                        Author:                         lang.GetStringMap("author"),
       @@ -1052,7 +1073,7 @@ func (s *Site) initializeSiteInfo() {
                        BuildDrafts:                    s.Cfg.GetBool("buildDrafts"),
                        canonifyURLs:                   s.Cfg.GetBool("canonifyURLs"),
                        relativeURLs:                   s.Cfg.GetBool("relativeURLs"),
       -                uglyURLs:                       s.Cfg.GetBool("uglyURLs"),
       +                uglyURLs:                       uglyURLs,
                        preserveTaxonomyNames:          lang.GetBool("preserveTaxonomyNames"),
                        PageCollections:                s.PageCollections,
                        Menus:                          &s.Menus,
 (DIR) diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go
       @@ -87,3 +87,40 @@ func TestPageCount(t *testing.T) {
                        }
                }
        }
       +
       +func TestUglyURLsPerSection(t *testing.T) {
       +        t.Parallel()
       +
       +        assert := require.New(t)
       +
       +        const dt = `---
       +title: Do not go gentle into that good night
       +---
       +
       +Wild men who caught and sang the sun in flight,
       +And learn, too late, they grieved it on its way,
       +Do not go gentle into that good night.
       +
       +`
       +
       +        cfg, fs := newTestCfg()
       +
       +        cfg.Set("uglyURLs", map[string]bool{
       +                "sect2": true,
       +        })
       +
       +        writeSource(t, fs, filepath.Join("content", "sect1", "p1.md"), dt)
       +        writeSource(t, fs, filepath.Join("content", "sect2", "p2.md"), dt)
       +
       +        s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
       +
       +        assert.Len(s.RegularPages, 2)
       +
       +        notUgly := s.getPage(KindPage, "sect1/p1.md")
       +        assert.NotNil(notUgly)
       +        assert.Equal("/sect1/p1/", notUgly.RelPermalink())
       +
       +        ugly := s.getPage(KindPage, "sect2/p2.md")
       +        assert.NotNil(ugly)
       +        assert.Equal("/sect2/p2.html", ugly.RelPermalink())
       +}