From 0636b7ac64390d02b4454555dacb21047939fb82 Mon Sep 17 00:00:00 2001 From: yonicd <yonicd@gmail.com> Date: Mon, 16 Oct 2017 15:21:22 -0400 Subject: [PATCH] Badge functionality to layout/post.html (#265) * add badges to default branch * add instructions in readme for post badges * update readme * add instructions for badges to readme yaml * switch GH badges to iframes and remove comment out cran badges * remove cran comment and update yaml table in readme file. * Update README.md * Update main.css --- README.md | 2 ++ _layouts/post.html | 23 +++++++++++++++++++++++ css/main.css | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/README.md b/README.md index 690c0ce..ceeae0f 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,8 @@ ext-js | List of external JavaScript files to include in the page (eg. `//c css | List of local CSS files to include in the page ext-css | List of external CSS files to include in the page. External CSS files using SRI (see `ext-js` parameter) are also supported. googlefonts | List of Google fonts to include in the page (eg. `["Monoton", "Lobster"]`) +gh-repo | If you want to show GitHub buttons at the top of a post, this sets the GitHub repo name (eg. `daattali/beautiful-jekyll`). You must also use the `gh-badge` parameter to specify what buttons to show. +gh-badge | Select which GitHub buttons to display, available options are: [star, watch, fork, follow]. You must also use the `gh-repo` parameter to specify the GitHub repo. ### Advanced features (including how to use a custom URL address for your site) diff --git a/_layouts/post.html b/_layouts/post.html index bd3c20c..1055722 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -8,6 +8,29 @@ layout: base <div class="row"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> + {% if page.gh-repo %} + {% assign gh_split = page.gh-repo | split:'/' %} + {% assign gh_user = gh_split[0] %} + {% assign gh_repo = gh_split[1] %} + + <div id="header-gh-btns"> + {% if page.gh-badge.size > 0 %} + {% for badge in page.gh-badge %} + {% case badge %} + {% when 'star'%} + <iframe src="https://ghbtns.com/github-btn.html?user={{ gh_user }}&repo={{ gh_repo }}&type=star&count=true" frameborder="0" scrolling="0" width="120px" height="20px"></iframe> + {% when 'watch'%} + <iframe src="https://ghbtns.com/github-btn.html?user={{ gh_user }}&repo={{ gh_repo }}&type=watch&v=2&count=true" frameborder="0" scrolling="0" width="120px" height="20px"></iframe> + {% when 'fork'%} + <iframe src="https://ghbtns.com/github-btn.html?user={{ gh_user }}&repo={{ gh_repo }}&type=fork&count=true" frameborder="0" scrolling="0" width="120px" height="20px"></iframe> + {% when 'follow'%} + <iframe src="https://ghbtns.com/github-btn.html?user={{ gh_user }}&type=follow&count=true" frameborder="0" scrolling="0" width="220px" height="20px"></iframe> + {% endcase %} + {% endfor %} + {% endif %} + </div> + {% endif %} + <article role="main" class="blog-post"> {{ content }} </article> diff --git a/css/main.css b/css/main.css index 5d84d69..51c9181 100644 --- a/css/main.css +++ b/css/main.css @@ -589,6 +589,16 @@ footer .theme-by { border-bottom-left-radius: 5px; } +#header-gh-btns { + margin-bottom: 15px; +} +@media only screen and (max-width: 500px) { + #header-gh-btns > iframe { + display: block; + margin-bottom: 5px; + } +} + /* --- Pager --- */ .pager li a {