From c68d6c023c7b75fe884be55442151a97c9322a3f Mon Sep 17 00:00:00 2001 From: parsiya Date: Sun, 6 May 2018 00:00:35 -0400 Subject: Add twitter card support --- README.md | 31 ++++++++++++++++++++++++++++++- layouts/partials/custom_twitter_card.html | 16 ++++++++++++++++ layouts/partials/header.html | 6 +++++- sample-config.toml | 9 +++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 layouts/partials/custom_twitter_card.html 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. +## 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`. + ## 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 @@ + +{{ if .IsPage }} + {{ with .Params.twitterImage }} + + + + {{ else }} + + {{ end }} + + + + {{ with .Site.Params.twitterCardSite }}{{ end }} + {{ with .Site.Params.twitterCardDomain }}{{ end }} + {{ with .Site.Params.twitterCardAuthor }}{{ 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 @@ {{ if not .Site.Params.disableGoogleFonts }} - {{ if not .Site.Params.remoteFonts }} @@ -58,6 +57,11 @@ {{ template "_internal/google_analytics_async.html" . }} + + {{ with .Site.Params.twitterCardEnabled }} + {{ partial "custom_twitter_card.html" $ }} + {{ 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 -- cgit v1.2.3