Compare commits

...

7 Commits

Author SHA1 Message Date
Mark Dumay
5c54291eb8 Merge pull request #372 from gethinode/develop
Implement web sharing
2023-07-31 07:57:59 +02:00
Mark Dumay
2a862034aa Merge branch 'main' into develop 2023-07-31 07:40:43 +02:00
mark
56e0713582 Exclude sharing.js from linting 2023-07-31 07:39:58 +02:00
mark
23a3f7ef71 Bump package version 2023-07-31 07:39:02 +02:00
mark
3418ac8d1d Implement Support Web Share API #294 2023-07-31 07:38:29 +02:00
mark
c645024474 Support custom attributes 2023-07-31 07:37:53 +02:00
Mark Dumay
6dd208f671 Merge pull request #369 from gethinode/main
Sync with main
2023-07-30 14:45:38 +02:00
7 changed files with 51 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
assets/js/critical/color.js assets/js/critical/color.js
assets/js/analytics.js assets/js/analytics.js
assets/js/flexsearch.js assets/js/flexsearch.js
assets/js/sharing.js
assets/js/vendor assets/js/vendor
node_modules node_modules

36
assets/js/sharing.js Normal file
View File

@@ -0,0 +1,36 @@
{{- if site.Params.sharing.webshare -}}
// Adapted from: https://dev.to/j471n/how-to-share-anything-from-your-website-by-web-share-api-1h5g
// function for Web Share API
function webShareAPI (title, description, link) {
navigator
.share({
title,
text: description,
url: link
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error))
}
const shareBtn = document.getElementById('btn-webshare')
if (shareBtn !== null) {
if (navigator.share) {
const title = shareBtn.getAttribute('data-sharing-title')
const description = shareBtn.getAttribute('data-sharing-description')
const url = shareBtn.getAttribute('data-sharing-url')
// show button if it supports webShareAPI
shareBtn.style.display = 'block'
shareBtn.addEventListener('click', () =>
webShareAPI(title, description, url)
)
} else {
// hide button if host does not support Web Share API
shareBtn.style.display = 'none'
}
}
{{- end -}}

View File

@@ -63,6 +63,7 @@
enabled = true enabled = true
sort = "weight" sort = "weight"
reverse = false reverse = false
webshare = true
[[sharing.providers]] [[sharing.providers]]
name = "LinkedIn" name = "LinkedIn"

View File

@@ -26,6 +26,7 @@
"main.externalLinks.cue" in the site's parameters. "main.externalLinks.cue" in the site's parameters.
"tab" Optional flag to indicate if an external link should open in a new tab, defaults to setting "tab" Optional flag to indicate if an external link should open in a new tab, defaults to setting
"main.externalLinks.tab" in the site's parameters. "main.externalLinks.tab" in the site's parameters.
"attributes" Optional dictionary of key-value pairs added as custom attributes to the button element ('<a>').
--> -->
{{- $title := trim .title " \r\n" -}} {{- $title := trim .title " \r\n" -}}
@@ -136,6 +137,8 @@
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- $attributes := .attributes -}}
<a aria-label="{{ $title }}" {{ if ne $state "disabled" }}{{ with $href }}href="{{ . }}"{{ end }}{{ end }} <a aria-label="{{ $title }}" {{ if ne $state "disabled" }}{{ with $href }}href="{{ . }}"{{ end }}{{ end }}
{{ with $id }}id="{{ . }}"{{ end }} {{ with $id }}id="{{ . }}"{{ end }}
{{ with $target }}target="{{ . }}"{{ end }}{{ with $rel }} rel="{{ . }}"{{ end }} {{ with $target }}target="{{ . }}"{{ end }}{{ with $rel }} rel="{{ . }}"{{ end }}
@@ -148,6 +151,9 @@
{{ with $collapse }}data-bs-toggle="collapse" aria-expanded="false" aria-controls="{{ . }}"{{ end }} {{ with $collapse }}data-bs-toggle="collapse" aria-expanded="false" aria-controls="{{ . }}"{{ end }}
{{ if eq $state "active" }}data-bs-toggle="button" aria-pressed="true"{{ end }} {{ if eq $state "active" }}data-bs-toggle="button" aria-pressed="true"{{ end }}
{{ if eq $state "inactive" }}data-bs-toggle="button" aria-pressed="false"{{ end }} {{ if eq $state "inactive" }}data-bs-toggle="button" aria-pressed="false"{{ end }}
{{ range $key, $val := $attributes }}
{{ print $key | safeHTMLAttr }}="{{ $val }}"
{{ end }}
> >
<div class="d-flex justify-content-{{ $justify }}"> <div class="d-flex justify-content-{{ $justify }}">

View File

@@ -23,6 +23,10 @@
{{- end -}} {{- end -}}
{{ partial "assets/button.html" (dict "toast" $target "clipboard" $clipboard "href" $url "icon" (printf "%s fa-fw" $item.icon) "class" "btn-social p-0" )}} {{ partial "assets/button.html" (dict "toast" $target "clipboard" $clipboard "href" $url "icon" (printf "%s fa-fw" $item.icon) "class" "btn-social p-0" )}}
{{- end -}} {{- end -}}
{{ if .Site.Params.sharing.webshare }}
{{ $attr := dict "data-sharing-title" .Title "data-sharing-description" .Description "data-sharing-url" .Permalink }}
{{ partial "assets/button.html" (dict "href" "#!" "icon" "fas share-nodes fa-fw" "id" "btn-webshare" "class" "btn-social p-0" "attributes" $attr )}}
{{- end -}}
</div> </div>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@gethinode/hinode", "name": "@gethinode/hinode",
"version": "0.16.8", "version": "0.16.9",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@gethinode/hinode", "name": "@gethinode/hinode",
"version": "0.16.8", "version": "0.16.9",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@fortawesome/fontawesome-free": "^6.4.0", "@fortawesome/fontawesome-free": "^6.4.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@gethinode/hinode", "name": "@gethinode/hinode",
"version": "0.16.8", "version": "0.16.9",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator", "description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [ "keywords": [
"hugo", "hugo",