Skip to content
Snippets Groups Projects
Commit 927f87c2 authored by Régis Witz's avatar Régis Witz
Browse files

:lipstick: rajoute la possibilité d'utiliser le theme ananke

https://github.com/theNewDynamic/gohugo-theme-ananke
parent ec0d6da7
Branches
No related merge requests found
Showing
with 514 additions and 0 deletions
{{/*
GetFeaturedImage
This partial gets the url for featured image for a given page.
If a featured_image was set in the page's front matter, then that will be used.
If not set, this will search page resources to find an image that contains the word
"cover", and if found, returns the path to that resource.
If no featured_image was set, and there's no "cover" image in page resources, then
this partial returns an empty string (which evaluates to false).
@return RelPermalink to featured image, or an empty string if not found.
*/}}
{{/* Declare a new string variable, $linkToCover */}}
{{ $linkToCover := "" }}
{{ $matches := "feature,cover" }}
{{/* Use the value from front matter if present */}}
{{ with .Params.featured_image }}
{{ $linkToCover = . }}
{{/* If we find a Page Resource matching the exact value, we use it instead. */}}
{{ with $.Resources.GetMatch . }}
{{ $linkToCover = .RelPermalink }}
{{ end }}
{{/* Find the first image with 'cover' in the name in this page bundle. */}}
{{ else }}
{{ with .Resources.ByType "image" }}
{{ with .GetMatch (printf "**{%s}*" $matches) }}
{{ $linkToCover = .RelPermalink }}
{{ end }}
{{ end }}
{{ end }}
{{/* return either a permalink, or an empty string. Note that partials can only have a single
return statement, so this needs to be at the end of the partial (and not in the if block) */}}
{{ return $linkToCover }}
{{ $dir := "" }}
{{ if ge hugo.Version "0.67.1" }}
{{ with site.Language.LanguageDirection }}
{{ $dir = . }}
{{ end }}
{{ end }}
{{ return $dir }}
{{/*
socials/Get
Returns the list of services registered by the user complemented by the built-in service default data if found.
@author @regisphilibert
@context Any (.)
@access public
@returns Slice of Maps
- String (.name)
String (.url)
String (.label)
String (.color)?
Bool (.share)?
@uses
- partial
@example - Go Template
{{ with partialCached "socials/Get" context context }}
{{ something = . }}
{{ end }}
*/}}
{{ $socials := slice }}
{{ with partial "func/socials/GetRegisteredServices" "GetRegisteredServices" }}
{{ range . }}
{{ $service := . }}
{{/* We fetch the default data and add it to service map if found */}}
{{ with partialCached "func/socials/GetServiceData" .name .name }}
{{ $service = merge . $service }}
{{ end }}
{{/* We fetch the icon and add it to service map fi found */}}
{{ with partialCached "func/socials/GetServiceIcon" .name .name }}
{{ $service = $service | merge (dict "icon" . ) }}
{{ end }}
{{/* In case no label is provided (on a non-built-in service) we add the .name as label to the service map */}}
{{ with .label }}{{ else }}
{{ $service = $service | merge (dict "label" $service.name ) }}
{{ end }}
{{ $socials = $socials | append $service }}
{{ end }}
{{ end }}
{{ return $socials }}
\ No newline at end of file
{{/*
GetBuiltInServicesData
Returns a map whose keys stores the map of defaults data for any built-in service.
We use a key to easily grab the data with `index $that github`
@author @regisphilibert
@context Any (.)
@access public
@returns Map
## Contributors can add a built-in service
1. Adding it to the following map with the following format:
```yaml
# [...]
shinyandnew:
label: Shiny And New
color: '#cccccc'
```
2. Edit README file with new service https://github.com/theNewDynamic/gohugo-theme-ananke/tree/422-improve-socials#built-in-services
*/}}
{{ return (`
facebook:
share: true
label: Facebook
color: '#3b5998'
twitter:
share: true
label: Twitter
color: '#1da1f2'
instagram:
label: Instagram
color: '#e1306c'
youtube:
label: YouTube
color: '#cd201f'
github:
label: GitHub
color: '#6cc644'
gitlab:
label: GitLab
color: '#FC6D26'
keybase:
label: Keybase
color: '#3d76ff'
linkedin:
share: true
label: LinkedIn
color: '#0077b5'
medium:
label: Medium
color: '#0077b5'
mastodon:
label: Mastodon
color: '#3088d4'
slack:
label: Slack
color: '#E01E5A'
stackoverflow:
label: Stack Overflow
color: '#f48024'
rss:
label: RSS
color: '#ff6f1a'
tiktok:
label: TikTok
color: '#fe2c55'
` | transform.Unmarshal) }}
\ No newline at end of file
{{/*
socials/GetRegisteredServices
Retrieves the list of user registered services.
Support legacy settings (root of params with service name as key)
@author @regisphilibert
@context Any (.)
@access private
@returns Slice of Maps
- String (.name)
String (.url)
String (.label)?
String (.color)?
*/}}
{{ $registered_services := slice }}
{{/* We first look for legacy settings that lives at the root of the site.Params as such (github: https://github.com/
theNewDynamic) and them to the list with key as .name and value as .url */}}
{{ $user_using_legacy := false }}
{{ $legacy_api_services := slice "facebook" "twitter" "instagram" "youtube" "github" "gitlab" "keybase" "linkedin" "medium" "mastodon" "slack" "stackoverflow" "rss" }}
{{ range $name := $legacy_api_services }}
{{ with $url := index site.Params . }}
{{/* If we can find a parameter matching the key with a set value, we add it with proper name and url */}}
{{/* We also note that user is using legacy for potential potential deprecation warnings */}}
{{ $user_using_legacy = true }}
{{ $registered_services = $registered_services | append (dict "name" $name "url" $url) }}
{{ end }}
{{ end }}
{{/* Then we go through the current way of registering services as per referenced in README */}}
{{ with site.Params.ananke_socials }}
{{ range $service := . }}
{{/* Only if the service has a .name, we add it all its keys to the slice of registered services */}}
{{ with .name }}
{{ $registered_services = $registered_services | append $service }}
{{ end }}
{{ end }}
{{ end }}
{{ return $registered_services }}
\ No newline at end of file
{{/*
socials/GetServiceDefaults
Returns the defaults of any given service as stored in GetBuildInServicesDefaults
@author @regisphilibert
@context String (.)
@access private
@returns Map
- String (.label)
String (.color)
@uses
- func/socials/GetBuiltInServicesDefaults
*/}}
{{ $service_data := dict }}
{{ with partialCached "func/socials/GetBuiltInServicesDefaults" "socials/GetBuiltInServicesDefaults" }}
{{/* If the passed context string (held in $) is found as a key of the map returned by the above returning partial
We store it in the returning variable */}}
{{ with index . $ }}
{{ $service_data = . }}
{{ end }}
{{ end }}
{{ return $service_data }}
\ No newline at end of file
{{/*
GetServiceIcon
User can overwrite/complement in assets/ananke/socials/{service_name}.svg
@author @regisphilibert
@context String (.)
@access private
@return String of safe HTML
@example - Go Template
{{ $icon := partialCached "tnd-socials/private/GetIcon" $icon $icon }}
*/}}
{{ $icon := "" }}
{{ with resources.Get (printf "ananke/socials/%s.svg" $) }}
{{ $icon = .Content | safeHTML }}
{{ end }}
{{ return $icon }}
\ No newline at end of file
{{/*
style/GetMainCSS
Process the main css stylesheet and return as resource
@author @regisphilibert
@context Any (.)
@returns Resource
@uses
- func/style/GetResource
*/}}
{{ $main_style := dict }}
{{/* We prepare a slice of resources to be concatenated as one */}}
{{ $assets_to_concat := slice }}
{{/* We add locale css files to the slice in the proper order */}}
{{ range slice "_tachyons.css" "_code.css" "_hugo-internal-templates.css" "_social-icons.css" "_styles.css" }}
{{ with partialCached "func/style/GetResource" . . }}
{{ $assets_to_concat = $assets_to_concat | append . }}
{{ end }}
{{ end }}
{{ with partialCached "func/socials/Get" "socials/Get" }}
{{ $socials_rules := slice }}
{{ range $service := . }}
{{ with .color }}
{{ $rule := printf `
.ananke-socials a.%s:hover {
color: %s
}` $service.name $service.color }}
{{ $socials_rules = $socials_rules | append $rule }}
{{ end }}
{{ end }}
{{ with $socials_rules }}
{{ $socials_rules = delimit . "" }}
{{ $socials_css := $socials_rules | resources.FromString "ananke/css/generated_socials.css" }}
{{ $assets_to_concat = $assets_to_concat | append $socials_css }}
{{ end }}
{{ end }}
{{/* We look for any custom css files registered by the user under `site.params.custom_css and if found in the theme's
css asset directory we (unless condition below) add to aforementioned slice */}}
{{ with site.Params.custom_css }}
{{ range . }}
{{ with partialCached "func/style/GetResource" . . }}
{{ if eq .MediaType.SubType "x-scss" "x-sass" "scss" "sass" }}
{{ if hugo.IsExtended }}
{{/* as we cannot concatenate styles of different types, we sass/scss to be transformed to css beforehand */}}
{{ $assets_to_concat = $assets_to_concat | append (. | resources.ToCSS) }}
{{ else }}
{{ partial "func/warn" (printf "Processing of stylesheet %s of type %s has been skipped. You need Hugo Extended to process such files." .Name .MediaType.SubType) }}
{{ end }}
{{ else }}
{{ $assets_to_concat = $assets_to_concat | append . }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ with $assets_to_concat }}
{{/* We proceed to concatenate the $assets_to_concat */}}
{{ $style := . | resources.Concat "ananke/css/main.css" }}
{{/* We then use toCSS to add sourceMap and minify */}}
{{ $options := dict "enableSourceMap" true "precision" 6 }}
{{ $style = $style | resources.ToCSS $options | minify }}
{{/* We fingerprint in production for cache busting purposes */}}
{{ if eq (getenv "HUGO_ENV") "production" }}
{{ $style = $style | fingerprint }}
{{ end }}
{{/* We're ready to set returning variable with resulting resource */}}
{{ $main_style = $style }}
{{ end }}
{{ return $main_style }}
\ No newline at end of file
{{/*
style/GetResource
Get a style asset stored at `/assets/ananke/css`
@author @regisphilibert
@context String (.)
@access private
@returns Resource
*/}}
{{ $resource := dict }}
{{ with resources.Get (print "/ananke/css/" .) }}
{{ $resource = . }}
{{ end }}
{{ return $resource }}
\ No newline at end of file
{{/*
warn
Emits a warning using the theme's Header.
@author @regisphilibert
@context String
@access private
@example - Go Template
{{ partial "func/warn" $message }}
*/}}
{{ $header := "Ananke Theme Warning" }}
{{ warnf "\n%s:\n%s" $header . }}
\ No newline at end of file
{{ if .IsTranslated }}
<h4>{{ i18n "translations" }}</h4>
<ul class="{{ cond (eq $.Site.Language.LanguageDirection "rtl") "pr0 ml3" "pl0 mr3" }}">
{{ range .Translations }}
<li class="list f5 f4-ns fw4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl3" "pr3" }}">
<a class="hover-white no-underline white-90" href="{{ .RelPermalink }}">{{ .Lang }}</a>
</li>
{{ end}}
</ul>
{{ end }}
{{/*
Use Hugo's native Table of contents feature. You must set `toc: true` in your parameters for this to show.
https://gohugo.io/content-management/toc/
*/}}
{{- if .Params.toc -}}
<div class="bg-light-gray pa3 nested-list-reset nested-copy-line-height nested-links">
<p class="f5 b mb3">{{ i18n "whatsInThis" . }}</p>
{{ .TableOfContents }}
</div>
{{- end -}}
{{/*
Use Hugo's native related content feature to pull in content that may have similar parameters, like tags. etc.
https://gohugo.io/content-management/related/
*/}}
{{ $related := .Site.RegularPages.Related . | first 15 }}
{{ with $related }}
<div class="bg-light-gray pa3 nested-list-reset nested-copy-line-height nested-links">
<p class="f5 b mb3">{{ i18n "related" }}</p>
<ul class="pa0 list">
{{ range . }}
<li class="mb2">
<a href="{{ .RelPermalink }}">
{{- .Title -}}
</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}
{{ $new_window_icon_size := "8px" }}
<span class="new-window">{{ partial "svg/new-window.svg" (dict "size" $new_window_icon_size) }}</span>
\ No newline at end of file
{{ $featured_image := partial "func/GetFeaturedImage.html" . }}
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
{{ $featured_image := (trim $featured_image "/") | absURL }}
<header class="cover bg-top" style="background-image: url('{{ $featured_image }}');">
<div class="bg-black-60">
{{ partial "site-navigation.html" . }}
<div class="tc-l pv6 ph3 ph4-ns">
{{ if not .Params.omit_header_text }}
<h1 class="f2 f1-l fw2 white-90 mb0 lh-title">{{ .Title | default .Site.Title }}</h1>
{{ with .Params.description }}
<h2 class="fw1 f5 f3-l white-80 measure-wide-l center lh-copy mt3 mb4">
{{ . }}
</h2>
{{ end }}
{{ end }}
</div>
</div>
</header>
{{ else }}
<header>
<div class="{{ .Site.Params.background_color_class | default "bg-black" }}">
{{ partial "site-navigation.html" . }}
</div>
</header>
{{ end }}
{{ if .Site.Params.favicon }}
<link rel="shortcut icon" href="{{ relURL ($.Site.Params.favicon) }}" type="image/x-icon" />
{{ end }}
<footer class="{{ .Site.Params.background_color_class | default "bg-black" }} bottom-0 w-100 pa3" role="contentinfo">
<div class="flex justify-between">
<a class="f4 fw4 hover-white no-underline white-70 dn dib-ns pv2 ph3" href="{{ .Site.BaseURL }}" >
&copy; {{ with .Site.Copyright | default .Site.Title }} {{ . | safeHTML }} {{ now.Format "2006"}} {{ end }}
</a>
<div>{{ partial "social-follow.html" . }}</div>
</div>
</footer>
{{ $featured_image := partial "func/GetFeaturedImage.html" . }}
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
{{ $featured_image := (trim $featured_image "/") | absURL }}
<header class="cover bg-top" style="background-image: url('{{ $featured_image }}');">
<div class="{{ .Site.Params.cover_dimming_class | default "bg-black-60" }}">
{{ partial "site-navigation.html" .}}
<div class="tc-l pv4 pv6-l ph3 ph4-ns">
<h1 class="f2 f-subheadline-l fw2 white-90 mb0 lh-title">
{{ .Title | default .Site.Title }}
</h1>
{{ with .Params.description }}
<h2 class="fw1 f5 f3-l white-80 measure-wide-l center mt3">
{{ . }}
</h2>
{{ end }}
</div>
</div>
</header>
{{ else }}
<header>
<div class="pb3-m pb6-l {{ .Site.Params.background_color_class | default "bg-black" }}">
{{ partial "site-navigation.html" . }}
<div class="tc-l pv3 ph3 ph4-ns">
<h1 class="f2 f-subheadline-l fw2 light-silver mb0 lh-title">
{{ .Title | default .Site.Title }}
</h1>
{{ with .Params.description }}
<h2 class="fw1 f5 f3-l white-80 measure-wide-l center lh-copy mt3 mb4">
{{ . }}
</h2>
{{ end }}
</div>
</div>
</header>
{{ end }}
<nav class="pv3 ph3 ph4-ns" role="navigation">
<div class="flex-l justify-between items-center center">
<a href="{{ .Site.Home.RelPermalink }}" class="f3 fw2 hover-white no-underline white-90 dib">
{{ with .Site.Params.site_logo }}
<img src="{{ relURL . }}" class="w100 mw5-ns" alt="{{ $.Site.Title }}" />
{{ else }}
{{ .Site.Title }}
{{ end }}
</a>
<div class="flex-l items-center">
{{ partial "i18nlist.html" . }}
{{ if .Site.Menus.main }}
<ul class="{{ cond (eq $.Site.Language.LanguageDirection "rtl") "pr0 ml3" "pl0 mr3" }}">
{{ range .Site.Menus.main }}
<li class="list f5 f4-ns fw4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl3" "pr3" }}">
<a class="hover-white no-underline white-90" href="{{ .URL }}" title="{{ i18n "pageTitle" . }}">
{{ .Name }}
</a>
</li>
{{ end }}
</ul>
{{ end }}
{{ partialCached "social-follow.html" . }}
</div>
</div>
</nav>
{{/* For Users's overwrite */}}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment