Multilingual TODO-fixes, take 1

See #2309
This commit is contained in:
Bjørn Erik Pedersen 2016-08-08 00:12:06 +02:00
parent 0a7d1d0ddc
commit e56ecab157
14 changed files with 34 additions and 105 deletions

View file

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

View file

@ -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

View file

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

View file

@ -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 {

View file

@ -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

View file

@ -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 {
@ -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()
}
}

View file

@ -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")

View file

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

View file

@ -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
@ -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
@ -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
@ -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
}

View file

@ -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

View file

@ -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}
}
@ -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
@ -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]}
}
@ -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
}
@ -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"))
}

View file

@ -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)

View file

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

View file

@ -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)