From 34ad9a4f178fcf50abe7246ad9d30b294327da16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 4 May 2018 17:53:56 +0200 Subject: [PATCH] tpl/tplimpl: Extract internal templates Having them in separate files should make maintainance easier. When adding new or making changes to the templates: ```bash mage generate ``` This will get the Go code in sync. Fixes #4457 --- hugolib/shortcode_test.go | 1 - magefile.go | 5 + tpl/tplimpl/embedded/generate/generate.go | 96 ++++++ .../templates.autogen.go} | 287 +++++++++--------- tpl/tplimpl/embedded/templates/README.md | 5 + .../embedded/templates/_default/robots.txt | 1 + .../embedded/templates/_default/rss.xml | 26 ++ .../embedded/templates/_default/sitemap.xml | 21 ++ .../templates/_default/sitemapindex.xml | 10 + tpl/tplimpl/embedded/templates/disqus.html | 20 ++ .../embedded/templates/google_analytics.html | 11 + .../templates/google_analytics_async.html | 8 + .../embedded/templates/google_news.html | 3 + tpl/tplimpl/embedded/templates/opengraph.html | 43 +++ .../embedded/templates/pagination.html | 42 +++ tpl/tplimpl/embedded/templates/schema.html | 15 + .../embedded/templates/shortcodes/figure.html | 18 ++ .../embedded/templates/shortcodes/gist.html | 1 + .../templates/shortcodes/highlight.html | 1 + .../templates/shortcodes/instagram.html | 1 + .../embedded/templates/shortcodes/ref.html | 1 + .../embedded/templates/shortcodes/relref.html | 1 + .../templates/shortcodes/speakerdeck.html | 1 + .../embedded/templates/shortcodes/tweet.html | 1 + .../embedded/templates/shortcodes/vimeo.html | 7 + .../templates/shortcodes/youtube.html | 9 + .../embedded/templates/twitter_cards.html | 29 ++ tpl/tplimpl/template.go | 19 +- 28 files changed, 520 insertions(+), 163 deletions(-) create mode 100644 tpl/tplimpl/embedded/generate/generate.go rename tpl/tplimpl/{template_embedded.go => embedded/templates.autogen.go} (79%) create mode 100644 tpl/tplimpl/embedded/templates/README.md create mode 100755 tpl/tplimpl/embedded/templates/_default/robots.txt create mode 100755 tpl/tplimpl/embedded/templates/_default/rss.xml create mode 100755 tpl/tplimpl/embedded/templates/_default/sitemap.xml create mode 100755 tpl/tplimpl/embedded/templates/_default/sitemapindex.xml create mode 100755 tpl/tplimpl/embedded/templates/disqus.html create mode 100755 tpl/tplimpl/embedded/templates/google_analytics.html create mode 100755 tpl/tplimpl/embedded/templates/google_analytics_async.html create mode 100755 tpl/tplimpl/embedded/templates/google_news.html create mode 100755 tpl/tplimpl/embedded/templates/opengraph.html create mode 100755 tpl/tplimpl/embedded/templates/pagination.html create mode 100755 tpl/tplimpl/embedded/templates/schema.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/figure.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/gist.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/highlight.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/instagram.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/ref.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/relref.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/speakerdeck.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/tweet.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/vimeo.html create mode 100755 tpl/tplimpl/embedded/templates/shortcodes/youtube.html create mode 100755 tpl/tplimpl/embedded/templates/twitter_cards.html diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 9f86ecb61..a32487477 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -249,7 +249,6 @@ This is **plain** text. func TestEmbeddedSC(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, "{{% test %}}", "This is a simple Test", nil) CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "\n
\n \n \n \n \n
\n", nil) CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "\n
\n \n \"This\n \n \n
\n

\n This is a caption\n \n \n \n

