shithub: hugo

Download patch

ref: e56ecab1575f1b25552988b9efff2836f05f87f9
parent: 0a7d1d0ddc213628fcde7c0e24991246836d9f16
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Aug 7 20:12:06 EDT 2016

Multilingual TODO-fixes, take 1

See #2309

--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -630,11 +630,17 @@
 }
 
 func reCreateAndbuildSites(watching bool) (err error) {
+	if err := initSites(); err != nil {
+		return err
+	}
 	fmt.Println("Started building sites ...")
 	return Hugo.Build(hugolib.BuildCfg{CreateSitesFromConfig: true, Watching: watching, PrintStats: true})
 }
 
 func resetAndbuildSites(watching bool) (err error) {
+	if err := initSites(); err != nil {
+		return err
+	}
 	fmt.Println("Started building sites ...")
 	return Hugo.Build(hugolib.BuildCfg{ResetState: true, Watching: watching, PrintStats: true})
 }
@@ -655,13 +661,17 @@
 }
 
 func buildSites(watching bool) (err error) {
-	initSites()
+	if err := initSites(); err != nil {
+		return err
+	}
 	fmt.Println("Started building sites ...")
 	return Hugo.Build(hugolib.BuildCfg{Watching: watching, PrintStats: true})
 }
 
 func rebuildSites(events []fsnotify.Event) error {
-	initSites()
+	if err := initSites(); err != nil {
+		return err
+	}
 	return Hugo.Rebuild(hugolib.BuildCfg{PrintStats: true, Watching: true}, events...)
 }
 
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -396,24 +396,6 @@
 	return m
 }
 
-// RemoveSummaryDivider removes summary-divider <!--more--> from content.
-// TODO(bep) ml remove
-func RemoveSummaryDivider(content []byte) []byte {
-	b := bytes.Replace(content, summaryDividerAndNewLines, []byte(""), 1)
-	if len(b) != len(content) {
-		return b
-	}
-	return bytes.Replace(content, SummaryDivider, []byte(""), 1)
-}
-
-func removeInternalSummaryDivider(content []byte) []byte {
-	b := bytes.Replace(content, summaryDividerAndNewLines, []byte(""), 1)
-	if len(b) != len(content) {
-		return b
-	}
-	return bytes.Replace(content, SummaryDivider, []byte(""), 1)
-}
-
 // TruncateWordsByRune truncates words by runes.
 func TruncateWordsByRune(words []string, max int) (string, bool) {
 	count := 0
--- a/helpers/content_test.go
+++ b/helpers/content_test.go
@@ -409,13 +409,3 @@
 		t.Errorf("Actual Map (%v) does not equal expected (%v)", actualMap, expectedMap)
 	}
 }
-
-func TestRemoveSummaryDivider(t *testing.T) {
-	content := []byte("This is before. <!--more-->This is after.")
-	actualRemovedContent := RemoveSummaryDivider(content)
-	expectedRemovedContent := []byte("This is before. This is after.")
-
-	if !bytes.Equal(actualRemovedContent, expectedRemovedContent) {
-		t.Errorf("Actual removed content (%s) did not equal expected removed content (%s)", actualRemovedContent, expectedRemovedContent)
-	}
-}
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -186,7 +186,6 @@
 }
 
 // IsAbsURL determines whether the given path points to an absolute URL.
-// TODO(bep) ml tests
 func IsAbsURL(path string) bool {
 	url, err := url.Parse(path)
 	if err != nil {
--- a/hugolib/handler_page.go
+++ b/hugolib/handler_page.go
@@ -104,15 +104,10 @@
 
 	// TODO(bep) these page handlers need to be re-evaluated, as it is hard to
 	// process a page in isolation. See the new preRender func.
-	// TODO(bep) ml not so raw anymore, but do we need to keep it raw?
 	if viper.GetBool("EnableEmoji") {
 		p.rawContent = helpers.Emojify(p.rawContent)
 	}
 
-	// TODO(bep) ml we let the summary divider survive the rendering. Must check if
-	// it actually survives, replace it with something more robus, or maybe
-	// rethink this fragile concept.
-	//p.rawContent = p.renderContent(helpers.RemoveSummaryDivider(p.rawContent))
 	// We have to replace the <!--more--> with something that survives all the
 	// rendering engines.
 	// TODO(bep) inline replace
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -62,8 +62,7 @@
 	var sites []*Site
 	multilingual := viper.GetStringMap("Languages")
 	if len(multilingual) == 0 {
-		// TODO(bep) multilingo langConfigsList = append(langConfigsList, NewLanguage("en"))
-		sites = append(sites, newSite(helpers.NewLanguage("en")))
+		sites = append(sites, newSite(helpers.NewDefaultLanguage()))
 	}
 
 	if len(multilingual) > 0 {
@@ -85,10 +84,9 @@
 }
 
 // Reset resets the sites, making it ready for a full rebuild.
-// TODO(bep) multilingo
 func (h *HugoSites) reset() {
 	for i, s := range h.Sites {
-		h.Sites[i] = s.Reset()
+		h.Sites[i] = s.reset()
 	}
 }
 
--- a/hugolib/hugo_sites_test.go
+++ b/hugolib/hugo_sites_test.go
@@ -73,9 +73,7 @@
 	assert.NoError(t, err, "permalink call failed")
 	assert.Equal(t, "http://example.com/blog/superbob", permalink, "invalid doc3 permalink")
 
-	// TODO(bep) multilingo. Check this case. This has url set in frontmatter, but we must split into lang folders
-	// The assertion below was missing the /en prefix.
-	assert.Equal(t, "/en/superbob", doc3.URL(), "invalid url, was specified on doc3 TODO(bep)")
+	assert.Equal(t, "/en/superbob", doc3.URL(), "invalid url, was specified on doc3")
 
 	assert.Equal(t, doc2.Next, doc3, "doc3 should follow doc2, in .Next")
 
--- a/hugolib/multilingual.go
+++ b/hugolib/multilingual.go
@@ -75,15 +75,6 @@
 	return s.Multilingual != nil && s.Multilingual.enabled()
 }
 
-// TODO(bep) multilingo remove these
-func (s *Site) currentLanguageString() string {
-	return s.currentLanguage().Lang
-}
-
-func (s *Site) currentLanguage() *helpers.Language {
-	return s.Language
-}
-
 func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) {
 	langs := make(helpers.Languages, len(l))
 	i := 0
@@ -107,7 +98,6 @@
 			}
 
 			// Put all into the Params map
-			// TODO(bep) ml reconsile with the type handling etc. from other params handlers.
 			language.SetParam(loki, v)
 		}
 
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -49,7 +49,7 @@
 
 	language     *helpers.Language
 	languageInit sync.Once
-	lang         string // TODO(bep) multilingo
+	lang         string
 
 	translations     Nodes
 	translationsInit sync.Once
@@ -168,7 +168,6 @@
 	return n.Site.RelRef(ref, nil)
 }
 
-// TODO(bep) multilingo some of these are now hidden. Consider unexport.
 type URLPath struct {
 	URL       string
 	Permalink string
@@ -192,7 +191,6 @@
 	return n.scratch
 }
 
-// TODO(bep) multilingo consolidate. See Page.
 func (n *Node) Language() *helpers.Language {
 	n.initLanguage()
 	return n.language
@@ -223,8 +221,7 @@
 		language := ml.Language(pageLang)
 
 		if language == nil {
-			// TODO(bep) ml
-			// This may or may not be serious. It can be a file named stefano.chiodino.md.
+			// It can be a file named stefano.chiodino.md.
 			jww.WARN.Printf("Page language (if it is that) not found in multilang setup: %s.", pageLang)
 			language = ml.DefaultLang
 		}
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -327,25 +327,6 @@
 	return nil
 }
 
-// TODO(bep) ml not used???
-func (p *Page) _renderBytes(content []byte) []byte {
-	var fn helpers.LinkResolverFunc
-	var fileFn helpers.FileResolverFunc
-	if p.getRenderingConfig().SourceRelativeLinksEval {
-		fn = func(ref string) (string, error) {
-			return p.Node.Site.SourceRelativeLink(ref, p)
-		}
-		fileFn = func(ref string) (string, error) {
-			return p.Node.Site.SourceRelativeLinkFile(ref, p)
-		}
-	}
-	return helpers.RenderBytes(
-		&helpers.RenderingContext{
-			Content: content, PageFmt: p.determineMarkupType(),
-			ConfigProvider: p.Language(),
-			DocumentID:     p.UniqueID(), Config: p.getRenderingConfig(), LinkResolver: fn, FileResolver: fileFn})
-}
-
 func (p *Page) renderContent(content []byte) []byte {
 	var fn helpers.LinkResolverFunc
 	var fileFn helpers.FileResolverFunc
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -99,9 +99,8 @@
 	Language     *helpers.Language
 }
 
