Stephen Ajulu Share This Post

Share This Post.

Share This Post

Hi guys, if you are a blogger using gohugo. This is for you!

Can be copied as is.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102

<style>

  .webshare {

  justify-content: center;

  display:flex;

}

  #tip {

  display: none;

}

\#tip.show {

  display: block;

}

.wsbutton {

  border: 0;

  padding: 0;

  cursor: pointer;

  outline: 0;

  -webkit-appearance: none;

  display: inline-block;

  position: relative;

  padding: 10px 8px;

  top: 0;

  font-size: 15px;

  border-radius: 50px;

  border-bottom: 1px solid rgba(28, 227, 125, 0.5);

  background: rgba(22, 230, 137, 1);

  color: #fff;

  box-shadow: 0px 0px 0px rgba(15, 165, 60, 0.1);

}

</style>

<div class="webshare">

  <p id="tip">Your browser does not support the Web Share API! Try the other share buttons</p>

  <button id="share" class="wsbutton" title="Share This Post">Web Share</button>

</div>

<script>

  const share = e => {

  if (navigator.share) {

    navigator

      .share({

        title: "{{ .Title }}",

        text: "{{ .Params.excerpt }}",

        url: "{{ .RelPermalink }}"

      })

      .then(() => console.log("thanks for sharing"))

      .catch(error => console.log("error", error));

  }

};

if(!navigator.share) {

  document.getElementById('tip').className = 'show'

}

document.getElementById("share").addEventListener("click", share);

</script>

Save it as a partial and include it e.g {{ partial “share/webshare.html” . }}

Since I already have a fall back I will not include that here as I already mentioned it in another post.

Check it out.

Also Read:


Previous ← Share on Facebook
Next → My Automatic Feed Item URL Shortener and Sender to Email