Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/parsiya/Hugo-Octopress.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparsiya <parsiya@gmail.com>2018-05-06 07:00:35 +0300
committerparsiya <parsiya@gmail.com>2018-05-06 07:00:35 +0300
commitc68d6c023c7b75fe884be55442151a97c9322a3f (patch)
treef053c8f6e39ccace846ff713b98c0b23a4524ac1
parentbe1373dfc0ec402ed42f6249b411eda7f1c1af2f (diff)
Add twitter card support
-rw-r--r--README.md31
-rwxr-xr-xlayouts/partials/custom_twitter_card.html16
-rw-r--r--layouts/partials/header.html6
-rw-r--r--sample-config.toml9
4 files changed, 60 insertions, 2 deletions
diff --git a/README.md b/README.md
index 0e16396..e0bd06b 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@ My personal website runs a modified version of the theme (mainly modified index)
- [Taxonomy pages](#taxonomy)
- [Individual pages](#page)
- [Disqus](#disqus)
+- [Twitter Card](#twitter)
- [Issues/TODO](#issues)
- [Attribution](#attribution)
- [Ported by](#portedby)
@@ -48,7 +49,6 @@ theme = "hugo-octopress"
# Disable comments for any individual post by adding "comments: false" in its frontmatter
disqusShortname = "Your disqus shortname"
-
# Number of blog posts in each pagination page
paginate = 6
@@ -440,6 +440,35 @@ disqusShortname = "whatever"
The disqus partial is at `layouts/partials/disqus.html`. By default it does not add Disqus when you are testing on localhost using the test server. This can be disabled (e.g. if you want to test Disqus locally) by commenting the `if and return` lines in the partial above.
+## <a name="twitter"></a>Twitter Card
+Twitter card support can be enabled in the config file under `Params`:
+
+``` toml
+[params]
+ # Twitter card config
+ # Enable with this.
+ twitterCardEnabled = true
+ # Don't include the @.
+ # twitterCardSite =
+ twitterCardDomain = "parsiya.net"
+ # Don't include the @.
+ twitterCardAuthor = "CryptoGangsta"
+```
+
+After Twitter card is enabled, you can add summary images to your posts via front matter through `twitterImage`:
+
+``` yaml
+twitterImage: 02-fuzzer-crash.png
+```
+
+**Note:** Image URL should be relative to the page, otherwise the final URL will not be correct. In short, image URL should be part of the page bundle. In this case, both `index.md` and `02-fuzzer-crash.png` are in the same root directory. If the image is in a subdirectory of page bundle, it can be added like this:
+
+``` yaml
+twitterImage: images/02-fuzzer-crash.png
+```
+
+The template can be modified at `Hugo-Octopress/partials/custom_twitter_card.html`.
+
## <a name="issues"></a>Issues/TODO
If you discover any issues/bugs or want new features please use the Github issue tracker. Please keep in my mind that development has not been my day job for quite a while and I may be slow in fixing things (don't be surprised if I ask you about details).
diff --git a/layouts/partials/custom_twitter_card.html b/layouts/partials/custom_twitter_card.html
new file mode 100755
index 0000000..6a77dd1
--- /dev/null
+++ b/layouts/partials/custom_twitter_card.html
@@ -0,0 +1,16 @@
+<!-- Modified from _internal/twitter_card.html -->
+{{ if .IsPage }}
+ {{ with .Params.twitterImage }}
+ <!-- Twitter summary card with large image must be at least 280x150px -->
+ <meta name="twitter:card" content="summary_large_image"/>
+ <meta name="twitter:image:src" content="{{ index . 0 | absURL }}"/>
+ {{ else }}
+ <meta name="twitter:card" content="summary"/>
+ {{ end }}
+ <!-- Twitter Card data -->
+ <meta name="twitter:title" content="{{ .Title }}"/>
+ <meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"/>
+ {{ with .Site.Params.twitterCardSite }}<meta name="twitter:site" content="@{{ . }}"/>{{ end }}
+ {{ with .Site.Params.twitterCardDomain }}<meta name="twitter:domain" content="{{ . }}"/>{{ end }}
+ {{ with .Site.Params.twitterCardAuthor }}<meta name="twitter:creator" content="@{{ . }}"/>{{ end }}
+{{ end }} \ No newline at end of file
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index 4cb78df..de38c7a 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -10,7 +10,6 @@
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1">
{{ if not .Site.Params.disableGoogleFonts }}
-
<!-- If local Google Fonts are enabled -->
{{ if not .Site.Params.remoteFonts }}
<link href="/css/fonts.css" rel="stylesheet" type="text/css">
@@ -58,6 +57,11 @@
<!-- Google Analytics -->
{{ template "_internal/google_analytics_async.html" . }}
+ <!-- Enable Twitter card -->
+ {{ with .Site.Params.twitterCardEnabled }}
+ {{ partial "custom_twitter_card.html" $ }}
+ {{ end }}
+
</head>
<body{{ with .Site.Params.theme }} class="{{ . }}"{{ end }}>
diff --git a/sample-config.toml b/sample-config.toml
index 50f1e00..65088cb 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -139,6 +139,15 @@ post = "/blog/:year-:month-:day-:title/" # change the post URL to look like the
# This is not needed unless alphabetical sort is needed
# sortTaxonomyAlphabetical = true
+ # Twitter card config
+ # Enable with this.
+ # twitterCardEnabled = true
+ # Don't include the @.
+ # twitterCardSite =
+ # twitterCardDomain = "parsiya.net"
+ # Don't include the @.
+ # twitterCardAuthor = "CryptoGangsta"
+
# Menu
# If navigationNewWindow (under [params]) is set to true then all links except root ("/") will open in a new window
# If it does not exist or is set to false then links will open in the same window