-// Reset returns a new Site prepared for rebuild.
-// TODO(bep) multilingo
-func (s *Site) Reset() *Site {
+// reset returns a new Site prepared for rebuild.
+func (s *Site) reset() *Site {
 	return &Site{Language: s.Language, Multilingual: s.Multilingual}
 }
 
@@ -144,21 +143,20 @@
 }
 
 type SiteInfo struct {
-	BaseURL     template.URL
-	Taxonomies  TaxonomyList
-	Authors     AuthorList
-	Social      SiteSocial
-	Sections    Taxonomy
-	Pages       *Pages // Includes only pages in this language
-	AllPages    *Pages // Includes other translated pages, excluding those in this language.
-	rawAllPages *Pages // Includes absolute all pages, including drafts etc.
-	Files       *[]*source.File
-	Menus       *Menus
-	Hugo        *HugoInfo
-	Title       string
-	RSSLink     string
-	Author      map[string]interface{}
-	// TODO(bep) multilingo
+	BaseURL               template.URL
+	Taxonomies            TaxonomyList
+	Authors               AuthorList
+	Social                SiteSocial
+	Sections              Taxonomy
+	Pages                 *Pages // Includes only pages in this language
+	AllPages              *Pages // Includes other translated pages, excluding those in this language.
+	rawAllPages           *Pages // Includes absolute all pages, including drafts etc.
+	Files                 *[]*source.File
+	Menus                 *Menus
+	Hugo                  *HugoInfo
+	Title                 string
+	RSSLink               string
+	Author                map[string]interface{}
 	LanguageCode          string
 	DisqusShortname       string
 	GoogleAnalytics       string
@@ -701,7 +699,6 @@
 
 	themeI18nDir, err := helpers.GetThemeI18nDirPath()
 	if err == nil {
-		// TODO(bep) multilingo what is this?
 		i18nSources = []source.Input{&source.Filesystem{Base: themeI18nDir}, i18nSources[0]}
 	}
 
@@ -1622,7 +1619,7 @@
 func (s *Site) addMultilingualPrefix(basePath string) string {
 	hadPrefix := strings.HasPrefix(basePath, "/")
 	if s.multilingualEnabled() {
-		basePath = path.Join(s.currentLanguageString(), basePath)
+		basePath = path.Join(s.Language.Lang, basePath)
 		if hadPrefix {
 			basePath = "/" + basePath
 		}
@@ -1992,7 +1989,6 @@
 func (s *Site) setURLs(n *Node, in string) {
 	n.URLPath.URL = helpers.URLizeAndPrep(in)
 	n.URLPath.Permalink = permalink(n.URLPath.URL)
-	// TODO(bep) multilingo
 	n.RSSLink = template.HTML(permalink(in + ".xml"))
 }
 
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -216,9 +216,7 @@
 }
 
 // Issue #957
-// TODO(bep) ml
 func TestCrossrefs(t *testing.T) {
-	hugofs.InitMemFs()
 	for _, uglyURLs := range []bool{true, false} {
 		for _, relative := range []bool{true, false} {
 			doTestCrossrefs(t, relative, uglyURLs)
--- a/hugolib/translations.go
+++ b/hugolib/translations.go
@@ -50,7 +50,6 @@
 			continue
 		}
 
-		// TODO(bep) multilingo remove lang
 		for _, translatedPage := range trans {
 			page.translations = append(page.translations, translatedPage)
 		}
--- a/source/file.go
+++ b/source/file.go
@@ -129,10 +129,6 @@
 	f.lang = strings.TrimPrefix(filepath.Ext(f.baseName), ".")
 	if f.lang == "" {
 		f.lang = viper.GetString("DefaultContentLanguage")
-		if f.lang == "" {
-			// TODO(bep) ml
-			f.lang = "en"
-		}
 	}
 	f.translationBaseName = helpers.Filename(f.baseName)