tpl: Alias tweet shortode to twitter
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 24 May 2018 09:24:38 +0000 (11:24 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 24 May 2018 09:40:47 +0000 (11:40 +0200)
See #4765

config/privacy/privacyConfig.go
config/privacy/privacyConfig_test.go
tpl/tplimpl/embedded/templates.autogen.go
tpl/tplimpl/embedded/templates/shortcodes/tweet.html [deleted file]
tpl/tplimpl/embedded/templates/shortcodes/twitter.html [new file with mode: 0755]
tpl/tplimpl/template.go

index ee7b7be2cb3ecd95795f15e38b91e9e31aeae613..bcffec8af2a84c83c0c2f67f230d72a55692bfd1 100644 (file)
@@ -31,7 +31,7 @@ type Config struct {
        GoogleAnalytics GoogleAnalytics
        Instagram       Instagram
        SpeakerDeck     SpeakerDeck
-       Tweet           Tweet
+       Twitter         Twitter
        Vimeo           Vimeo
        YouTube         YouTube
 }
@@ -64,8 +64,8 @@ type SpeakerDeck struct {
        Service `mapstructure:",squash"`
 }
 
-// Tweet holds the privacy configuration settingsrelated to the Tweet shortcode.
-type Tweet struct {
+// Twitter holds the privacy configuration settingsrelated to the Twitter shortcode.
+type Twitter struct {
        Service `mapstructure:",squash"`
 }
 
index f945ac8c2292547c0a542526c24f27bb76248b0f..0efc734db283e8ffb8c73953b2e0137005fd157c 100644 (file)
@@ -39,7 +39,7 @@ disable = true
 simple = true
 [privacy.speakerDeck]
 disable = true
-[privacy.tweet]
+[privacy.twitter]
 disable = true
 [privacy.vimeo]
 disable = true
@@ -61,7 +61,7 @@ simple = true
        assert.True(pc.Instagram.Disable)
        assert.True(pc.Instagram.Simple)
        assert.True(pc.SpeakerDeck.Disable)
-       assert.True(pc.Tweet.Disable)
+       assert.True(pc.Twitter.Disable)
        assert.True(pc.Vimeo.Disable)
 
        assert.True(pc.YouTube.PrivacyEnhanced)
index ebed43a37e162dc7814826f42327d79b41dfcb19..94e4c33abfc7e520e059a47ec330a2bee09967ef 100644 (file)
@@ -363,7 +363,7 @@ M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.5
 {{- if not $pc.Disable -}}
 <script async class='speakerdeck-embed' data-id='{{ index .Params 0 }}' data-ratio='1.33333333333333' src='//speakerdeck.com/assets/embed.js'></script>
 {{- end -}}`},
-       {`shortcodes/tweet.html`, `{{- $pc := .Page.Site.Config.Privacy.Tweet -}}
+       {`shortcodes/twitter.html`, `{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
 {{- if not $pc.Disable -}}
 {{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
 {{- end -}}`},
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/tweet.html b/tpl/tplimpl/embedded/templates/shortcodes/tweet.html
deleted file mode 100755 (executable)
index 09adaf7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{{- $pc := .Page.Site.Config.Privacy.Tweet -}}
-{{- if not $pc.Disable -}}
-{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
-{{- end -}}
\ No newline at end of file
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/twitter.html b/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
new file mode 100755 (executable)
index 0000000..d9bef72
--- /dev/null
@@ -0,0 +1,4 @@
+{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
+{{- if not $pc.Disable -}}
+{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
+{{- end -}}
\ No newline at end of file
index 7c7d639f0ef56165aea0f59d82a626b1916035fe..74860b67e45a12271385e6092ab5e272f9e1e653 100644 (file)
@@ -686,10 +686,21 @@ func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) e
        }
 }
 
+var embeddedTemplatesAliases = map[string][]string{
+       "shortcodes/twitter.html": []string{"shortcodes/tweet.html"},
+}
+
 func (t *templateHandler) loadEmbedded() {
        for _, kv := range embedded.EmbeddedTemplates {
                // TODO(bep) error handling
-               t.addInternalTemplate(kv[0], kv[1])
+               name, templ := kv[0], kv[1]
+               t.addInternalTemplate(name, templ)
+               if aliases, found := embeddedTemplatesAliases[name]; found {
+                       for _, alias := range aliases {
+                               t.addInternalTemplate(alias, templ)
+                       }
+
+               }
        }
 
 }