Initial site working
This commit is contained in:
41
themes/ananke/layouts/partials/func/GetFeaturedImage.html
Normal file
41
themes/ananke/layouts/partials/func/GetFeaturedImage.html
Normal file
@ -0,0 +1,41 @@
|
||||
{{/*
|
||||
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 }}
|
||||
{{/* This is the default case, the image lives in the static directory.
|
||||
In which case we'll use the static dir */}}
|
||||
{{ $linkToCover = trim . "/" | absURL }}
|
||||
{{/* 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 }}
|
@ -0,0 +1,7 @@
|
||||
{{ $dir := "" }}
|
||||
{{ if ge hugo.Version "0.67.1" }}
|
||||
{{ with site.Language.LanguageDirection }}
|
||||
{{ $dir = . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ return $dir }}
|
45
themes/ananke/layouts/partials/func/socials/Get.html
Normal file
45
themes/ananke/layouts/partials/func/socials/Get.html
Normal file
@ -0,0 +1,45 @@
|
||||
{{/*
|
||||
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 }}
|
@ -0,0 +1,73 @@
|
||||
{{/*
|
||||
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: '#6364FF'
|
||||
slack:
|
||||
label: Slack
|
||||
color: '#E01E5A'
|
||||
stackoverflow:
|
||||
label: Stack Overflow
|
||||
color: '#f48024'
|
||||
rss:
|
||||
label: RSS
|
||||
color: '#ff6f1a'
|
||||
tiktok:
|
||||
label: TikTok
|
||||
color: '#fe2c55'
|
||||
` | transform.Unmarshal) }}
|
@ -0,0 +1,45 @@
|
||||
{{/*
|
||||
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 }}
|
@ -0,0 +1,27 @@
|
||||
{{/*
|
||||
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 }}
|
@ -0,0 +1,21 @@
|
||||
{{/*
|
||||
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 }}
|
78
themes/ananke/layouts/partials/func/style/GetMainCSS.html
Normal file
78
themes/ananke/layouts/partials/func/style/GetMainCSS.html
Normal file
@ -0,0 +1,78 @@
|
||||
{{/*
|
||||
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 }}
|
19
themes/ananke/layouts/partials/func/style/GetResource.html
Normal file
19
themes/ananke/layouts/partials/func/style/GetResource.html
Normal file
@ -0,0 +1,19 @@
|
||||
{{/*
|
||||
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 }}
|
15
themes/ananke/layouts/partials/func/warn.html
Normal file
15
themes/ananke/layouts/partials/func/warn.html
Normal file
@ -0,0 +1,15 @@
|
||||
{{/*
|
||||
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 . }}
|
Reference in New Issue
Block a user