\n
\n \n
\n", nil) } diff --git a/magefile.go b/magefile.go index 883f96620..0cede2697 100644 --- a/magefile.go +++ b/magefile.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "path/filepath" "runtime" "strings" @@ -67,6 +68,10 @@ func flagEnv() map[string]string { } } +func Generate() error { + return sh.RunWith(flagEnv(), goexe, "generate", path.Join(packageName, "tpl/tplimpl/embedded/generate")) +} + // Build hugo without git info func HugoNoGitInfo() error { ldflags = noGitLdflags diff --git a/tpl/tplimpl/embedded/generate/generate.go b/tpl/tplimpl/embedded/generate/generate.go new file mode 100644 index 000000000..14b877c55 --- /dev/null +++ b/tpl/tplimpl/embedded/generate/generate.go @@ -0,0 +1,96 @@ +// Copyright 2018 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:generate go run generate.go + +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + "strings" +) + +func main() { + + templateFolder := filepath.Join("..", "templates") + + temlatePath := filepath.Join(".", templateFolder) + + file, err := os.Create("../templates.autogen.go") + if err != nil { + log.Fatal(err) + } + defer file.Close() + + var nameValues []string + + err = filepath.Walk(temlatePath, func(path string, info os.FileInfo, err error) error { + + if info.IsDir() { + return nil + } + if strings.HasPrefix(info.Name(), ".") { + return nil + } + + templateName := filepath.ToSlash(strings.TrimPrefix(path, templateFolder+string(os.PathSeparator))) + + templateContent, err := ioutil.ReadFile(path) + if err != nil { + return err + } + + nameValues = append(nameValues, nameValue(templateName, string(templateContent))) + + return nil + }) + + if err != nil { + log.Fatal(err) + } + + fmt.Fprint(file, `// Copyright 2018 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file is autogenerated. + +// Package embedded defines the internal templates that Hugo provides. +package embedded + +var EmbeddedTemplates = [][2]string{ +`) + + for _, v := range nameValues { + fmt.Fprint(file, " ", v, ",\n") + } + fmt.Fprint(file, "}\n") + +} + +func nameValue(name, value string) string { + return fmt.Sprintf("{`%s`, `%s`}", name, value) +} diff --git a/tpl/tplimpl/template_embedded.go b/tpl/tplimpl/embedded/templates.autogen.go similarity index 79% rename from tpl/tplimpl/template_embedded.go rename to tpl/tplimpl/embedded/templates.autogen.go index 18bba44f2..d30352502 100644 --- a/tpl/tplimpl/template_embedded.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -1,4 +1,4 @@ -// Copyright 2017-present The Hugo Authors. All rights reserved. +// Copyright 2018 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,56 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package tplimpl +// This file is autogenerated. -func (t *templateHandler) embedShortcodes() { - t.addInternalShortcode("ref.html", `{{ if len .Params | eq 2 }}{{ ref .Page (.Get 0) (.Get 1) }}{{ else }}{{ ref .Page (.Get 0) }}{{ end }}`) - t.addInternalShortcode("relref.html", `{{ if len .Params | eq 2 }}{{ relref .Page (.Get 0) (.Get 1) }}{{ else }}{{ relref .Page (.Get 0) }}{{ end }}`) - t.addInternalShortcode("highlight.html", `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`) - t.addInternalShortcode("test.html", `This is a simple Test`) - t.addInternalShortcode("figure.html", ` - - {{ if .Get "link"}}{{ end }} - - {{ if .Get "link"}}{{ end }} - {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} -
{{ if isset .Params "title" }} -

{{ .Get "title" }}

{{ end }} - {{ if or (.Get "caption") (.Get "attr")}}

- {{ .Get "caption" }} - {{ with .Get "attrlink"}} {{ end }} - {{ .Get "attr" }} - {{ if .Get "attrlink"}} {{ end }} -

