// Copyright 2015 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.
package tplimpl
type Tmpl struct {
Name string
Data string
}
func (t *GoHTMLTemplate) EmbedShortcodes() {
t.AddInternalShortcode("ref.html", `{{ .Get 0 | ref .Page }}`)
t.AddInternalShortcode("relref.html", `{{ .Get 0 | relref .Page }}`)
t.AddInternalShortcode("highlight.html", `{{ if len .Params | eq 2 }}{{ highlight .Inner (.Get 0) (.Get 1) }}{{ else }}{{ highlight .Inner (.Get 0) "" }}{{ end }}`)
t.AddInternalShortcode("test.html", `This is a simple Test`)
t.AddInternalShortcode("figure.html", `
`)
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 }}`)
}
func (t *GoHTMLTemplate) EmbedTemplates() {
t.AddInternalTemplate("_default", "rss.xml", `{{ 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 }}
{{ 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 }}{{ .Content | html }}
{{ end }}
`)
t.AddInternalTemplate("_default", "sitemap.xml", `
{{ 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 }}
{{ end }}
`)
// For multilanguage sites
t.AddInternalTemplate("_default", "sitemapindex.xml", `
{{ range . }}
{{ .SitemapAbsURL }}
{{ if not .LastChange.IsZero }}
{{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}
{{ end }}
{{ end }}
`)
t.AddInternalTemplate("", "pagination.html", `{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
{{ end }}`)
t.AddInternalTemplate("", "disqus.html", `{{ if .Site.DisqusShortname }}
comments powered by Disqus{{end}}`)
// Add SEO & Social metadata
t.AddInternalTemplate("", "opengraph.html", `
{{ 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 .Params.videos }}
{{ 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 }}`)
t.AddInternalTemplate("", "twitter_cards.html", `{{ if .IsPage }}
{{ with .Params.images }}
{{ else }}
{{ end }}
{{ with .Site.Social.twitter }}{{ end }}
{{ with .Site.Social.twitter_domain }}{{ end }}
{{ range .Site.Authors }}
{{ with .twitter }}{{ end }}
{{ 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: *")
}