Skip to content
Permalink
Browse files

Support for Twitter share button

  • Loading branch information...
Depado committed Apr 6, 2018
1 parent 7c2d802 commit 6c75bf3e5b53a6d33c1a498548a6342061a9d9dd
Showing with 40 additions and 25 deletions.
  1. +11 −16 assets/style.css
  2. +1 −0 cmd/root.go
  3. +3 −1 templates/index.tmpl
  4. +13 −8 templates/post.tmpl
  5. +11 −0 templates/share.tmpl
  6. +1 −0 views/views.go
@@ -2,12 +2,13 @@
html, button, input, select, textarea,
.pure-g [class *= "pure-u"] {
font-family: 'Roboto', serif;
font-size: 18px;
}
body {
font-family: 'Roboto', serif;
text-align: justify;
line-height: 1.6;
font-size: 18px;
font-size: 0; /* Fix for unexpected whitespaces showing up */
color: #444;
padding: 0 10px;
background-color: #FFF;
@@ -91,7 +92,6 @@ cite {
nav > ul > li {
padding-top: 0.6em;
}
/* Code related stuff */

code[class*="language-"], pre[class*="language-"] {
font-family: 'Roboto Mono';
@@ -146,31 +146,26 @@ pre>code {
width: 100%;
margin-top: 0;
}
.sm-tag {
background: grey;
.btn {
display: inline-block;
color: #fff;
position: relative;
border-radius: 16px;
padding-left: 0.6em;
padding-right: 0.6em;
padding-top: 0.2em;
padding-bottom: 0.2em;
text-decoration: none;
font-size: 14px;
margin: 3px;
}
.home-sm-tag {
.twitter {
background: #00aced;
color: #fff;
border-radius: 5%;
padding-top: 0.2em;
padding-bottom: 0.2em;
}
.tag {
background: grey;
display: inline-block;
color: #fff;
position: relative;
border-radius: 16px;
padding-left: 0.6em;
padding-right: 0.6em;
text-decoration: none;
font-size: 14px;
margin: 3px;
}
.footerinfo {
text-align: center;
@@ -43,6 +43,7 @@ func init() {
rootCmd.PersistentFlags().String("blog.author.github", "", "github username of the author")
rootCmd.PersistentFlags().String("blog.author.site", "", "website of the author")
rootCmd.PersistentFlags().String("blog.author.avatar", "", "URL to the author's avatar")
rootCmd.PersistentFlags().Bool("blog.share", false, "add a Twitter share button on articles")

// Flag binding
viper.BindPFlags(rootCmd.PersistentFlags())
@@ -26,7 +26,9 @@
{{ if .extra }}<b>{{ .extra }}</b><br /><br />{{ end }}
{{ range .posts }}
<a href="/post/{{ .Slug }}">{{ .Title }}</a>{{ if .Draft }}<span class="draft">Draft</span>{{ end }}<br />
{{ range .Tags }}{{ if not $.local }}<a href="/tag/{{ . }}">{{ end }}<span class="home-sm-tag">{{ . }}</span>{{ if not $.local }}</a>{{ end }}{{ end }}
{{ range .Tags }}
{{ if not $.local }}<a href="/tag/{{ . }}">{{ end }}<span class="btn tag">{{ . }}</span>{{ if not $.local }}</a>{{ end }}
{{ end }}
<span style="float: right;">{{ .DateFmt }}</span><br />
<hr style="background: #e3e1e1;">
{{ end }}
@@ -6,19 +6,15 @@
<title>{{ .post.Title }}</title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet" type="text/css">
<link href="/static/grids-responsive-min.css" rel="stylesheet" />
<link href="/static/style.css" rel="stylesheet" />
<link href="/static/grids-responsive-min.css" rel="stylesheet" />
{{ if .gitalk.Enabled }}
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
{{ end }}
<script defer src="https://use.fontawesome.com/releases/v5.0.9/js/all.js" integrity="sha384-8iPTk2s/jMVj81dnzb/iFR2sdA7u06vHJyyLlAd4snFpCl/SnyUjRrbdJsw1pGIl" crossorigin="anonymous"></script>
<link rel="icon" href="/static/favicon.gif">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ if .extra_style }}
<style>
{{ .extra_style }}
</style>
{{ end }}
{{ if .extra_style }}<style>{{ .extra_style }}</style>{{ end }}
</head>

<body>
@@ -31,9 +27,11 @@
{{ if .post.Banner }}<img src="{{ .post.Banner }}" alt="banner">{{ end }}
<h1 class="title">{{ .post.Title }}</h1>
{{ if .post.Description }}<p>{{ .post.Description }}</p>{{ end }}
{{ range .Tags }}{{ if not $.local }}<a href="/tag/{{ . }}">{{ end }}<span class="home-sm-tag">{{ . }}</span>{{ if not $.local }}</a>{{ end }}{{ end }}
{{ range .post.Tags }}
{{ if not $.local }}<a href="/tag/{{ . }}">{{ end }}<span class="btn tag">{{ . }}</span>{{ if not $.local }}</a>{{ end }}
{{ end }}
{{ if .post.Author }}
{{ template "author" .post.Author }}
{{ template "author" .post.Author }}
{{ end }}
</div>
<div class="md">
@@ -46,6 +44,13 @@
<div id="gitalk-container"></div>
{{ end }}
</div>
<div class="pure-u-1 pure-u-md-1-4">
{{ if .share }}
<div style="float: right;">
{{ template "share" .post }}
</div>
{{ end }}
</div>
</div>
{{ if .gitalk.Enabled }}
<script id="gt" defer src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
@@ -0,0 +1,11 @@
{{ define "share" }}
{{ if .Author }}
{{ if .Author.Twitter }}
<a target="_blank" href='http://twitter.com/share?text="{{ .Title }}" by @{{ .Author.Twitter }}'><span class="btn twitter"><i class="fab fa-twitter"></i> Tweet</span></a>
{{ else }}
<a target="_blank" href='http://twitter.com/share?text="{{ .Title }}" by {{ .Author.Name }}'><span class="btn twitter"><i class="fab fa-twitter"></i> Tweet</span></a>
{{ end }}
{{ else }}
<a target="_blank" href='http://twitter.com/share?text="{{ .Title }}"'><span class="btn twitter"><i class="fab fa-twitter"></i> Tweet</span></a>
{{ end }}
{{ end }}
@@ -44,6 +44,7 @@ func Post(c *gin.Context) {
"post": val,
"gitalk": models.GetGitalk(),
"extra_style": models.GlobCSS,
"share": viper.GetBool("blog.share"),
}
c.HTML(http.StatusOK, "post.tmpl", data)
} else {

0 comments on commit 6c75bf3

Please sign in to comment.
You can’t perform that action at this time.