git.greeks.studio/lethews/hugo@v0.47.1/hugolib/sitemap.go (about)

     1  // Copyright 2015 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 hugolib
    15  
    16  import (
    17  	"github.com/spf13/cast"
    18  	jww "github.com/spf13/jwalterweatherman"
    19  )
    20  
    21  // Sitemap configures the sitemap to be generated.
    22  type Sitemap struct {
    23  	ChangeFreq string
    24  	Priority   float64
    25  	Filename   string
    26  }
    27  
    28  func parseSitemap(input map[string]interface{}) Sitemap {
    29  	sitemap := Sitemap{Priority: -1, Filename: "sitemap.xml"}
    30  
    31  	for key, value := range input {
    32  		switch key {
    33  		case "changefreq":
    34  			sitemap.ChangeFreq = cast.ToString(value)
    35  		case "priority":
    36  			sitemap.Priority = cast.ToFloat64(value)
    37  		case "filename":
    38  			sitemap.Filename = cast.ToString(value)
    39  		default:
    40  			jww.WARN.Printf("Unknown Sitemap field: %s\n", key)
    41  		}
    42  	}
    43  
    44  	return sitemap
    45  }