2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2016-10-31 14:53:33 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2017-11-20 04:34:30 -05:00
|
|
|
"strings"
|
2016-10-31 14:53:33 -04:00
|
|
|
"sync"
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
"github.com/gohugoio/hugo/tpl"
|
|
|
|
|
2019-04-05 04:09:22 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/output"
|
2018-10-03 08:58:09 -04:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
|
|
|
"github.com/gohugoio/hugo/resources/page/pagemeta"
|
2016-10-31 14:53:33 -04:00
|
|
|
)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
type siteRenderContext struct {
|
|
|
|
cfg *BuildCfg
|
|
|
|
|
|
|
|
// Zero based index for all output formats combined.
|
|
|
|
sitesOutIdx int
|
|
|
|
|
|
|
|
// Zero based index of the output formats configured within a Site.
|
2019-05-02 03:54:26 -04:00
|
|
|
// Note that these outputs are sorted.
|
2019-01-02 06:33:26 -05:00
|
|
|
outIdx int
|
|
|
|
|
|
|
|
multihost bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whether to render 404.html, robotsTXT.txt which usually is rendered
|
|
|
|
// once only in the site root.
|
|
|
|
func (s siteRenderContext) renderSingletonPages() bool {
|
|
|
|
if s.multihost {
|
|
|
|
// 1 per site
|
|
|
|
return s.outIdx == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1 for all sites
|
|
|
|
return s.sitesOutIdx == 0
|
|
|
|
}
|
|
|
|
|
2016-10-31 14:53:33 -04:00
|
|
|
// renderPages renders pages each corresponding to a markdown file.
|
|
|
|
// TODO(bep np doc
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) renderPages(ctx *siteRenderContext) error {
|
2019-04-05 04:09:22 -04:00
|
|
|
numWorkers := config.GetNumWorkerMultiplier()
|
2019-04-04 10:50:10 -04:00
|
|
|
|
2016-10-31 14:53:33 -04:00
|
|
|
results := make(chan error)
|
2019-04-04 10:50:10 -04:00
|
|
|
pages := make(chan *pageState, numWorkers) // buffered for performance
|
2016-10-31 14:53:33 -04:00
|
|
|
errs := make(chan error)
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
go s.errorCollator(results, errs)
|
2016-10-31 14:53:33 -04:00
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
2017-02-21 12:56:56 -05:00
|
|
|
for i := 0; i < numWorkers; i++ {
|
2016-10-31 14:53:33 -04:00
|
|
|
wg.Add(1)
|
2019-01-02 06:33:26 -05:00
|
|
|
go pageRenderer(ctx, s, pages, results, wg)
|
2016-10-31 14:53:33 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
cfg := ctx.cfg
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
s.pageMap.pageTrees.Walk(func(ss string, n *contentNode) bool {
|
|
|
|
if cfg.shouldRender(n.p) {
|
2019-01-02 06:33:26 -05:00
|
|
|
select {
|
|
|
|
case <-s.h.Done():
|
2019-09-10 05:26:34 -04:00
|
|
|
return true
|
2019-01-02 06:33:26 -05:00
|
|
|
default:
|
2019-09-10 05:26:34 -04:00
|
|
|
pages <- n.p
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
Only re-render the view(s) you're working on
Hugo already, in its server mode, support partial rebuilds. To put it simply: If you change `about.md`, only that content page is read and processed, then Hugo does some processing (taxonomies etc.) and the full site is rendered.
This commit covers the rendering part: We now only re-render the pages you work on, i.e. the last n pages you watched in the browser (which obviously also includes the page in the example above).
To be more specific: When you are running the hugo server in watch (aka. livereload) mode, and change a template or a content file, then we do a partial re-rendering of the following:
* The current content page (if it is a content change)
* The home page
* Up to the last 10 pages you visited on the site.
This should in most cases be enough, but if you navigate to something completely different, you may see stale content. Doing an edit will then refresh that page.
Note that this feature is enabled by default. To turn it off, run `hugo server --disableFastRender`.
Fixes #3962
See #1643
2017-10-14 07:40:43 -04:00
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
return false
|
|
|
|
})
|
2016-10-31 14:53:33 -04:00
|
|
|
|
|
|
|
close(pages)
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
close(results)
|
|
|
|
|
|
|
|
err := <-errs
|
|
|
|
if err != nil {
|
2018-10-03 08:58:09 -04:00
|
|
|
return errors.Wrap(err, "failed to render pages")
|
2016-10-31 14:53:33 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func pageRenderer(
|
|
|
|
ctx *siteRenderContext,
|
|
|
|
s *Site,
|
|
|
|
pages <-chan *pageState,
|
|
|
|
results chan<- error,
|
|
|
|
wg *sync.WaitGroup) {
|
|
|
|
defer wg.Done()
|
2018-05-08 04:10:13 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for p := range pages {
|
2019-09-10 05:26:34 -04:00
|
|
|
if p.m.buildConfig.PublishResources {
|
|
|
|
if err := p.renderResources(); err != nil {
|
|
|
|
s.SendError(p.errorf(err, "failed to render page resources"))
|
|
|
|
continue
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2017-03-17 11:35:09 -04:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if !p.render {
|
|
|
|
// Nothing more to do for this page.
|
2019-04-15 06:06:12 -04:00
|
|
|
continue
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2017-04-28 03:40:50 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
templ, found, err := p.resolveTemplate()
|
2019-01-02 06:33:26 -05:00
|
|
|
if err != nil {
|
2020-01-15 09:59:56 -05:00
|
|
|
s.SendError(p.errorf(err, "failed to resolve template"))
|
2019-01-02 06:33:26 -05:00
|
|
|
continue
|
|
|
|
}
|
2017-03-02 09:35:25 -05:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
if !found {
|
2020-09-13 14:36:37 -04:00
|
|
|
s.logMissingLayout("", p.Layout(), p.Kind(), p.f.Name)
|
2019-01-02 06:33:26 -05:00
|
|
|
continue
|
|
|
|
}
|
2017-03-07 03:55:17 -05:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
targetPath := p.targetPaths().TargetFilename
|
|
|
|
|
|
|
|
if err := s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "page "+p.Title(), targetPath, p, templ); err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
results <- err
|
|
|
|
}
|
2017-03-06 13:16:31 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if p.paginator != nil && p.paginator.current != nil {
|
2020-01-15 09:59:56 -05:00
|
|
|
if err := s.renderPaginator(p, templ); err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
results <- err
|
2017-03-06 13:16:31 -05:00
|
|
|
}
|
2016-10-31 14:53:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 14:36:37 -04:00
|
|
|
func (s *Site) logMissingLayout(name, layout, kind, outputFormat string) {
|
2020-10-21 05:17:48 -04:00
|
|
|
log := s.Log.Warn()
|
2020-01-15 09:59:56 -05:00
|
|
|
if name != "" && infoOnMissingLayout[name] {
|
2020-10-21 05:17:48 -04:00
|
|
|
log = s.Log.Info()
|
2020-01-15 09:59:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
errMsg := "You should create a template file which matches Hugo Layouts Lookup Rules for this combination."
|
|
|
|
var args []interface{}
|
|
|
|
msg := "found no layout file for"
|
|
|
|
if outputFormat != "" {
|
|
|
|
msg += " %q"
|
|
|
|
args = append(args, outputFormat)
|
|
|
|
}
|
|
|
|
|
2020-09-13 14:36:37 -04:00
|
|
|
if layout != "" {
|
|
|
|
msg += " for layout %q"
|
|
|
|
args = append(args, layout)
|
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
if kind != "" {
|
|
|
|
msg += " for kind %q"
|
|
|
|
args = append(args, kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
if name != "" {
|
|
|
|
msg += " for %q"
|
|
|
|
args = append(args, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg += ": " + errMsg
|
|
|
|
|
|
|
|
log.Printf(msg, args...)
|
|
|
|
}
|
|
|
|
|
2016-10-31 14:53:33 -04:00
|
|
|
// renderPaginator must be run after the owning Page has been rendered.
|
2020-01-15 09:59:56 -05:00
|
|
|
func (s *Site) renderPaginator(p *pageState, templ tpl.Template) error {
|
2019-01-02 06:33:26 -05:00
|
|
|
paginatePath := s.Cfg.GetString("paginatePath")
|
2016-10-31 14:53:33 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
d := p.targetPathDescriptor
|
|
|
|
f := p.s.rc.Format
|
|
|
|
d.Type = f
|
2016-10-31 14:53:33 -04:00
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
if p.paginator.current == nil || p.paginator.current != p.paginator.current.First() {
|
|
|
|
panic(fmt.Sprintf("invalid paginator state for %q", p.pathOrTitle()))
|
|
|
|
}
|
2016-10-31 14:53:33 -04:00
|
|
|
|
2020-01-30 12:35:40 -05:00
|
|
|
if f.IsHTML {
|
|
|
|
// Write alias for page 1
|
|
|
|
d.Addends = fmt.Sprintf("/%s/%d", paginatePath, 1)
|
|
|
|
targetPaths := page.CreateTargetPaths(d)
|
2017-04-09 04:33:04 -04:00
|
|
|
|
2020-01-30 12:35:40 -05:00
|
|
|
if err := s.writeDestAlias(targetPaths.TargetFilename, p.Permalink(), f, nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-10-31 14:53:33 -04:00
|
|
|
}
|
2016-11-02 16:34:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Render pages for the rest
|
|
|
|
for current := p.paginator.current.Next(); current != nil; current = current.Next() {
|
2016-12-06 03:32:14 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p.paginator.current = current
|
|
|
|
d.Addends = fmt.Sprintf("/%s/%d", paginatePath, current.PageNumber())
|
|
|
|
targetPaths := page.CreateTargetPaths(d)
|
2016-11-26 09:50:32 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := s.renderAndWritePage(
|
|
|
|
&s.PathSpec.ProcessingStats.PaginatorPages,
|
|
|
|
p.Title(),
|
2020-01-15 09:59:56 -05:00
|
|
|
targetPaths.TargetFilename, p, templ); err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
return err
|
|
|
|
}
|
2017-03-25 12:46:09 -04:00
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
}
|
2016-11-02 16:34:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return nil
|
2016-11-02 16:34:19 -04:00
|
|
|
}
|
2016-11-08 17:34:52 -05:00
|
|
|
|
|
|
|
func (s *Site) render404() error {
|
2019-01-02 06:33:26 -05:00
|
|
|
p, err := newPageStandalone(&pageMeta{
|
|
|
|
s: s,
|
|
|
|
kind: kind404,
|
|
|
|
urlPaths: pagemeta.URLPath{
|
2019-03-31 06:08:15 -04:00
|
|
|
URL: "404.html",
|
2019-01-02 06:33:26 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
output.HTMLFormat,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2017-03-25 15:31:43 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if !p.render {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-26 07:14:08 -05:00
|
|
|
var d output.LayoutDescriptor
|
|
|
|
d.Kind = kind404
|
|
|
|
|
|
|
|
templ, found, err := s.Tmpl().LookupLayout(d, output.HTMLFormat)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
targetPath := p.targetPaths().TargetFilename
|
2017-04-02 06:22:54 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if targetPath == "" {
|
|
|
|
return errors.New("failed to create targetPath for 404 page")
|
2017-07-01 16:58:52 -04:00
|
|
|
}
|
2016-11-23 12:28:14 -05:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "404 page", targetPath, p, templ)
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) renderSitemap() error {
|
2019-01-02 06:33:26 -05:00
|
|
|
p, err := newPageStandalone(&pageMeta{
|
|
|
|
s: s,
|
|
|
|
kind: kindSitemap,
|
|
|
|
urlPaths: pagemeta.URLPath{
|
|
|
|
URL: s.siteCfg.sitemap.Filename,
|
2020-12-02 07:23:25 -05:00
|
|
|
},
|
|
|
|
},
|
2019-01-02 06:33:26 -05:00
|
|
|
output.HTMLFormat,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2017-03-25 15:31:43 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if !p.render {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
targetPath := p.targetPaths().TargetFilename
|
2016-11-08 17:34:52 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if targetPath == "" {
|
|
|
|
return errors.New("failed to create targetPath for sitemap")
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
templ := s.lookupLayouts("sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml")
|
2016-11-08 17:34:52 -05:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
return s.renderAndWriteXML(&s.PathSpec.ProcessingStats.Sitemaps, "sitemap", targetPath, p, templ)
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) renderRobotsTXT() error {
|
2017-02-04 22:20:06 -05:00
|
|
|
if !s.Cfg.GetBool("enableRobotsTXT") {
|
2016-11-08 17:34:52 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p, err := newPageStandalone(&pageMeta{
|
|
|
|
s: s,
|
|
|
|
kind: kindRobotsTXT,
|
|
|
|
urlPaths: pagemeta.URLPath{
|
2019-03-31 06:08:15 -04:00
|
|
|
URL: "robots.txt",
|
2019-01-02 06:33:26 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
output.RobotsTxtFormat)
|
2018-01-25 04:36:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if !p.render {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
templ := s.lookupLayouts("robots.txt", "_default/robots.txt", "_internal/_default/robots.txt")
|
2017-04-23 16:03:25 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "Robots Txt", p.targetPaths().TargetFilename, p, templ)
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// renderAliases renders shell pages that simply have a redirect in the header.
|
|
|
|
func (s *Site) renderAliases() error {
|
2019-09-10 05:26:34 -04:00
|
|
|
var err error
|
2020-10-14 05:23:24 -04:00
|
|
|
s.pageMap.pageTrees.WalkLinkable(func(ss string, n *contentNode) bool {
|
2019-09-10 05:26:34 -04:00
|
|
|
p := n.p
|
2019-01-02 06:33:26 -05:00
|
|
|
if len(p.Aliases()) == 0 {
|
2019-09-10 05:26:34 -04:00
|
|
|
return false
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
|
2020-10-14 05:23:24 -04:00
|
|
|
pathSeen := make(map[string]bool)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, of := range p.OutputFormats() {
|
|
|
|
if !of.Format.IsHTML {
|
2020-10-14 05:23:24 -04:00
|
|
|
continue
|
2017-03-24 06:25:25 -04:00
|
|
|
}
|
2016-11-15 04:43:49 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
f := of.Format
|
2017-03-24 06:25:25 -04:00
|
|
|
|
2020-10-14 05:23:24 -04:00
|
|
|
if pathSeen[f.Path] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pathSeen[f.Path] = true
|
|
|
|
|
|
|
|
plink := of.Permalink()
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, a := range p.Aliases() {
|
2019-03-30 12:08:25 -04:00
|
|
|
isRelative := !strings.HasPrefix(a, "/")
|
|
|
|
|
|
|
|
if isRelative {
|
|
|
|
// Make alias relative, where "." will be on the
|
|
|
|
// same directory level as the current page.
|
2020-06-16 19:05:53 -04:00
|
|
|
basePath := path.Join(p.targetPaths().SubResourceBaseLink, "..")
|
2019-03-30 12:08:25 -04:00
|
|
|
a = path.Join(basePath, a)
|
|
|
|
|
2020-06-14 17:33:00 -04:00
|
|
|
} else {
|
2017-03-24 06:25:25 -04:00
|
|
|
// Make sure AMP and similar doesn't clash with regular aliases.
|
2019-03-30 11:46:18 -04:00
|
|
|
a = path.Join(f.Path, a)
|
2017-03-24 06:25:25 -04:00
|
|
|
}
|
|
|
|
|
2020-06-14 17:33:00 -04:00
|
|
|
if s.UglyURLs && !strings.HasSuffix(a, ".html") {
|
|
|
|
a += ".html"
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
lang := p.Language().Lang
|
2017-11-20 04:34:30 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if s.h.multihost && !strings.HasPrefix(a, "/"+lang) {
|
2017-11-20 04:34:30 -05:00
|
|
|
// These need to be in its language root.
|
|
|
|
a = path.Join(lang, a)
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
err = s.writeDestAlias(a, plink, f, p)
|
|
|
|
if err != nil {
|
|
|
|
return true
|
2017-03-24 06:25:25 -04:00
|
|
|
}
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
return false
|
|
|
|
})
|
2016-11-08 17:34:52 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
return err
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// renderMainLanguageRedirect creates a redirect to the main language home,
|
|
|
|
// depending on if it lives in sub folder (e.g. /en) or not.
|
|
|
|
func (s *Site) renderMainLanguageRedirect() error {
|
|
|
|
if !s.h.multilingual.enabled() || s.h.IsMultihost() {
|
|
|
|
// No need for a redirect
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
html, found := s.outputFormatsConfig.GetByName("HTML")
|
|
|
|
if found {
|
|
|
|
mainLang := s.h.multilingual.DefaultLang
|
|
|
|
if s.Info.defaultContentLanguageInSubdir {
|
2020-06-14 05:14:56 -04:00
|
|
|
mainLangURL := s.PathSpec.AbsURL(mainLang.Lang+"/", false)
|
2020-10-21 05:17:48 -04:00
|
|
|
s.Log.Debug().Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := s.publishDestAlias(true, "/", mainLangURL, html, nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mainLangURL := s.PathSpec.AbsURL("", false)
|
2020-10-21 05:17:48 -04:00
|
|
|
s.Log.Debug().Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := s.publishDestAlias(true, mainLang.Lang, mainLangURL, html, nil); err != nil {
|
|
|
|
return err
|
2016-11-08 17:34:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|