mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-22 14:52:09 +00:00
Add Disqus support out of the box. Move template/bundle into hugolib.
This commit is contained in:
parent
41adafbc3e
commit
4a8de8ea46
7 changed files with 57 additions and 39 deletions
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/spf13/cast"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/parser"
|
||||
"github.com/spf13/hugo/template/bundle"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/theplant/blackfriday"
|
||||
|
@ -49,7 +48,7 @@ type Page struct {
|
|||
contentType string
|
||||
Draft bool
|
||||
Aliases []string
|
||||
Tmpl bundle.Template
|
||||
Tmpl Template
|
||||
Markup string
|
||||
renderable bool
|
||||
layout string
|
||||
|
@ -519,7 +518,7 @@ func (page *Page) parse(reader io.Reader) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) ProcessShortcodes(t bundle.Template) {
|
||||
func (p *Page) ProcessShortcodes(t Template) {
|
||||
p.rawContent = []byte(ShortcodesHandle(string(p.rawContent), p, t))
|
||||
p.Summary = template.HTML(ShortcodesHandle(string(p.Summary), p, t))
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"testing"
|
|
@ -20,7 +20,6 @@ import (
|
|||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/spf13/hugo/template/bundle"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
)
|
||||
|
||||
|
@ -78,7 +77,7 @@ func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
|
|||
|
||||
type Shortcodes map[string]ShortcodeFunc
|
||||
|
||||
func ShortcodesHandle(stringToParse string, p *Page, t bundle.Template) string {
|
||||
func ShortcodesHandle(stringToParse string, p *Page, t Template) string {
|
||||
leadStart := strings.Index(stringToParse, `{{%`)
|
||||
if leadStart >= 0 {
|
||||
leadEnd := strings.Index(stringToParse[leadStart:], `%}}`) + leadStart
|
||||
|
@ -147,7 +146,7 @@ func FindEnd(str string, name string) (int, int) {
|
|||
return startPos, endPos
|
||||
}
|
||||
|
||||
func GetTemplate(name string, t bundle.Template) *template.Template {
|
||||
func GetTemplate(name string, t Template) *template.Template {
|
||||
if x := t.Lookup("shortcodes/" + name + ".html"); x != nil {
|
||||
return x
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/hugo/target"
|
||||
"github.com/spf13/hugo/template/bundle"
|
||||
"github.com/spf13/hugo/transform"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/nitro"
|
||||
|
@ -57,7 +56,7 @@ var DefaultTimer *nitro.B
|
|||
// 5. The entire collection of files is written to disk.
|
||||
type Site struct {
|
||||
Pages Pages
|
||||
Tmpl bundle.Template
|
||||
Tmpl Template
|
||||
Taxonomies TaxonomyList
|
||||
Source source.Input
|
||||
Sections Taxonomy
|
||||
|
@ -72,19 +71,20 @@ type Site struct {
|
|||
}
|
||||
|
||||
type SiteInfo struct {
|
||||
BaseUrl template.URL
|
||||
Taxonomies TaxonomyList
|
||||
Indexes *TaxonomyList // legacy, should be identical to Taxonomies
|
||||
Recent *Pages
|
||||
Title string
|
||||
Author string
|
||||
AuthorEmail string
|
||||
LanguageCode string
|
||||
Copyright string
|
||||
LastChange time.Time
|
||||
ConfigGet func(key string) interface{}
|
||||
Permalinks PermalinkOverrides
|
||||
Params map[string]interface{}
|
||||
BaseUrl template.URL
|
||||
Taxonomies TaxonomyList
|
||||
Indexes *TaxonomyList // legacy, should be identical to Taxonomies
|
||||
Recent *Pages
|
||||
Title string
|
||||
Author map[string]string
|
||||
LanguageCode string
|
||||
DisqusShortname string
|
||||
Copyright string
|
||||
LastChange time.Time
|
||||
ConfigGet func(key string) interface{}
|
||||
Permalinks PermalinkOverrides
|
||||
Params map[string]interface{}
|
||||
}
|
||||
}
|
||||
|
||||
type runmode struct {
|
||||
|
@ -130,7 +130,7 @@ func (s *Site) Analyze() {
|
|||
}
|
||||
|
||||
func (s *Site) prepTemplates() {
|
||||
s.Tmpl = bundle.NewTemplate()
|
||||
s.Tmpl = NewTemplate()
|
||||
s.Tmpl.LoadTemplates(s.absLayoutDir())
|
||||
if s.hasTheme() {
|
||||
s.Tmpl.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
|
||||
|
@ -234,16 +234,16 @@ func (s *Site) initializeSiteInfo() {
|
|||
permalinks = make(PermalinkOverrides)
|
||||
}
|
||||
|
||||
s.Info = SiteInfo{
|
||||
BaseUrl: template.URL(helpers.SanitizeUrl(viper.GetString("BaseUrl"))),
|
||||
Title: viper.GetString("Title"),
|
||||
Author: viper.GetString("author"),
|
||||
AuthorEmail: viper.GetString("authoremail"),
|
||||
LanguageCode: viper.GetString("languagecode"),
|
||||
Copyright: viper.GetString("copyright"),
|
||||
Recent: &s.Pages,
|
||||
Params: params,
|
||||
Permalinks: permalinks,
|
||||
s.Info = &SiteInfo{
|
||||
BaseUrl: template.URL(helpers.SanitizeUrl(viper.GetString("BaseUrl"))),
|
||||
Title: viper.GetString("Title"),
|
||||
Author: viper.GetStringMapString("author"),
|
||||
LanguageCode: viper.GetString("languagecode"),
|
||||
Copyright: viper.GetString("copyright"),
|
||||
DisqusShortname: viper.GetString("DisqusShortname"),
|
||||
Recent: &s.Pages,
|
||||
Params: params,
|
||||
Permalinks: permalinks,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -192,7 +192,11 @@ func (t *GoHtmlTemplate) LoadEmbedded() {
|
|||
}
|
||||
|
||||
func (t *GoHtmlTemplate) AddInternalTemplate(prefix, name, tpl string) error {
|
||||
return t.AddTemplate("_internal/"+prefix+"/"+name, tpl)
|
||||
if prefix != "" {
|
||||
return t.AddTemplate("_internal/"+prefix+"/"+name, tpl)
|
||||
} else {
|
||||
return t.AddTemplate("_internal/"+name, tpl)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) AddInternalShortcode(name, content string) error {
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bundle
|
||||
package hugolib
|
||||
|
||||
type Tmpl struct {
|
||||
Name string
|
||||
|
@ -49,7 +49,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
|||
<generator uri="https://hugo.spf13.com">Hugo</generator>
|
||||
<link>{{ .Permalink }}</link>
|
||||
{{ with .Site.LanguageCode }}<language>{{.}}</language>{{end}}
|
||||
{{ with .Site.Author }}<author>{{.}}</author>{{end}}
|
||||
{{ with .Site.Author.name }}<author>{{.}}</author>{{end}}
|
||||
{{ with .Site.Copyright }}<copyright>{{.}}</copyright>{{end}}
|
||||
<updated>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</updated>
|
||||
{{ range first 15 .Data.Pages }}
|
||||
|
@ -57,7 +57,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
|||
<title>{{ .Title }}</title>
|
||||
<link>{{ .Permalink }}</link>
|
||||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</pubDate>
|
||||
{{with .Site.Author}}<author>{{.}}</author>{{end}}
|
||||
{{with .Site.Author.name}}<author>{{.}}</author>{{end}}
|
||||
<guid>{{ .Permalink }}</guid>
|
||||
<description>{{ .Content | html }}</description>
|
||||
</item>
|
||||
|
@ -65,4 +65,20 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
|||
</channel>
|
||||
</rss>`)
|
||||
|
||||
t.AddInternalTemplate("", "disqus.html", `{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div>
|
||||
<script type="text/javascript">
|
||||
var disqus_shortname = '{{ .Site.DisqusShortname }}';
|
||||
var disqus_identifier = '{{with .GetParam "disqus_identifier" }}{{ . }}{{ else }}{{ .Permalink }}{{end}}';
|
||||
var disqus_title = '{{with .GetParam "disqus_title" }}{{ . }}{{ else }}{{ .Title }}{{end}}';
|
||||
var disqus_url = '{{with .GetParam "disqus_url" }}{{ . | html }}{{ else }}{{ .Permalink }}{{end}}';
|
||||
|
||||
(function() {
|
||||
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
|
||||
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
|
||||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
||||
})();
|
||||
</script>
|
||||
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
|
||||
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>{{end}}`)
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"reflect"
|
Loading…
Reference in a new issue