davidsneighbour / hugo-modules

A mono repo for all GoHugo modules by @davidsneighbour.
https://github.com/davidsneighbour/hugo-modules
MIT License
3 stars 1 forks source link

hugo-giscus: add custom theming #44

Open davidsneighbour opened 2 years ago

davidsneighbour commented 2 years ago

As described in Advanced Usage a custom theme can be added. Let's implement it here too.

The setup would be as follows:

config

[outputs]
home = ["GISCUS_THEME"]
[params.dnb.giscus]
theme = "dark"
[params.dnb.giscus.theme]
stylesheet = "scss/giscus/theme.scss"
colorPrettylightsSyntaxComment = "#768390"
colorPrettylightsSyntaxConstant = "#6cb6ff"
...

stylesheet is a path to a stylesheet (looks by default for assets/scss/giscus/theme.scss). This stylesheet will import the original theme selected under giscus (loading via getRemote), then subsequent properties under theme are added as overrides and exports the finished stylesheet.

The camelcased syntax of the theme variables are corresponding to the CSS variables in the sample theme.

The pain point here is how to map this without having to add all items to the template. I think there should be a way to transform camelcase to title-case in Hugo.

Currently I think it's a sequence like this:

If GISCUS_THEME is set in the outputs, then a custom stylesheet will be linked, so a custom theme without any settings in the theme config section still can add custom styles via theme.scss.

davidsneighbour commented 2 years ago

See https://discourse.gohugo.io/t/camel-case-to-dashed-case/37757/5

It's easier than that:

{{ $v := "someCamelCase" }}
{{ add "--" ($v | humanize | lower | replaceRE " " "-") }}
davidsneighbour commented 2 years ago

stylesheet is a path to a stylesheet (looks by default for assets/scss/giscus/theme.scss). This stylesheet will import the original theme selected under giscus (loading via getRemote), then subsequent properties under theme are added as overrides and exports the finished stylesheet.

Let's rephrase this: The file in stylesheet will be used in connection with a pipeline, that will do the following steps: