hugolib, target: Rework/move the target package

This relates to #3123.

The interfaces and types in `target` made sense at some point, but now this package is too restricted to a hardcoded set of media types.

The overall current logic:

* Create a file path based on some `Translator` with some hardcoded logic handling uglyURLs, hardcoded html suffix etc.
* In in some cases (alias), a template is applied to create the alias file.
* Then the content is written to destination.

One could argue that it is the last bullet that is the actual core responsibility.

This commit fixes that by moving the `hugolib`-related logic where it belong, and simplify the code, i.e. remove the abstractions.

This code will most certainly evolve once we start on #3123, but now it is at least possible to understand where to start.

Fixes #3123
This commit is contained in:
Bjørn Erik Pedersen
2017-03-03 10:47:43 +01:00
parent ea165bf9e7
commit e52e2a70e5
13 changed files with 374 additions and 546 deletions

View File

@@ -257,7 +257,7 @@ func (s *Site) renderRobotsTXT() error {
err := s.renderForLayouts("robots", n, outBuffer, s.appendThemeTemplates(rLayouts)...)
if err == nil {
err = s.writeDestFile("robots.txt", outBuffer)
err = s.w.writeDestFile("robots.txt", outBuffer)
}
return err
@@ -284,13 +284,13 @@ func (s *Site) renderAliases() error {
if s.Info.defaultContentLanguageInSubdir {
mainLangURL := s.PathSpec.AbsURL(mainLang.Lang, false)
s.Log.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
if err := s.publishDestAlias(s.languageAliasTarget(), "/", mainLangURL, nil); err != nil {
if err := s.publishDestAlias(true, "/", mainLangURL, nil); err != nil {
return err
}
} else {
mainLangURL := s.PathSpec.AbsURL("", false)
s.Log.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
if err := s.publishDestAlias(s.languageAliasTarget(), mainLang.Lang, mainLangURL, nil); err != nil {
if err := s.publishDestAlias(true, mainLang.Lang, mainLangURL, nil); err != nil {
return err
}
}