hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

integration_test.go (3335B)

    1 // Copyright 2021 The Hugo Authors. All rights reserved.
    2 //
    3 // Licensed under the Apache License, Version 2.0 (the "License");
    4 // you may not use this file except in compliance with the License.
    5 // You may obtain a copy of the License at
    6 // http://www.apache.org/licenses/LICENSE-2.0
    7 //
    8 // Unless required by applicable law or agreed to in writing, software
    9 // distributed under the License is distributed on an "AS IS" BASIS,
   10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   11 // See the License for the specific language governing permissions and
   12 // limitations under the License.
   13 
   14 package page_test
   15 
   16 import (
   17 	"testing"
   18 
   19 	"github.com/gohugoio/hugo/hugolib"
   20 )
   21 
   22 func TestGroupByLocalizedDate(t *testing.T) {
   23 
   24 	files := `
   25 -- config.toml --
   26 defaultContentLanguage = 'en'
   27 defaultContentLanguageInSubdir = true
   28 [languages]
   29 [languages.en]
   30 title = 'My blog'
   31 weight = 1
   32 [languages.fr]
   33 title = 'Mon blogue'
   34 weight = 2
   35 [languages.nn]
   36 title = 'Bloggen min'
   37 weight = 3
   38 -- content/p1.md --
   39 ---
   40 title: "Post 1"
   41 date: "2020-01-01"
   42 ---
   43 -- content/p2.md --
   44 ---
   45 title: "Post 2"
   46 date: "2020-02-01"
   47 ---
   48 -- content/p1.fr.md --
   49 ---
   50 title: "Post 1"
   51 date: "2020-01-01"
   52 ---
   53 -- content/p2.fr.md --
   54 ---
   55 title: "Post 2"
   56 date: "2020-02-01"
   57 ---
   58 -- layouts/index.html --
   59 {{ range $k, $v := site.RegularPages.GroupByDate "January, 2006" }}{{ $k }}|{{ $v.Key }}|{{ $v.Pages }}{{ end }}
   60 
   61 	`
   62 
   63 	b := hugolib.NewIntegrationTestBuilder(
   64 		hugolib.IntegrationTestConfig{
   65 			T:           t,
   66 			TxtarString: files,
   67 			NeedsOsFS:   true,
   68 		}).Build()
   69 
   70 	b.AssertFileContent("public/en/index.html", "0|February, 2020|Pages(1)1|January, 2020|Pages(1)")
   71 	b.AssertFileContent("public/fr/index.html", "0|février, 2020|Pages(1)1|janvier, 2020|Pages(1)")
   72 }
   73 
   74 func TestPagesSortCollation(t *testing.T) {
   75 
   76 	files := `
   77 -- config.toml --
   78 defaultContentLanguage = 'en'
   79 defaultContentLanguageInSubdir = true
   80 [languages]
   81 [languages.en]
   82 title = 'My blog'
   83 weight = 1
   84 [languages.fr]
   85 title = 'Mon blogue'
   86 weight = 2
   87 [languages.nn]
   88 title = 'Bloggen min'
   89 weight = 3
   90 -- content/p1.md --
   91 ---
   92 title: "zulu"
   93 date: "2020-01-01"
   94 param1: "xylophone"
   95 tags: ["xylophone", "éclair", "zulu", "emma"]
   96 ---
   97 -- content/p2.md --
   98 ---
   99 title: "émotion"
  100 date: "2020-01-01"
  101 param1: "violin"
  102 ---
  103 -- content/p3.md --
  104 ---
  105 title: "alpha"
  106 date: "2020-01-01"
  107 param1: "éclair"
  108 ---
  109 -- layouts/index.html --
  110 ByTitle: {{ range site.RegularPages.ByTitle }}{{ .Title }}|{{ end }}
  111 ByLinkTitle: {{ range site.RegularPages.ByLinkTitle }}{{ .Title }}|{{ end }}
  112 ByParam: {{ range site.RegularPages.ByParam "param1" }}{{ .Params.param1 }}|{{ end }}
  113 Tags Alphabetical: {{  range site.Taxonomies.tags.Alphabetical }}{{ .Term }}|{{ end }}
  114 GroupBy: {{ range site.RegularPages.GroupBy "Title" }}{{ .Key }}|{{ end }}
  115 {{ with (site.GetPage "p1").Params.tags }}
  116 Sort: {{  sort . }}
  117 ByWeight: {{ range site.RegularPages.ByWeight }}{{ .Title }}|{{ end }}
  118 {{ end }}
  119 
  120 	`
  121 
  122 	b := hugolib.NewIntegrationTestBuilder(
  123 		hugolib.IntegrationTestConfig{
  124 			T:           t,
  125 			TxtarString: files,
  126 			NeedsOsFS:   true,
  127 		}).Build()
  128 
  129 	b.AssertFileContent("public/en/index.html", `
  130 ByTitle: alpha|émotion|zulu|
  131 ByLinkTitle: alpha|émotion|zulu|
  132 ByParam: éclair|violin|xylophone
  133 Tags Alphabetical: éclair|emma|xylophone|zulu|
  134 GroupBy: alpha|émotion|zulu|
  135 Sort: [éclair emma xylophone zulu]
  136 ByWeight: alpha|émotion|zulu|
  137 `)
  138 }