{{ end }} -
- {{ end }} - -`) - t.addInternalShortcode("speakerdeck.html", "") - t.addInternalShortcode("youtube.html", `{{ if .IsNamedParams }} -
- -
{{ else }} -
- -
-{{ end }}`) - t.addInternalShortcode("vimeo.html", `{{ if .IsNamedParams }}
- -
{{ else }} -
- -
-{{ end }}`) - t.addInternalShortcode("gist.html", ``) - t.addInternalShortcode("tweet.html", `{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}`) - t.addInternalShortcode("instagram.html", `{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }}`) -} +// Package embedded defines the internal templates that Hugo provides. +package embedded -func (t *templateHandler) embedTemplates() { - - t.addInternalTemplate("_default", "rss.xml", ` +var EmbeddedTemplates = [][2]string{ + {`_default/robots.txt`, `User-agent: *`}, + {`_default/rss.xml`, ` {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} {{ .Permalink }} @@ -85,9 +43,8 @@ func (t *templateHandler) embedTemplates() { {{ end }} -`) - - t.addInternalTemplate("_default", "sitemap.xml", ``}, + {`_default/sitemap.xml`, ` {{ range .Data.Pages }} @@ -107,10 +64,8 @@ func (t *templateHandler) embedTemplates() { />{{ end }} {{ end }} -`) - - // For multilanguage sites - t.addInternalTemplate("_default", "sitemapindex.xml", ` +`}, + {`_default/sitemapindex.xml`, ` {{ range . }} {{ .SitemapAbsURL }} @@ -120,52 +75,8 @@ func (t *templateHandler) embedTemplates() { {{ end }} -`) - - t.addInternalTemplate("", "pagination.html", `{{ $pag := $.Paginator }} -{{ if gt $pag.TotalPages 1 }} -
    - {{ with $pag.First }} -
  • - -
  • - {{ end }} -
  • - -
  • - {{ $.Scratch.Set "__paginator.ellipsed" false }} - {{ range $pag.Pagers }} - {{ $right := sub .TotalPages .PageNumber }} - {{ $showNumber := or (le .PageNumber 3) (eq $right 0) }} - {{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }} - {{ if $showNumber }} - {{ $.Scratch.Set "__paginator.ellipsed" false }} - {{ $.Scratch.Set "__paginator.shouldEllipse" false }} - {{ else }} - {{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }} - {{ $.Scratch.Set "__paginator.ellipsed" true }} - {{ end }} - {{ if $showNumber }} -
  • {{ .PageNumber }}
  • - {{ else if ($.Scratch.Get "__paginator.shouldEllipse") }} -
  • - {{ end }} - {{ end }} -
  • - -
  • - {{ with $pag.Last }} -
  • - -
  • - {{ end }} -
-{{ end }}`) - - t.addInternalTemplate("", "disqus.html", `{{ if .Site.DisqusShortname }}
+`}, + {`disqus.html`, `{{ if .Site.DisqusShortname }}
-comments powered by Disqus{{end}}`) +comments powered by Disqus{{end}}`}, + {`google_analytics.html`, `{{ with .Site.GoogleAnalytics }} + +{{ end }}`}, + {`google_analytics_async.html`, `{{ with .Site.GoogleAnalytics }} + + +{{ end }}`}, + {`google_news.html`, `{{ if .IsPage }}{{ with .Params.news_keywords }} + +{{ end }}{{ end }}`}, + {`opengraph.html`, ` @@ -229,9 +160,106 @@ func (t *templateHandler) embedTemplates() { {{ end }}{{ end }} -{{ with .Site.Social.facebook_admin }}{{ end }}`) +{{ with .Site.Social.facebook_admin }}{{ end }}`}, + {`pagination.html`, `{{ $pag := $.Paginator }} +{{ if gt $pag.TotalPages 1 }} +
    + {{ with $pag.First }} +
  • + +
  • + {{ end }} +
  • + +
  • + {{ $.Scratch.Set "__paginator.ellipsed" false }} + {{ range $pag.Pagers }} + {{ $right := sub .TotalPages .PageNumber }} + {{ $showNumber := or (le .PageNumber 3) (eq $right 0) }} + {{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }} + {{ if $showNumber }} + {{ $.Scratch.Set "__paginator.ellipsed" false }} + {{ $.Scratch.Set "__paginator.shouldEllipse" false }} + {{ else }} + {{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }} + {{ $.Scratch.Set "__paginator.ellipsed" true }} + {{ end }} + {{ if $showNumber }} +
  • {{ .PageNumber }}
  • + {{ else if ($.Scratch.Get "__paginator.shouldEllipse") }} +
  • + {{ end }} + {{ end }} +
  • + +
  • + {{ with $pag.Last }} +
  • + +
  • + {{ end }} +
