dc7a9ae12content: Update JS options07d3d8803npm: Use tilde ranges for versionse06362a13Minor grammar fixesc42db0838content: Algolia DocSearch clarificationd67412b82deps: Upgrade to TailwindCSS 4.1.0da1fb12d3theme: Update Lato font path for images.Text example140fa3bb9Update introduction.md7b1fcca27content: Fix links to embedded template source908a55532theme: Improve dark mode syntax highlighting backgroundd830e5962Update XxHash.md807be5dbfUpdate Defer.md4b56693f6content: Update GitHub Pages sample workflow57b766fbaUpdate TailwindCSS.md64982ab6aUpdate TailwindCSS.md1b6e879c6Update TailwindCSS.mde67cbcdd2content: Add caching to the GitHub Pages workflow exampleb7ca3b07cUpdate index.md14e1a3977Update XxHash.md980f344aeUpdate XxHash.md6b815f03etheme: Remove aria-label attribute from links1c00bbc45theme: Update npm dependencies533149bf9theme: Include section pages in related content2b6bda6bdcontent: Fix typos92ce95cbbcontent: Miscellaneous editsf12936681theme: Add a simple LRU cache for search339ca3388Fix the previous broken commit8537e59e0Make it into a non-linke13f17d29Add Algolia logo/link to the search listing dialogd3e09e886content: Fix typo7217f64b6content: Miscellaneous edits51aa1ae73content: Improve some examples8ebaa53f9theme: Adjust shortcodes898870438theme: Hide anchor until mouse-overc933ea237content: More front matter cleanupf26ca047acontent: Miscellaneous editse272b2039theme: Fix inline partial refsc540e6d29content: Replace note shortcode calls with blockquote alertsaef899bc5theme: Add title and QR code when printingbd46ef626theme: Implement blockquote render hookddefbefaacontent: Improve contributing pagef41d28ee1content: Adjust usage of whitespace removal with action delimiters03315336dtheme: Use full title in related content sidebar4f4076364misc: Document the front matter fields used on this site2f78d7632misc: Fix gitignore file7de6dbab3content: Fix front matter for several function pages5d3542ea6config: Disable tags taxonomy68bc28d67content: Add linkTitle to shortcode pages5f32c92edtheme: Restore deduplication logic for related itemsa943a4bb8theme: Implement related content toolingfd628be6econtent: Replace calls to the code shortcode with fenced code blocksb23c9a583content: Fix position of new-in badgesec056f251content: Fix typo245351c84theme: Adjust spacing in highlighting theme examples2fcd21ee5content: Remove "related" array from function and method pages71d8426eetheme: Create code block render hook4cdde6649theme: Adjust number of news items to display34ab45261content: Miscellaneous editsb6cae5cbccontent: Consolidate configuration documentation727ef6f66theme: Fix overflow issue for wide tablesc4f759e01Add es202493cce62c8Update support list of more recent targets with js.Build / esbuild974d0655fUpdate hosting-on-codeberg.mdb3f0ed9cecontent: Add hosting instructions for Codeberg Pages8217c0900content: Correct the SourceHut repository URLa8cf3d28fcontent: Add hosting instructions for SourceHut Pages8c059cbe1theme: Use content adapter for news section03938c600Remove some old new-in5c50a75e8content: Fix typo5cf89f2f6theme: Re-enable banner gtag outbound link tracking3c555d5f8One more copy button94bce999aAdd some copy buttons9e1cc0c2bUpdate PortableText.mddd26ac49fDocument transform.PortableText5f632ab32netlify: Hugo 0.145.059e057bb4Update index.mdd07e07d6cRemove some unused home page front matterd482657b7Add footnote about alias to the build front matter keyf0629b77ccontent: Fix typod91c4cccftheme: Fix news items URLsca931cd1ftheme: Restore RSS feed for news sectione6b870bc9theme: Adjust copy-to-clipboard button071851431Update netlify.tomle68431034theme: Format layoutsaa3cd839atheme: Format assets22ad3eee3theme: Add some more space on the right for copy buttonsf4a19083anetlify: Hugo 0.144.1974cb8795theme: Remove Internet Explorer configs (#2929)4a23a1f41content: Fix typosd49f15d03theme: Get the scrollspy back working720c7ff67config: Evict getresource cache hourly1f62ca97etheme: Hide the Turbo progress barf6449ace3Move the dark class up to the html element074cd1a07content: Miscellaneous editse098a7716content: Miscellaneous edits8e1e104aacontent: Updates for v0.144.018e1aa916theme: Add anchor links via JSac3b5505cClose new-inbfa4db6b8netlify: Hugo 0.144.0fd6e7feeeRegen CLI docsda9d1218aRegen docs helper5de494dedMerge branch 'tempv0.144.0'f683e6469theme: Minor improvements to base templateef8bf89d8resources/page: Revise the new contentbasename permalinks tokens901adb07bresources/page: Add :contentbasename and :contentbasenameorslug permalink tokens0fca8ef25all: Change shortcode usage and design to prevent invalid HTMLc41d76613Update RegularPagesRecursive.mde93574748content: Correct return type for strings.Split3d504abbaRevert "content: Add ids to the Netlify steps"c08c8e15econtent: Add ids to the Netlify steps5a3b470a2theme: "move" the id from content to articleb878613aatheme: Add page kind as a CSS class to body269657e8fcontent: Fix formatting error664f6c92fconfig: Change image cache locationfa6b719b1theme: Reduce ToC to level 2-4bc16341catheme: Render mathematical markup with transform.ToMath14bf9dc70theme: Add aria-label attribute to search fieldsed42af5b3theme: Adjust search field and search activationf042e4970dev: Add prettier-plugin-void-htmlf6ec83533content: Fix inline shortcode example0a74210e2theme: Remove readfile shortcode334ca06actheme: Fix some dark mode accessibility as reported by Axe core02626ff92theme: aria-lbabel => aria-label227b76ab7Add Prettier and config43ab22428content: Bump minimum required Go version to 1.23.003e54683fmodules: Add GOAUTH to module config9f06a3b9cjs/esbuild: Add drop optionddcd99369Merge commit 'a024bc7d76fcc5e49e8210f9b0896db9ef21861a'733731253helpers: Add Chroma styles to docs.yaml git-subtree-dir: docs git-subtree-split:dc7a9ae127
8.5 KiB
title, description, categories, keywords, params
| title | description | categories | keywords | params | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| css.Sass | Transpiles Sass to CSS. |
|
{{< new-in 0.128.0 />}}
{{ with resources.Get "sass/main.scss" }}
{{ $opts := dict
"enableSourceMap" (not hugo.IsProduction)
"outputStyle" (cond hugo.IsProduction "compressed" "expanded")
"targetPath" "css/main.css"
"transpiler" "libsass"
}}
{{ with . | toCSS $opts }}
{{ if hugo.IsProduction }}
{{ with . | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}
{{ else }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
{{ end }}
Transpile Sass to CSS using the LibSass transpiler included in Hugo's extended and extended/deploy editions, or install Dart Sass to use the latest features of the Sass language.
Sass has two forms of syntax: SCSS and indented. Hugo supports both.
Options
- transpiler
- (
string) The transpiler to use, eitherlibsass(default) ordartsass. Hugo's extended and extended/deploy editions include the LibSass transpiler. To use the Dart Sass transpiler, see the installation instructions below. - targetPath
- (
string) If not set, the transformed resource's target path will be the original path of the asset file with its extension replaced by.css. - vars
- (
map) A map of key-value pairs that will be available in thehugo:varsnamespace. Useful for initializing Sass variables from Hugo templates.
// LibSass
@import "hugo:vars";
// Dart Sass
@use "hugo:vars" as v;
- outputStyle
- (
string) Output styles available to LibSass includenested(default),expanded,compact, andcompressed. Output styles available to Dart Sass includeexpanded(default) andcompressed. - precision
- (
int) Precision of floating point math. Not applicable to Dart Sass. - enableSourceMap
- (
bool) Whether to generate a source map. Default isfalse. - sourceMapIncludeSources
- (
bool) Whether to embed sources in the generated source map. Not applicable to LibSass. Default isfalse. - includePaths
- (
slice) A slice of paths, relative to the project root, that the transpiler will use when resolving@useand@importstatements.
{{ $opts := dict
"transpiler" "dartsass"
"targetPath" "css/style.css"
"vars" site.Params.styles
"enableSourceMap" (not hugo.IsProduction)
"includePaths" (slice "node_modules/bootstrap/scss")
}}
{{ with resources.Get "sass/main.scss" | toCSS $opts | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}
- silenceDeprecations
- (
slice) {{< new-in 0.139.0 />}} A slice of deprecation IDs to silence. The deprecation IDs are printed to in the warning message, e.g "import" inWARN Dart Sass: DEPRECATED [import] .... This is for Dart Sass only.
Dart Sass
Hugo's extended and extended/deploy editions include LibSass to transpile Sass to CSS. In 2020, the Sass team deprecated LibSass in favor of Dart Sass.
Use the latest features of the Sass language by installing Dart Sass in your development and production environments.
Installation overview
Dart Sass is compatible with Hugo v0.114.0 and later.
If you have been using Embedded Dart Sass1 with Hugo v0.113.0 and earlier, uninstall Embedded Dart Sass, then install Dart Sass. If you have installed both, Hugo will use Dart Sass.
If you install Hugo as a Snap package there is no need to install Dart Sass. The Hugo Snap package includes Dart Sass.
Installing in a development environment
When you install Dart Sass somewhere in your PATH, Hugo will find it.
| OS | Package manager | Site | Installation |
|---|---|---|---|
| Linux | Homebrew | brew.sh | brew install sass/sass/sass |
| Linux | Snap | snapcraft.io | sudo snap install dart-sass |
| macOS | Homebrew | brew.sh | brew install sass/sass/sass |
| Windows | Chocolatey | chocolatey.org | choco install sass |
| Windows | Scoop | scoop.sh | scoop install sass |
You may also install prebuilt binaries for Linux, macOS, and Windows.
Run hugo env to list the active transpilers.
Installing in a production environment
For CI/CD deployments (e.g., GitHub Pages, GitLab Pages, Netlify, etc.) you must edit the workflow to install Dart Sass before Hugo builds the site2 . Some providers allow you to use one of the package managers above, or you can download and extract one of the prebuilt binaries.
GitHub Pages
To install Dart Sass for your builds on GitHub Pages, add this step to the GitHub Pages workflow file:
- name: Install Dart Sass
run: sudo snap install dart-sass
If you are using GitHub Pages for the first time with your repository, GitHub provides a starter workflow for Hugo that includes Dart Sass. This is the simplest way to get started.
GitLab Pages
To install Dart Sass for your builds on GitLab Pages, the .gitlab-ci.yml file should look something like this:
variables:
HUGO_VERSION: 0.144.2
DART_SASS_VERSION: 1.85.0
GIT_DEPTH: 0
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: recursive
TZ: America/Los_Angeles
image:
name: golang:1.20-buster
pages:
script:
# Install Dart Sass
- curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
- tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
- cp -r dart-sass/* /usr/local/bin
- rm -rf dart-sass*
# Install Hugo
- curl -LJO https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
- apt install -y ./hugo_extended_${HUGO_VERSION}_linux-amd64.deb
- rm hugo_extended_${HUGO_VERSION}_linux-amd64.deb
# Build
- hugo --gc --minify
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Netlify
To install Dart Sass for your builds on Netlify, the netlify.toml file should look something like this:
[build.environment]
HUGO_VERSION = "0.144.2"
DART_SASS_VERSION = "1.85.0"
NODE_VERSION = "22"
TZ = "America/Los_Angeles"
[build]
publish = "public"
command = """\
curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
rm dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
export PATH=/opt/build/repo/dart-sass:$PATH && \
hugo --gc --minify \
"""
Example
To transpile with Dart Sass, set transpiler to dartsass in the options map passed to css.Sass. For example:
{{ with resources.Get "sass/main.scss" }}
{{ $opts := dict
"enableSourceMap" (not hugo.IsProduction)
"outputStyle" (cond hugo.IsProduction "compressed" "expanded")
"targetPath" "css/main.css"
"transpiler" "dartsass"
}}
{{ with . | toCSS $opts }}
{{ if hugo.IsProduction }}
{{ with . | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}
{{ else }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
{{ end }}
Miscellaneous
If you build Hugo from source and run mage test -v, the test will fail if you install Dart Sass as a Snap package. This is due to the Snap package's strict confinement model.
-
In 2023, the Sass team deprecated Embedded Dart Sass in favor of Dart Sass. ↩︎
-
You do not have to do this if (a) you have not modified the assets cache location, and (b) you have not set
useResourceCacheWhentoneverin your site configuration, and (c) you add and commit yourresourcesdirectory to your repository. ↩︎