From 523f38a9a8f27261d5d95afadfee18489a3b50c1 Mon Sep 17 00:00:00 2001 From: Dan Hersam Date: Thu, 29 Jan 2015 13:30:51 -0500 Subject: [PATCH 1/7] Fix for issue 839 and 490 on Windows The paths were seen as changed but not static because of the backslashes in ev.Name. Once the backslashes were added, I discovered that the JSON sent to livereload was invalid and failed to work because it had backslashes. Hence the code to replace the backslashes from the path to make them work in JSON and for the URL. With this fix, changes to a stylesheet are shown on the page, and if it's a single file that changed, it's reflected in the browser without reloading the whole page. --- commands/hugo.go | 2 +- helpers/path.go | 12 ++++++++++-- livereload/livereload.go | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/commands/hugo.go b/commands/hugo.go index cce37a5f9..e53804f1c 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -358,7 +358,7 @@ func NewWatcher(port int) error { continue } - isstatic := strings.HasPrefix(ev.Name, helpers.AbsPathify(viper.GetString("StaticDir"))) || strings.HasPrefix(ev.Name, helpers.AbsPathify("themes/"+viper.GetString("theme"))+"/static/") + isstatic := strings.HasPrefix(ev.Name, helpers.GetStaticDirPath()) || strings.HasPrefix(ev.Name, helpers.GetThemesDirPath()) static_changed = static_changed || isstatic dynamic_changed = dynamic_changed || !isstatic diff --git a/helpers/path.go b/helpers/path.go index 3351e0265..7965a6ada 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -174,9 +174,17 @@ func AbsPathify(inPath string) string { return filepath.Clean(filepath.Join(viper.GetString("WorkingDir"), inPath)) } +func GetStaticDirPath() string { + return AbsPathify(viper.GetString("StaticDir")) +} + +func GetThemesDirPath() string { + return AbsPathify(filepath.Join("themes", viper.GetString("theme"), "static")) +} + func MakeStaticPathRelative(inPath string) (string, error) { - staticDir := AbsPathify(viper.GetString("StaticDir")) - themeStaticDir := AbsPathify("themes/"+viper.GetString("theme")) + "/static/" + staticDir := GetStaticDirPath() + themeStaticDir := GetThemesDirPath() return MakePathRelative(inPath, staticDir, themeStaticDir) } diff --git a/livereload/livereload.go b/livereload/livereload.go index 1b1546158..a47a7b687 100644 --- a/livereload/livereload.go +++ b/livereload/livereload.go @@ -15,6 +15,7 @@ package livereload import ( "net/http" + "strings" "github.com/gorilla/websocket" ) @@ -44,7 +45,8 @@ func ForceRefresh() { func RefreshPath(s string) { // Tell livereload a file has changed - will force a hard refresh if not CSS or an image - wsHub.broadcast <- []byte(`{"command":"reload","path":"` + s + "\"" + `,"originalPath":"","liveCSS":true,"liveImg":true}`) + url_path := strings.Replace(s, "\\", "/", -1) // If path has backslashes on Windows, make path work for URL + wsHub.broadcast <- []byte(`{"command":"reload","path":"` + url_path + "\"" + `,"originalPath":"","liveCSS":true,"liveImg":true}`) } func ServeJS(w http.ResponseWriter, r *http.Request) { From ba53799fdb7c59af8733df2027d245584ca6749f Mon Sep 17 00:00:00 2001 From: bep Date: Fri, 30 Jan 2015 16:21:46 +0100 Subject: [PATCH 2/7] url_path => urlPath --- livereload/livereload.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/livereload/livereload.go b/livereload/livereload.go index a47a7b687..07e640d05 100644 --- a/livereload/livereload.go +++ b/livereload/livereload.go @@ -45,8 +45,8 @@ func ForceRefresh() { func RefreshPath(s string) { // Tell livereload a file has changed - will force a hard refresh if not CSS or an image - url_path := strings.Replace(s, "\\", "/", -1) // If path has backslashes on Windows, make path work for URL - wsHub.broadcast <- []byte(`{"command":"reload","path":"` + url_path + "\"" + `,"originalPath":"","liveCSS":true,"liveImg":true}`) + urlPath := strings.Replace(s, "\\", "/", -1) // If path has backslashes on Windows, make path work for URL + wsHub.broadcast <- []byte(`{"command":"reload","path":"` + urlPath + "\"" + `,"originalPath":"","liveCSS":true,"liveImg":true}`) } func ServeJS(w http.ResponseWriter, r *http.Request) { From 366c557251c73288987a700c63d148a69e9f0ec0 Mon Sep 17 00:00:00 2001 From: Jeffrey Tolar Date: Wed, 28 Jan 2015 21:11:41 -0600 Subject: [PATCH 3/7] Use a regular expression in replaceShortcodeTokens This fixes a bug where a shortcode needs to be expanded multiple times, which can arise in practice when using reference links. --- hugolib/handler_page.go | 4 +- hugolib/page.go | 3 +- hugolib/shortcode.go | 77 +++++++++++++++------------------------ hugolib/shortcode_test.go | 31 ++++++++-------- 4 files changed, 49 insertions(+), 66 deletions(-) diff --git a/hugolib/handler_page.go b/hugolib/handler_page.go index 6c912ded3..b3b236344 100644 --- a/hugolib/handler_page.go +++ b/hugolib/handler_page.go @@ -60,7 +60,7 @@ func (h markdownHandler) PageConvert(p *Page, t tpl.Template) HandledResult { tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.renderContent(helpers.RemoveSummaryDivider(p.rawContent))) if len(p.contentShortCodes) > 0 { - tmpContentWithTokensReplaced, err := replaceShortcodeTokens(tmpContent, shortcodePlaceholderPrefix, -1, true, p.contentShortCodes) + tmpContentWithTokensReplaced, err := replaceShortcodeTokens(tmpContent, shortcodePlaceholderPrefix, true, p.contentShortCodes) if err != nil { jww.FATAL.Printf("Fail to replace short code tokens in %s:\n%s", p.BaseFileName(), err.Error()) @@ -113,7 +113,7 @@ func (h rstHandler) PageConvert(p *Page, t tpl.Template) HandledResult { tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.renderContent(helpers.RemoveSummaryDivider(p.rawContent))) if len(p.contentShortCodes) > 0 { - tmpContentWithTokensReplaced, err := replaceShortcodeTokens(tmpContent, shortcodePlaceholderPrefix, -1, true, p.contentShortCodes) + tmpContentWithTokensReplaced, err := replaceShortcodeTokens(tmpContent, shortcodePlaceholderPrefix, true, p.contentShortCodes) if err != nil { jww.FATAL.Printf("Fail to replace short code tokens in %s:\n%s", p.BaseFileName(), err.Error()) diff --git a/hugolib/page.go b/hugolib/page.go index ffbe7772b..9a96b8360 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -162,10 +162,9 @@ func (p *Page) setSummary() { p.Truncated = true // by definition header := bytes.Split(p.rawContent, helpers.SummaryDivider)[0] renderedHeader := p.renderBytes(header) - numShortcodesInHeader := bytes.Count(header, []byte(shortcodePlaceholderPrefix)) if len(p.contentShortCodes) > 0 { tmpContentWithTokensReplaced, err := - replaceShortcodeTokens(renderedHeader, shortcodePlaceholderPrefix, numShortcodesInHeader, true, p.contentShortCodes) + replaceShortcodeTokens(renderedHeader, shortcodePlaceholderPrefix, true, p.contentShortCodes) if err != nil { jww.FATAL.Printf("Failed to replace short code tokens in Summary for %s:\n%s", p.BaseFileName(), err.Error()) } else { diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 03cd7d4a7..9458b3961 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -20,7 +20,6 @@ import ( "reflect" "regexp" "sort" - "strconv" "strings" "sync" @@ -132,7 +131,7 @@ func ShortcodesHandle(stringToParse string, page *Page, t tpl.Template) string { tmpContent, tmpShortcodes := extractAndRenderShortcodes(stringToParse, page, t) if len(tmpShortcodes) > 0 { - tmpContentWithTokensReplaced, err := replaceShortcodeTokens([]byte(tmpContent), shortcodePlaceholderPrefix, -1, true, tmpShortcodes) + tmpContentWithTokensReplaced, err := replaceShortcodeTokens([]byte(tmpContent), shortcodePlaceholderPrefix, true, tmpShortcodes) if err != nil { jww.ERROR.Printf("Fail to replace short code tokens in %s:\n%s", page.BaseFileName(), err.Error()) @@ -428,60 +427,44 @@ Loop: } // Replace prefixed shortcode tokens (HUGOSHORTCODE-1, HUGOSHORTCODE-2) with the real content. -// This assumes that all tokens exist in the input string and that they are in order. -// numReplacements = -1 will do len(replacements), and it will always start from the beginning (1) // wrapped = true means that the token has been wrapped in {@{@/@}@} -func replaceShortcodeTokens(source []byte, prefix string, numReplacements int, wrapped bool, replacements map[string]string) ([]byte, error) { +func replaceShortcodeTokens(source []byte, prefix string, wrapped bool, replacements map[string]string) (b []byte, err error) { + var re *regexp.Regexp - if numReplacements < 0 { - numReplacements = len(replacements) - } - - if numReplacements == 0 { - return source, nil - } - - newLen := len(source) - - for i := 1; i <= numReplacements; i++ { - key := prefix + "-" + strconv.Itoa(i) - - if wrapped { - key = "{@{@" + key + "@}@}" + if wrapped { + re, err = regexp.Compile(`\{@\{@` + regexp.QuoteMeta(prefix) + `-\d+@\}@\}`) + if err != nil { + return nil, err + } + } else { + re, err = regexp.Compile(regexp.QuoteMeta(prefix) + `-(\d+)`) + if err != nil { + return nil, err } - val := []byte(replacements[key]) - - newLen += (len(val) - len(key)) } - buff := make([]byte, newLen) - - width := 0 - start := 0 - - for i := 0; i < numReplacements; i++ { - tokenNum := i + 1 - oldVal := prefix + "-" + strconv.Itoa(tokenNum) - if wrapped { - oldVal = "{@{@" + oldVal + "@}@}" + // use panic/recover for reporting if an unknown + defer func() { + if r := recover(); r != nil { + var ok bool + b = nil + err, ok = r.(error) + if !ok { + err = fmt.Errorf("unexpected panic during replaceShortcodeTokens: %v", r) + } } - newVal := []byte(replacements[oldVal]) - j := start + }() + b = re.ReplaceAllFunc(source, func(m []byte) []byte { + key := string(m) - k := bytes.Index(source[start:], []byte(oldVal)) - - if k < 0 { - // this should never happen, but let the caller decide to panic or not - return nil, fmt.Errorf("illegal state in content; shortcode token #%d is missing or out of order (%q)", tokenNum, source) + if val, ok := replacements[key]; ok { + return []byte(val) + } else { + panic(fmt.Errorf("unknown shortcode token %q", key)) } - j += k + }) - width += copy(buff[width:], source[start:j]) - width += copy(buff[width:], newVal) - start = j + len(oldVal) - } - width += copy(buff[width:], source[start:]) - return buff[0:width], nil + return b, err } func GetTemplate(name string, t tpl.Template) *template.Template { diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 06f36aebd..ad966b286 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -281,23 +281,24 @@ func collectAndShortShortcodes(shortcodes map[string]shortcode) []string { func TestReplaceShortcodeTokens(t *testing.T) { for i, this := range []struct { - input []byte - prefix string - replacements map[string]string - numReplacements int - wrappedInDiv bool - expect interface{} + input []byte + prefix string + replacements map[string]string + wrappedInDiv bool + expect interface{} }{ - {[]byte("Hello PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "World"}, -1, false, []byte("Hello World.")}, - {[]byte("A {@{@A-1@}@} asdf {@{@A-2@}@}."), "A", map[string]string{"{@{@A-1@}@}": "v1", "{@{@A-2@}@}": "v2"}, -1, true, []byte("A v1 asdf v2.")}, - {[]byte("Hello PREFIX2-1. Go PREFIX2-2, Go, Go PREFIX2-3 Go Go!."), "PREFIX2", map[string]string{"PREFIX2-1": "Europe", "PREFIX2-2": "Jonny", "PREFIX2-3": "Johnny"}, -1, false, []byte("Hello Europe. Go Jonny, Go, Go Johnny Go Go!.")}, - {[]byte("A PREFIX-2 PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, -1, false, false}, - {[]byte("A PREFIX-1 PREFIX-2"), "PREFIX", map[string]string{"PREFIX-1": "A"}, -1, false, []byte("A A PREFIX-2")}, - {[]byte("A PREFIX-1 but not the second."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, -1, false, false}, - {[]byte("An PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, 1, false, []byte("An A.")}, - {[]byte("An PREFIX-1 PREFIX-2."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, 1, false, []byte("An A PREFIX-2.")}, + {[]byte("Hello PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "World"}, false, []byte("Hello World.")}, + {[]byte("A {@{@A-1@}@} asdf {@{@A-2@}@}."), "A", map[string]string{"{@{@A-1@}@}": "v1", "{@{@A-2@}@}": "v2"}, true, []byte("A v1 asdf v2.")}, + {[]byte("Hello PREFIX2-1. Go PREFIX2-2, Go, Go PREFIX2-3 Go Go!."), "PREFIX2", map[string]string{"PREFIX2-1": "Europe", "PREFIX2-2": "Jonny", "PREFIX2-3": "Johnny"}, false, []byte("Hello Europe. Go Jonny, Go, Go Johnny Go Go!.")}, + {[]byte("A PREFIX-2 PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("A B A.")}, + {[]byte("A PREFIX-1 PREFIX-2"), "PREFIX", map[string]string{"PREFIX-1": "A"}, false, false}, + {[]byte("A PREFIX-1 but not the second."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("A A but not the second.")}, + {[]byte("An PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("An A.")}, + {[]byte("An PREFIX-1 PREFIX-2."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("An A B.")}, + {[]byte("A PREFIX-1 PREFIX-2 PREFIX-3 PREFIX-1 PREFIX-3."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B", "PREFIX-3": "C"}, false, []byte("A A B C A C.")}, + {[]byte("A {@{@PREFIX-1@}@} {@{@PREFIX-2@}@} {@{@PREFIX-3@}@} {@{@PREFIX-1@}@} {@{@PREFIX-3@}@}."), "PREFIX", map[string]string{"{@{@PREFIX-1@}@}": "A", "{@{@PREFIX-2@}@}": "B", "{@{@PREFIX-3@}@}": "C"}, true, []byte("A A B C A C.")}, } { - results, err := replaceShortcodeTokens(this.input, this.prefix, this.numReplacements, this.wrappedInDiv, this.replacements) + results, err := replaceShortcodeTokens(this.input, this.prefix, this.wrappedInDiv, this.replacements) if b, ok := this.expect.(bool); ok && !b { if err == nil { From 35684e8f6fb9f9a959d00b34c13868ac46bbc1ef Mon Sep 17 00:00:00 2001 From: Jeffrey Tolar Date: Wed, 28 Jan 2015 21:39:59 -0600 Subject: [PATCH 4/7] Use strings instead of byte arrays for replaceShortcodeTokens tests --- hugolib/shortcode_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index ad966b286..5df969f49 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -281,24 +281,24 @@ func collectAndShortShortcodes(shortcodes map[string]shortcode) []string { func TestReplaceShortcodeTokens(t *testing.T) { for i, this := range []struct { - input []byte + input string prefix string replacements map[string]string wrappedInDiv bool expect interface{} }{ - {[]byte("Hello PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "World"}, false, []byte("Hello World.")}, - {[]byte("A {@{@A-1@}@} asdf {@{@A-2@}@}."), "A", map[string]string{"{@{@A-1@}@}": "v1", "{@{@A-2@}@}": "v2"}, true, []byte("A v1 asdf v2.")}, - {[]byte("Hello PREFIX2-1. Go PREFIX2-2, Go, Go PREFIX2-3 Go Go!."), "PREFIX2", map[string]string{"PREFIX2-1": "Europe", "PREFIX2-2": "Jonny", "PREFIX2-3": "Johnny"}, false, []byte("Hello Europe. Go Jonny, Go, Go Johnny Go Go!.")}, - {[]byte("A PREFIX-2 PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("A B A.")}, - {[]byte("A PREFIX-1 PREFIX-2"), "PREFIX", map[string]string{"PREFIX-1": "A"}, false, false}, - {[]byte("A PREFIX-1 but not the second."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("A A but not the second.")}, - {[]byte("An PREFIX-1."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("An A.")}, - {[]byte("An PREFIX-1 PREFIX-2."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, []byte("An A B.")}, - {[]byte("A PREFIX-1 PREFIX-2 PREFIX-3 PREFIX-1 PREFIX-3."), "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B", "PREFIX-3": "C"}, false, []byte("A A B C A C.")}, - {[]byte("A {@{@PREFIX-1@}@} {@{@PREFIX-2@}@} {@{@PREFIX-3@}@} {@{@PREFIX-1@}@} {@{@PREFIX-3@}@}."), "PREFIX", map[string]string{"{@{@PREFIX-1@}@}": "A", "{@{@PREFIX-2@}@}": "B", "{@{@PREFIX-3@}@}": "C"}, true, []byte("A A B C A C.")}, + {"Hello PREFIX-1.", "PREFIX", map[string]string{"PREFIX-1": "World"}, false, "Hello World."}, + {"A {@{@A-1@}@} asdf {@{@A-2@}@}.", "A", map[string]string{"{@{@A-1@}@}": "v1", "{@{@A-2@}@}": "v2"}, true, "A v1 asdf v2."}, + {"Hello PREFIX2-1. Go PREFIX2-2, Go, Go PREFIX2-3 Go Go!.", "PREFIX2", map[string]string{"PREFIX2-1": "Europe", "PREFIX2-2": "Jonny", "PREFIX2-3": "Johnny"}, false, "Hello Europe. Go Jonny, Go, Go Johnny Go Go!."}, + {"A PREFIX-2 PREFIX-1.", "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, "A B A."}, + {"A PREFIX-1 PREFIX-2", "PREFIX", map[string]string{"PREFIX-1": "A"}, false, false}, + {"A PREFIX-1 but not the second.", "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, "A A but not the second."}, + {"An PREFIX-1.", "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, "An A."}, + {"An PREFIX-1 PREFIX-2.", "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B"}, false, "An A B."}, + {"A PREFIX-1 PREFIX-2 PREFIX-3 PREFIX-1 PREFIX-3.", "PREFIX", map[string]string{"PREFIX-1": "A", "PREFIX-2": "B", "PREFIX-3": "C"}, false, "A A B C A C."}, + {"A {@{@PREFIX-1@}@} {@{@PREFIX-2@}@} {@{@PREFIX-3@}@} {@{@PREFIX-1@}@} {@{@PREFIX-3@}@}.", "PREFIX", map[string]string{"{@{@PREFIX-1@}@}": "A", "{@{@PREFIX-2@}@}": "B", "{@{@PREFIX-3@}@}": "C"}, true, "A A B C A C."}, } { - results, err := replaceShortcodeTokens(this.input, this.prefix, this.wrappedInDiv, this.replacements) + results, err := replaceShortcodeTokens([]byte(this.input), this.prefix, this.wrappedInDiv, this.replacements) if b, ok := this.expect.(bool); ok && !b { if err == nil { @@ -309,7 +309,7 @@ func TestReplaceShortcodeTokens(t *testing.T) { t.Errorf("[%d] failed: %s", i, err) continue } - if !reflect.DeepEqual(results, this.expect) { + if !reflect.DeepEqual(results, []byte(this.expect.(string))) { t.Errorf("[%d] replaceShortcodeTokens, got %q but expected %q", i, results, this.expect) } } From 3d60955e17328d2bb212a9dceb4825ac2f260681 Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Fri, 30 Jan 2015 06:24:44 -0700 Subject: [PATCH 5/7] Use .Date.IsZero to skip unset date in embedded templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `{{ if not .Date.IsZero }}` to print dates only when they are defined. This is to avoid things like Mon, 01 Jan 0001 00:00:00 +0000 and 0001-01-01T00:00:00+00:00 showing up in index.xml (RSS) and sitemap.xml. Pipe dates with ±hh:mm time zone through `safeHtml` to prevent the `+` sign from turning into `+`. Also make some shuffling to avoid blank lines in the output. --- tpl/template_embedded.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go index d09ef8447..dbeace556 100644 --- a/tpl/template_embedded.go +++ b/tpl/template_embedded.go @@ -50,18 +50,18 @@ func (t *GoHtmlTemplate) EmbedTemplates() { {{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }} {{ .Permalink }} Recent content {{ with .Title }}in {{.}} {{ end }}on {{ .Site.Title }} - Hugo -- gohugo.io - {{ with .Site.LanguageCode }}{{.}}{{end}} - {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} - {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} - {{ with .Site.Copyright }}{{.}}{{end}} - {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }} + Hugo -- gohugo.io{{ with .Site.LanguageCode }} + {{.}}{{end}}{{ with .Site.Author.email }} + {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }} + {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }} + {{.}}{{end}}{{ if not .Date.IsZero }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHtml }}{{ end }} {{ range first 15 .Data.Pages }} {{ .Title }} {{ .Permalink }} - {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHtml }} {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} {{ .Permalink }} {{ .Content | html }} @@ -73,8 +73,8 @@ func (t *GoHtmlTemplate) EmbedTemplates() { t.AddInternalTemplate("_default", "sitemap.xml", ` {{ range .Data.Pages }} - {{ .Permalink }} - {{ safeHtml ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}{{ with .Sitemap.ChangeFreq }} + {{ .Permalink }}{{ if not .Date.IsZero }} + {{ safeHtml ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} {{ .Sitemap.Priority }}{{ end }} @@ -134,7 +134,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() { {{ end }}{{ end }} -{{ with .Params.audio }} +{{ with .Params.audio }} {{ end }}{{ with .Params.locale }} {{ end }}{{ with .Site.Params.title }} {{ end }}{{ with .Params.videos }} @@ -192,9 +192,9 @@ func (t *GoHtmlTemplate) EmbedTemplates() { -{{if .IsPage}}{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}{{ if ne (.PublishDate.Format $ISO8601) "0001-01-01T00:00:00+00:00" }} -{{ end }} - +{{if .IsPage}}{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}{{ if not .PublishDate.IsZero }} +{{ end }} + {{ with .Params.images }}{{ range first 6 . }} From 230e7c02c528d0840675f27b3e926178c78176cb Mon Sep 17 00:00:00 2001 From: bep Date: Fri, 30 Jan 2015 21:58:18 +0100 Subject: [PATCH 6/7] Remove _default prefix from SEO templates --- tpl/template_embedded.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go index dbeace556..c0b36d999 100644 --- a/tpl/template_embedded.go +++ b/tpl/template_embedded.go @@ -126,7 +126,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() { comments powered by Disqus{{end}}`) // Add SEO & Social metadata - t.AddInternalTemplate("_default", "opengraph.html", ` + t.AddInternalTemplate("", "opengraph.html", ` @@ -166,7 +166,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() { {{ with .Site.Social.facebook_admin }}{{ end }}`) - t.AddInternalTemplate("_default", "twitter_cards.html", `{{ if .IsPage }} + t.AddInternalTemplate("", "twitter_cards.html", `{{ if .IsPage }} {{ with .Params.images }} @@ -184,11 +184,11 @@ func (t *GoHtmlTemplate) EmbedTemplates() { {{ with .twitter }}{{ end }} {{ end }}{{ end }}`) - t.AddInternalTemplate("_default", "google_news.html", `{{ if .IsPage }}{{ with .Params.news_keywords }} + t.AddInternalTemplate("", "google_news.html", `{{ if .IsPage }}{{ with .Params.news_keywords }} {{ end }}{{ end }}`) - t.AddInternalTemplate("_default", "schema.html", `{{ with .Site.Social.GooglePlus }}{{ end }} + t.AddInternalTemplate("", "schema.html", `{{ with .Site.Social.GooglePlus }}{{ end }} From 4a9436c116776ad3b776f9c16a816c878bccd4f3 Mon Sep 17 00:00:00 2001 From: bep Date: Fri, 30 Jan 2015 22:05:03 +0100 Subject: [PATCH 7/7] Some more .Date.IsZero checks in internal templates --- tpl/template_embedded.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go index c0b36d999..bb946a515 100644 --- a/tpl/template_embedded.go +++ b/tpl/template_embedded.go @@ -134,7 +134,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() { {{ end }}{{ end }} -{{ with .Params.audio }} +{{ if not .Date.IsZero }}{{ end }}{{ with .Params.audio }} {{ end }}{{ with .Params.locale }} {{ end }}{{ with .Site.Params.title }} {{ end }}{{ with .Params.videos }} @@ -194,7 +194,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() { {{if .IsPage}}{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}{{ if not .PublishDate.IsZero }} {{ end }} - +{{ if not .Date.IsZero }}{{ end }} {{ with .Params.images }}{{ range first 6 . }}