Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sites to use local Sass files #413

Merged
merged 6 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/theme-css/fresh.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
position: absolute;
left: 50%;
top: 50%;
background-image: url(../../images/loaders/rings.svg);
background-image: url(../images/loaders/rings.svg);
background-size: 80px 80px;
background-repeat: no-repeat;
background-position: 50%;
Expand Down
6 changes: 3 additions & 3 deletions doc/content/getstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ Example `config.yaml` files can be seen in [scientific-python.org](https://githu

### CSS

To customize styles, add CSS files to the `./assets/css/` directory.
It's recommended to put your customizations in a file named `custom.css`, but other `css` files added there will also be loaded.
To customize styles, add CSS (`.css`) and Sass (`.scss`) files to the `./assets/css/` directory.
It's recommended to put your customizations in a file named `custom.css`, but other `.css` and `.scss` files added there will also be loaded.

CSS files are compiled as Hugo templates, i.e. configuration variables from the `config.yaml` file can be accessed as `{{ .Site.Params.VARIABLE }}`.
CSS and SCSS files are compiled as Hugo templates, i.e. configuration variables from the `config.yaml` file can be accessed as `{{ .Site.Params.VARIABLE }}`.

### JavaScript

Expand Down
14 changes: 7 additions & 7 deletions layouts/partials/css.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{{- $serverOpts := cond ($inServerMode) (dict "enableSourceMap" true) (dict "outputStyle" "compressed") -}}
{{- $sassCompiler := dict "transpiler" "dartsass" -}}
{{- $cssOpts := collections.Merge $sassCompiler $serverOpts -}}
{{- $sass := (slice "theme-css/pst/pydata-sphinx-theme.scss") -}}

<!-- Fonts -->
{{- $fontName := .Site.Params.font.name | default "Open Sans" -}}
Expand All @@ -23,13 +22,16 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Sans+Symbols+2">

<!-- SASS -->
{{- $sass := (slice "theme-css/pst/pydata-sphinx-theme.scss") | append (resources.Match "css/*.scss") -}}
{{- range $sass -}}

{{- $targetFile := printf "%s.scss" . -}}

{{- if $inServerMode -}}
{{ $css := resources.Get . | toCSS $cssOpts -}}
{{ $css := resources.Get . | resources.ExecuteAsTemplate $targetFile $page | toCSS $cssOpts -}}
<link rel="stylesheet" type="text/css" href="{{ $css.RelPermalink }}">
{{ else }}
{{ $css := resources.Get . | toCSS $cssOpts | minify | fingerprint -}}
{{ $css := resources.Get . | resources.ExecuteAsTemplate $targetFile $page | toCSS $cssOpts | minify | fingerprint -}}
<link rel="stylesheet" type="text/css" href="{{ $css.RelPermalink }}" integrity="{{ $css.Data.Integrity }}">
{{- end -}}

Expand All @@ -41,13 +43,11 @@

{{- range $cssFiles -}}

{{- $targetFile := printf "css/%s" . -}}

{{ if $inServerMode -}}
{{ $custom_style := . | resources.ExecuteAsTemplate $targetFile $page -}}
{{ $custom_style := . | resources.ExecuteAsTemplate . $page -}}
<link rel="stylesheet" href="{{ $custom_style.RelPermalink }}">
{{ else }}
{{ $custom_style := . | resources.ExecuteAsTemplate $targetFile $page | minify | fingerprint -}}
{{ $custom_style := . | resources.ExecuteAsTemplate . $page | minify | fingerprint -}}
<link rel="stylesheet" href="{{ $custom_style.RelPermalink }}" integrity="{{ $custom_style.Data.Integrity }}">
{{- end -}}

Expand Down