+{{ end }}`}, + {`schema.html`, `{{ with .Site.Social.GooglePlus }}{{ end }} + + - t.addInternalTemplate("", "twitter_cards.html", `{{- with $.Params.images -}} +{{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 . }} + +{{ end }}{{ end }} + + + +{{ end }}`}, + {`shortcodes/figure.html`, ` + + {{ if .Get "link"}}{{ end }} + + {{ if .Get "link"}}{{ end }} + {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} +
{{ if isset .Params "title" }} +

{{ .Get "title" }}

{{ end }} + {{ if or (.Get "caption") (.Get "attr")}}

+ {{ .Get "caption" }} + {{ with .Get "attrlink"}} {{ end }} + {{ .Get "attr" }} + {{ if .Get "attrlink"}} {{ end }} +

{{ end }} +
+ {{ end }} + +`}, + {`shortcodes/gist.html`, ``}, + {`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`}, + {`shortcodes/instagram.html`, `{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }}`}, + {`shortcodes/ref.html`, `{{ if len .Params | eq 2 }}{{ ref .Page (.Get 0) (.Get 1) }}{{ else }}{{ ref .Page (.Get 0) }}{{ end }}`}, + {`shortcodes/relref.html`, `{{ if len .Params | eq 2 }}{{ relref .Page (.Get 0) (.Get 1) }}{{ else }}{{ relref .Page (.Get 0) }}{{ end }}`}, + {`shortcodes/speakerdeck.html`, ``}, + {`shortcodes/tweet.html`, `{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}`}, + {`shortcodes/vimeo.html`, `{{ if .IsNamedParams }}
+ +
{{ else }} +
+ +
+{{ end }}`}, + {`shortcodes/youtube.html`, `{{ if .IsNamedParams }} +
+ +
{{ else }} +
+ +
+{{ end }}`}, + {`twitter_cards.html`, `{{- with $.Params.images -}} {{ else -}} @@ -259,48 +287,5 @@ func (t *templateHandler) embedTemplates() { {{ with .twitter -}} {{ end -}} -{{ end -}}`) - - t.addInternalTemplate("", "google_news.html", `{{ if .IsPage }}{{ with .Params.news_keywords }} - -{{ end }}{{ end }}`) - - t.addInternalTemplate("", "schema.html", `{{ with .Site.Social.GooglePlus }}{{ end }} - - - -{{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 . }} - -{{ end }}{{ end }} - - - -{{ end }}`) - - t.addInternalTemplate("", "google_analytics.html", `{{ with .Site.GoogleAnalytics }} - -{{ end }}`) - - t.addInternalTemplate("", "google_analytics_async.html", `{{ with .Site.GoogleAnalytics }} - - -{{ end }}`) - - t.addInternalTemplate("_default", "robots.txt", "User-agent: *") +{{ end -}}`}, } diff --git a/tpl/tplimpl/embedded/templates/README.md b/tpl/tplimpl/embedded/templates/README.md new file mode 100644 index 000000000..034c383d1 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/README.md @@ -0,0 +1,5 @@ + + +## Build Templates + +If you add or modify any template in this folder, you also need to run `mage generate` to get the Go code in synch. \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/_default/robots.txt b/tpl/tplimpl/embedded/templates/_default/robots.txt new file mode 100755 index 000000000..4f9540ba3 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/_default/robots.txt @@ -0,0 +1 @@ +User-agent: * \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/_default/rss.xml b/tpl/tplimpl/embedded/templates/_default/rss.xml new file mode 100755 index 000000000..abba0b28a --- /dev/null +++ b/tpl/tplimpl/embedded/templates/_default/rss.xml @@ -0,0 +1,26 @@ + + + {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} + {{ .Permalink }} + Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ 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}}{{ if not .Date.IsZero }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} + {{ with .OutputFormats.Get "RSS" }} + {{ printf "" .Permalink .MediaType | safeHTML }} + {{ end }} + {{ range .Data.Pages }} + + {{ .Title }} + {{ .Permalink }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} + {{ .Permalink }} + {{ .Summary | html }} + + {{ end }} + + \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/_default/sitemap.xml b/tpl/tplimpl/embedded/templates/_default/sitemap.xml new file mode 100755 index 000000000..e0a2b189d --- /dev/null +++ b/tpl/tplimpl/embedded/templates/_default/sitemap.xml @@ -0,0 +1,21 @@ + + {{ range .Data.Pages }} + + {{ .Permalink }}{{ if not .Lastmod.IsZero }} + {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} + {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} + {{ .Sitemap.Priority }}{{ end }}{{ if .IsTranslated }}{{ range .Translations }} + {{ end }} + {{ end }} + + {{ end }} + \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/_default/sitemapindex.xml b/tpl/tplimpl/embedded/templates/_default/sitemapindex.xml new file mode 100755 index 000000000..4cd289fe9 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/_default/sitemapindex.xml @@ -0,0 +1,10 @@ + + {{ range . }} + + {{ .SitemapAbsURL }} + {{ if not .LastChange.IsZero }} + {{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }} + {{ end }} + + {{ end }} + diff --git a/tpl/tplimpl/embedded/templates/disqus.html b/tpl/tplimpl/embedded/templates/disqus.html new file mode 100755 index 000000000..a42298e53 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/disqus.html @@ -0,0 +1,20 @@ +{{ if .Site.DisqusShortname }}
+ + +comments powered by Disqus{{end}} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/google_analytics.html b/tpl/tplimpl/embedded/templates/google_analytics.html new file mode 100755 index 000000000..8155cf6f2 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/google_analytics.html @@ -0,0 +1,11 @@ +{{ with .Site.GoogleAnalytics }} + +{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/google_analytics_async.html b/tpl/tplimpl/embedded/templates/google_analytics_async.html new file mode 100755 index 000000000..0e983850a --- /dev/null +++ b/tpl/tplimpl/embedded/templates/google_analytics_async.html @@ -0,0 +1,8 @@ +{{ with .Site.GoogleAnalytics }} + + +{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/google_news.html b/tpl/tplimpl/embedded/templates/google_news.html new file mode 100755 index 000000000..9361de16a --- /dev/null +++ b/tpl/tplimpl/embedded/templates/google_news.html @@ -0,0 +1,3 @@ +{{ if .IsPage }}{{ with .Params.news_keywords }} + +{{ end }}{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/opengraph.html b/tpl/tplimpl/embedded/templates/opengraph.html new file mode 100755 index 000000000..3468efd95 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/opengraph.html @@ -0,0 +1,43 @@ + + + + +{{ with .Params.images }}{{ range first 6 . }} + +{{ end }}{{ end }} + +{{ if .IsPage }} +{{ if not .PublishDate.IsZero }} +{{ else if not .Date.IsZero }}{{ end }} +{{ if not .Lastmod.IsZero }}{{ end }} +{{ else }} +{{ if not .Date.IsZero }}{{ end }} +{{ end }}{{ with .Params.audio }} +{{ end }}{{ with .Params.locale }} +{{ end }}{{ with .Site.Params.title }} +{{ end }}{{ with .Params.videos }} +{{ range . }} + +{{ end }}{{ end }} + + +{{ $permalink := .Permalink }} +{{ $siteSeries := .Site.Taxonomies.series }}{{ with .Params.series }} +{{ range $name := . }} + {{ $series := index $siteSeries $name }} + {{ range $page := first 6 $series.Pages }} + {{ if ne $page.Permalink $permalink }}{{ end }} + {{ end }} +{{ end }}{{ end }} + +{{ if .IsPage }} +{{ range .Site.Authors }}{{ with .Social.facebook }} +{{ end }}{{ with .Site.Social.facebook }} +{{ end }} + +{{ with .Params.tags }}{{ range first 6 . }} + {{ end }}{{ end }} +{{ end }}{{ end }} + + +{{ with .Site.Social.facebook_admin }}{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/pagination.html b/tpl/tplimpl/embedded/templates/pagination.html new file mode 100755 index 000000000..eeaf2fbd6 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/pagination.html @@ -0,0 +1,42 @@ +{{ $pag := $.Paginator }} +{{ if gt $pag.TotalPages 1 }} +
    + {{ with $pag.First }} +
  • + +
  • + {{ end }} +
  • + +
  • + {{ $.Scratch.Set "__paginator.ellipsed" false }} + {{ range $pag.Pagers }} + {{ $right := sub .TotalPages .PageNumber }} + {{ $showNumber := or (le .PageNumber 3) (eq $right 0) }} + {{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }} + {{ if $showNumber }} + {{ $.Scratch.Set "__paginator.ellipsed" false }} + {{ $.Scratch.Set "__paginator.shouldEllipse" false }} + {{ else }} + {{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }} + {{ $.Scratch.Set "__paginator.ellipsed" true }} + {{ end }} + {{ if $showNumber }} +
  • {{ .PageNumber }}
  • + {{ else if ($.Scratch.Get "__paginator.shouldEllipse") }} +
  • + {{ end }} + {{ end }} +
  • + +
  • + {{ with $pag.Last }} +
  • + +
  • + {{ end }} +
+{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/schema.html b/tpl/tplimpl/embedded/templates/schema.html new file mode 100755 index 000000000..bef45b167 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/schema.html @@ -0,0 +1,15 @@ +{{ with .Site.Social.GooglePlus }}{{ end }} + + + +{{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 . }} + +{{ end }}{{ end }} + + + +{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/figure.html b/tpl/tplimpl/embedded/templates/shortcodes/figure.html new file mode 100755 index 000000000..258d25bfe --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/figure.html @@ -0,0 +1,18 @@ + + + {{ if .Get "link"}}{{ end }} + + {{ if .Get "link"}}{{ end }} + {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} +
{{ if isset .Params "title" }} +

{{ .Get "title" }}

{{ end }} + {{ if or (.Get "caption") (.Get "attr")}}

+ {{ .Get "caption" }} + {{ with .Get "attrlink"}} {{ end }} + {{ .Get "attr" }} + {{ if .Get "attrlink"}} {{ end }} +

{{ end }} +
+ {{ end }} + + \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/gist.html b/tpl/tplimpl/embedded/templates/shortcodes/gist.html new file mode 100755 index 000000000..a1b6dc6eb --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/gist.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/highlight.html b/tpl/tplimpl/embedded/templates/shortcodes/highlight.html new file mode 100755 index 000000000..b063f92ad --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/highlight.html @@ -0,0 +1 @@ +{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/instagram.html b/tpl/tplimpl/embedded/templates/shortcodes/instagram.html new file mode 100755 index 000000000..9f012cf3a --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/instagram.html @@ -0,0 +1 @@ +{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/ref.html b/tpl/tplimpl/embedded/templates/shortcodes/ref.html new file mode 100755 index 000000000..84e3e3820 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/ref.html @@ -0,0 +1 @@ +{{ if len .Params | eq 2 }}{{ ref .Page (.Get 0) (.Get 1) }}{{ else }}{{ ref .Page (.Get 0) }}{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/relref.html b/tpl/tplimpl/embedded/templates/shortcodes/relref.html new file mode 100755 index 000000000..c61423bf1 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/relref.html @@ -0,0 +1 @@ +{{ if len .Params | eq 2 }}{{ relref .Page (.Get 0) (.Get 1) }}{{ else }}{{ relref .Page (.Get 0) }}{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/speakerdeck.html b/tpl/tplimpl/embedded/templates/shortcodes/speakerdeck.html new file mode 100755 index 000000000..9ef1f92f6 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/speakerdeck.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/tweet.html b/tpl/tplimpl/embedded/templates/shortcodes/tweet.html new file mode 100755 index 000000000..008b0b776 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/tweet.html @@ -0,0 +1 @@ +{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html b/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html new file mode 100755 index 000000000..513e5c2b4 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html @@ -0,0 +1,7 @@ +{{ if .IsNamedParams }}
+ +
{{ else }} +
+ +
+{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html new file mode 100755 index 000000000..f128889ae --- /dev/null +++ b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html @@ -0,0 +1,9 @@ +{{ if .IsNamedParams }} +
+ +
{{ else }} +
+ +
+{{ end }} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/twitter_cards.html b/tpl/tplimpl/embedded/templates/twitter_cards.html new file mode 100755 index 000000000..fc4895b56 --- /dev/null +++ b/tpl/tplimpl/embedded/templates/twitter_cards.html @@ -0,0 +1,29 @@ +{{- with $.Params.images -}} + + +{{ else -}} +{{- $images := $.Resources.ByType "image" -}} +{{- $featured := $images.GetMatch "*feature*" -}} +{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}} +{{- with $featured -}} + + +{{- else -}} +{{- with $.Site.Params.images -}} + + +{{ else -}} + +{{- end -}} +{{- end -}} +{{- end }} + + +{{ with .Site.Social.twitter -}} + +{{ end -}} +{{ range .Site.Authors }} +{{ with .twitter -}} + +{{ end -}} +{{ end -}} \ No newline at end of file diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index 25757abc4..7c7d639f0 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -20,6 +20,8 @@ import ( "strings" texttemplate "text/template" + "github.com/gohugoio/hugo/tpl/tplimpl/embedded" + "github.com/eknkc/amber" "os" @@ -682,23 +684,18 @@ func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) e return t.AddTemplate(name, templ) } - } func (t *templateHandler) loadEmbedded() { - t.embedShortcodes() - t.embedTemplates() -} - -func (t *templateHandler) addInternalTemplate(prefix, name, tpl string) error { - if prefix != "" { - return t.AddTemplate("_internal/"+prefix+"/"+name, tpl) + for _, kv := range embedded.EmbeddedTemplates { + // TODO(bep) error handling + t.addInternalTemplate(kv[0], kv[1]) } - return t.AddTemplate("_internal/"+name, tpl) + } -func (t *templateHandler) addInternalShortcode(name, content string) error { - return t.addInternalTemplate("shortcodes", name, content) +func (t *templateHandler) addInternalTemplate(name, tpl string) error { + return t.AddTemplate("_internal/"+name, tpl) } func (t *templateHandler) checkState() {