Requirements:
- Go 1.14
- Hugo 0.61.0
If not already, init your project as Hugo Module:
$: hugo mod init {repo_url}
Configure your project's module to import this module:
# config.yaml
module:
imports:
- path: github.com/theNewDynamic/hugo-module-tnd-socialsModule provides one partial called GetSocials which returns every or some Social services set in the project through the Module's configuration.
Returned services are maps structured as the following:
- String (.Name)
- String (.Handle)
- String (.URL)
- SVG (String of safe HTML)
If the given partial receives a .Page key with a Page object as value among its context, each service will sport an extra key:
- String (.ShareURL)
To simply print links pointing to the project's Social landing pages:
{{ range partialCached "tnd-socials/GetSocials" "GetSocials" }}
<a href="{{ .URL }}" title="Follow {{ .Handle }} on {{ .Name }}">
{{ .SVG }}
</a>
{{ end }}
By default, the partial will return all the services set though the module's configuration in their original order.
To limit or reorder services, the partial can take a slice as context:
{{ range partial "tnd-socials/GetSocials" (slice "facebook "twitter") }}
[...]
{{ end }}
The partial can also return a .ShareURL key for each services if it receives a .Page key among its context. The value is a share URL for the given services.
(Ex: https://www.linkedin.com/sharing/share-offsite/?url=https://example.com/that-article)
Chosen services discussed above will be hold in a services key.
{{ range partial "tnd-socials/GetSocials" (dict "Page" $ "services" (slice "facebook" "twitter")) }}
<a href="{{ .ShareURL }}" title="Share on {{ .Name }}">
{{ .SVG }}
</a>
{{ end }}
Services sporting a ShareURL are for now:
Icons are pulled from a default set but can easily be overwritten by adding svg files to your projects using the following naming convention:
assets/tnd-socials/{service|icon}.svg
The module can read Hugo's default Social settings but we recommand using the module's own .Params.tnd_socials reserved key for more control:
The services key takes a slice of Maps with the following keys:
- name*: The name of the service
- handle*: The username or handle of the service's profile. Use an email address for the
emailservice. - url: If the profile URL does not follow the conventional
https://www.{service}.com/{handle}it should be set here. - icon: Icon file's basename (no extension). Available icons are here
# config.yaml
params:
tnd_socials:
services:
- name: github
handle: theNewDynamic
- name: twitter
handle: JohnDoe
url: https://www.twitter.com/john67898
icon: twitter-alt
- name: email
handle: welcome@thenewdynamic.com