From 311307c9e4740bd5ee24a09157012b7d12076681 Mon Sep 17 00:00:00 2001 From: digitalcraftsman Date: Mon, 23 Nov 2015 19:32:03 +0100 Subject: [PATCH] Add IsNamedParams property in shortcodes --- docs/content/extras/shortcodes.md | 4 ++-- tpl/template_embedded.go | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/content/extras/shortcodes.md b/docs/content/extras/shortcodes.md index 3de732a2a..ae3b16619 100644 --- a/docs/content/extras/shortcodes.md +++ b/docs/content/extras/shortcodes.md @@ -173,9 +173,9 @@ You want to include a single tweet into your blog post? Everything you need is t https://twitter.com/spf13/status/666616452582129664 -Pass the tweet's author the id from the URL as parameters to the shortcode as shown below: +Pass the tweet's id from the URL as parameter to the shortcode as shown below: - {{}} + {{}} *** diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go index 673907d00..f13554ab0 100644 --- a/tpl/template_embedded.go +++ b/tpl/template_embedded.go @@ -41,15 +41,24 @@ func (t *GoHTMLTemplate) EmbedShortcodes() { {{ end }} `) - t.AddInternalShortcode("speakerdeck.html", "") - t.AddInternalShortcode("youtube.html", `
`) - t.AddInternalShortcode("vimeo.html", `
- -
`) - t.AddInternalShortcode("gist.html", ``) - t.AddInternalShortcode("tweet.html", `{{ $user := index .Params 0 }} -{{ $tweet := index .Params 1 }} -{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?url=https://twitter.com/" $user "/status/" $tweet).html | safeHTML }}`) + 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 }}`) } func (t *GoHTMLTemplate) EmbedTemplates() {