Skip to content

Commit

Permalink
Multilingual TODO-fixes, take 1
Browse files Browse the repository at this point in the history
  • Loading branch information
bep authored and tychoish committed Aug 13, 2017
1 parent 560a9bc commit 06c0472
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 105 deletions.
14 changes: 12 additions & 2 deletions commands/hugo.go
Expand Up @@ -630,11 +630,17 @@ func getDirList() []string {
}

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})
}
Expand All @@ -655,13 +661,17 @@ func initSites() error {
}

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...)
}

Expand Down
18 changes: 0 additions & 18 deletions helpers/content.go
Expand Up @@ -396,24 +396,6 @@ func WordCount(s string) map[string]int {
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
Expand Down
10 changes: 0 additions & 10 deletions helpers/content_test.go
Expand Up @@ -409,13 +409,3 @@ func TestWordCount(t *testing.T) {
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)
}
}
1 change: 0 additions & 1 deletion helpers/url.go
Expand Up @@ -186,7 +186,6 @@ func getLanguagePrefix() string {
}

// 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 {
Expand Down
5 changes: 0 additions & 5 deletions hugolib/handler_page.go
Expand Up @@ -104,15 +104,10 @@ func commonConvert(p *Page, t tpl.Template) HandledResult {

// 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
Expand Down
6 changes: 2 additions & 4 deletions hugolib/hugo_sites.go
Expand Up @@ -62,8 +62,7 @@ func createSitesFromConfig() ([]*Site, error) {
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 {
Expand All @@ -85,10 +84,9 @@ func createSitesFromConfig() ([]*Site, error) {
}

// 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()
}
}

Expand Down
4 changes: 1 addition & 3 deletions hugolib/hugo_sites_test.go
Expand Up @@ -73,9 +73,7 @@ func TestMultiSitesBuild(t *testing.T) {
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")

Expand Down
10 changes: 0 additions & 10 deletions hugolib/multilingual.go
Expand Up @@ -75,15 +75,6 @@ func (s *Site) multilingualEnabled() bool {
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
Expand All @@ -107,7 +98,6 @@ func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) {
}

// Put all into the Params map
// TODO(bep) ml reconsile with the type handling etc. from other params handlers.
language.SetParam(loki, v)
}

Expand Down
7 changes: 2 additions & 5 deletions hugolib/node.go
Expand Up @@ -49,7 +49,7 @@ type Node struct {

language *helpers.Language
languageInit sync.Once
lang string // TODO(bep) multilingo
lang string

translations Nodes
translationsInit sync.Once
Expand Down Expand Up @@ -168,7 +168,6 @@ func (n *Node) RelRef(ref string) (string, error) {
return n.Site.RelRef(ref, nil)
}

// TODO(bep) multilingo some of these are now hidden. Consider unexport.
type URLPath struct {
URL string
Permalink string
Expand All @@ -192,7 +191,6 @@ func (n *Node) Scratch() *Scratch {
return n.scratch
}

// TODO(bep) multilingo consolidate. See Page.
func (n *Node) Language() *helpers.Language {
n.initLanguage()
return n.language
Expand Down Expand Up @@ -223,8 +221,7 @@ func (n *Node) initLanguage() {
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
}
Expand Down
19 changes: 0 additions & 19 deletions hugolib/page.go
Expand Up @@ -327,25 +327,6 @@ func (p *Page) setAutoSummary() error {
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
Expand Down
38 changes: 17 additions & 21 deletions hugolib/site.go
Expand Up @@ -99,9 +99,8 @@ type Site struct {
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}
}

Expand Down Expand Up @@ -144,21 +143,20 @@ type targetList struct {
}

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
Expand Down Expand Up @@ -701,7 +699,6 @@ func (s *Site) readI18nSources() error {

themeI18nDir, err := helpers.GetThemeI18nDirPath()
if err == nil {
// TODO(bep) multilingo what is this?
i18nSources = []source.Input{&source.Filesystem{Base: themeI18nDir}, i18nSources[0]}
}

Expand Down Expand Up @@ -1622,7 +1619,7 @@ func (s *Site) newTaxonomyNode(t taxRenderInfo) (*Node, string) {
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
}
Expand Down Expand Up @@ -1992,7 +1989,6 @@ func (s *Site) Stats() {
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"))
}

Expand Down
2 changes: 0 additions & 2 deletions hugolib/site_test.go
Expand Up @@ -216,9 +216,7 @@ func TestFutureExpirationRender(t *testing.T) {
}

// 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)
Expand Down
1 change: 0 additions & 1 deletion hugolib/translations.go
Expand Up @@ -50,7 +50,6 @@ func assignTranslationsToPages(allTranslations map[string]Translations, pages []
continue
}

// TODO(bep) multilingo remove lang
for _, translatedPage := range trans {
page.translations = append(page.translations, translatedPage)
}
Expand Down
4 changes: 0 additions & 4 deletions source/file.go
Expand Up @@ -129,10 +129,6 @@ func NewFile(relpath string) *File {
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)

Expand Down

0 comments on commit 06c0472

Please sign in to comment.