### Hugo Build Settings (Docs) Source: https://github.com/hugo-fixit/fixit/wiki/Vercel-Settings Configuration details for building the FixIt project documentation using Hugo. Includes framework preset, build commands, output directory, and installation commands, with Go installation. ```text Framework Preset: Hugo # hugo -v --gc --minify $BUILD_DRAFTS Build Command: npm run build -- $BUILD_DRAFTS Output Directory: public Install Command: npm install && amazon-linux-extras install golang1.19 ``` -------------------------------- ### Run Docs Server Source: https://github.com/hugo-fixit/fixit/blob/main/CONTRIBUTING.md Starts the documentation server, typically used when making docs-related theme changes. Requires FixIt and fixit-docs cloned as sibling directories. ```bash pnpm server:docs ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/hugo-fixit/fixit/blob/main/CONTRIBUTING.md Installs the necessary development dependencies for the project using pnpm. This command ensures all required packages are available for development. ```bash pnpm install ``` -------------------------------- ### Hugo Build Settings (Demo) Source: https://github.com/hugo-fixit/fixit/wiki/Vercel-Settings Configuration details for building the FixIt project demo using Hugo. Includes framework preset, build commands, output directory, and installation commands. ```text Framework Preset: Hugo # hugo -v --source=demo --gc --minify $BUILD_DRAFTS Build Command: npm run build -- $BUILD_DRAFTS Output Directory: demo/public Install Command: npm install ``` -------------------------------- ### Run Local Debugging Server (Production) Source: https://github.com/hugo-fixit/fixit/blob/main/CONTRIBUTING.md Starts a local debugging server with watch mode enabled, configured for a production environment. Useful for testing production builds locally. ```bash pnpm server:production ``` -------------------------------- ### Run Local Debugging Server Source: https://github.com/hugo-fixit/fixit/blob/main/CONTRIBUTING.md Starts a local debugging server with watch mode enabled. This command is useful for development and testing changes in real-time. ```bash pnpm server ``` -------------------------------- ### Theme Version Compatibility and Warnings Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/init/detection-version.html This section handles the theme's version compatibility checks. It ensures the installed theme version meets minimum requirements and issues warnings for development versions or when a newer version is available. ```gohtml {{/\* FixIt theme version detection \*/}} {{- if eq .Site .Sites.Default -}} {{- if not .Site.Params.version -}} {{- errorf "FixIt %v\n%v\n\n" $version (T "init.configurationError") -}} {{- else if gt "0.2.0" (strings.TrimPrefix "v" .Site.Params.version) -}} {{- errorf "FixIt %v\n%v\n\n" $version (dict "From" .Site.Params.version "To" $version | T "init.compatibilityError") -}} {{- end -}} {{- if gt (len (findRE "^v\[0-9\]+\\.[0-9\]+\\.[0-9\]+-\[0-9a-f\]$" $version)) 0 -}} {{- warnidf "warning-dev-version" "FixIt %v\n%v" $version (T "init.devVersionWarn") -}} {{- end -}} {{- if (gt $latest $version) | and $devOpts.c4u -}} {{- warnf "FixIt %v (⬆️ %v)\n%v\`git submodule update --remote --merge\`\n\n" $version $latest (T "init.quicklyUpgrade") -}} {{- end -}} {{- end -}} {{- hugo.Store.Set "latest" $latest -}} ``` -------------------------------- ### Deprecated Build Commands (v0.2.15) Source: https://github.com/hugo-fixit/fixit/wiki/Vercel-Settings Deprecated build commands for the FixIt project, including installation and build steps for different scenarios. These commands are marked as deprecated. ```bash # invalid in pull request # install rm -rf FixIt && git clone -b $VERCEL_GIT_COMMIT_REF https://github.com/Lruihao/FixIt.git FixIt && npm install # or rm -rf FixIt && git clone https://github.com/Lruihao/FixIt.git FixIt && cd FixIt && git checkout $VERCEL_GIT_COMMIT_SHA && npm install # build # `BUILD_DRAFTS`: `--buildDrafts` (Preview, Development) cd FixIt && npm run babel && hugo -v --source=exampleSite --themesDir ../.. $BUILD_DRAFTS --gc --minify # output FixIt/exampleSite/public ``` ```bash # install # last modify date error of posts # build hugo -v --source=exampleSite --themesDir ../.. --theme $PWD --gc --minify # output exampleSite/public ``` -------------------------------- ### Configure GitHub Token Header from Environment Variable Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/init/global.html This snippet configures an HTTP header for GitHub API requests. It checks for the presence of the `HUGO_PARAMS_GHTOKEN` environment variable. If found, it creates an 'Authorization' header with a 'token' prefix; otherwise, it initializes an empty header. ```hugo {{- /* Select the scope named `public_repo` to generate personal access token */ -}} {{- $header := dict "Authorization" "" -}} {{- with (getenv "HUGO_PARAMS_GHTOKEN") -}} {{- $header = dict "Authorization" (printf "token %v" .) -}} {{- end -}} {{- hugo.Store.Set "githubTokenHeader" $header -}} ``` -------------------------------- ### Hugo Mermaid Diagram Setup Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_shortcodes/mermaid.html This snippet initializes options, calls a partial to render a Mermaid diagram, and sets a page store variable to indicate Mermaid's presence. It's commonly used in Hugo themes to enable diagram functionality. ```go-template {{- $options := dict -}} {{- dict "Options" $options "Inner" .Inner | partial "plugin/mermaid.html" -}} {{- .Page.Store.Set "hasMermaid" true -}} ``` -------------------------------- ### Hugo Front Matter Example Source: https://github.com/hugo-fixit/fixit/blob/main/archetypes/post-bundle/index.md This snippet demonstrates a typical front matter configuration for a Hugo page using the Fixit theme. It includes settings for title, date, slug, draft status, author information, description, keywords, tags, categories, and resource management. ```yaml --- title: {{ replace .TranslationBaseName "-" " " | title }} subtitle: date: {{ .Date }} slug: {{ substr .File.UniqueID 0 7 }} draft: true author: name: link: email: avatar: description: keywords: license: comment: false weight: 0 tags: - draft categories: - draft hiddenFromHomePage: false hiddenFromSearch: false hiddenFromRelated: false hiddenFromFeed: false summary: resources: - name: featured-image src: featured-image.jpg - name: featured-image-preview src: featured-image-preview.jpg toc: true math: false lightgallery: false password: message: repost: enable: true url: # See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter --- ``` -------------------------------- ### Hugo Page Title and Asset Setup Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/head/link.html This snippet demonstrates Hugo template logic for dynamically setting the page title based on site configuration and home page status. It also includes logic for including various CSS assets, such as the main stylesheet, Font Awesome, and Animate.css, with options for CDN or local paths and fingerprinting for cache busting. ```go-template {{- $cdn := .Site.Store.Get "cdn" | default dict -}} {{- $fingerprint := .Site.Store.Get "fingerprint" -}} {{- $title := printf "%s %s %s" .Title .Site.Params.titleDelimiter .Site.Title -}} {{- if .IsHome -}} {{- $title = site.Title -}} {{- end -}} {{- if not .Site.Params.app.noFavicon -}} {{- with .Site.Params.app.svgFavicon -}} {{- else -}} {{- end -}} {{- with .Site.Params.app.iconColor -}} {{- end -}} {{- if eq .Site.Params.enablePWA true -}} {{- end -}} {{- end -}} {{- with .Prev -}} {{- end -}} {{- with .Next -}} {{- end -}} {{- range .AlternativeOutputFormats -}} {{- printf `` .Rel .MediaType.Type .Permalink $title | safeHTML -}} {{- end -}} {{- /\* Compatible with https://github.com/hugo-fixit/hugo-json-feed \*/ -}} {{- with .OutputFormats.Get "jsonfeed" -}} {{- end -}} {{- /\* style.min.css \*/ -}} {{- $options := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}} {{- $toCSS := dict "targetPath" "css/style.min.css" "enableSourceMap" true -}} {{- $options = dict "Context" . "ToCSS" $toCSS | merge $options -}} {{- partial "plugin/style.html" $options -}} {{- /\* Font Awesome \*/ -}} {{- $source := $cdn.fontawesomeFreeCSS | default "lib/fontawesome-free/all.min.css" -}} {{- $options := dict "Source" $source "Fingerprint" $fingerprint "Preload" true -}} {{- partial "plugin/style.html" $options -}} {{- /\* Animate.css \*/ -}} {{- $source := $cdn.animateCSS | default "lib/animate/animate.min.css" -}} {{- $options := dict "Source" $source "Fingerprint" $fingerprint "Preload" true -}} {{- partial "plugin/style.html" $options -}} ``` -------------------------------- ### Hugo Project Initialization and Configuration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/init/index.html This snippet demonstrates the core initialization logic for a Hugo project. It sets project versioning, initializes data structures, and includes various partial templates responsible for environment detection, global settings, and plugin compatibility. These partials are crucial for configuring the project's behavior and ensuring proper functionality. ```go-template {{- hugo.Store.Set "version" "v0.4.0-alpha-20250721024521-a1cd700b" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} {{- partial "init/detection-version.html" . -}} {{- partial "init/detection-deprecated.html" . -}} {{- partial "init/global.html" . -}} {{- partial "init/patch.html" . -}} {{- partial "plugin/compatibility.html" . -}} ``` -------------------------------- ### Chore: Build Process/Auxiliary Tool Commit Message Source: https://github.com/hugo-fixit/fixit/blob/main/CONTRIBUTING.md For changes in the build process, auxiliary tools, or dependency updates. Example: 'Chore: update plugin version'. ```APIDOC Chore: update plugin version ``` -------------------------------- ### Site Creation Time Configuration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Configures the site creation time, likely for display purposes. The value is retrieved from the site's store. ```go-template {{ $siteTime := .Site.Store.Get "siteTime" }} {{ if $siteTime.enable -}} {{ with $siteTime.value -}} {{ $config = dict "siteTime" . | merge $config }} {{ end }} {{ end }} ``` -------------------------------- ### Include MathJax Library Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Loads MathJax for mathematical rendering, with options for CDN or local paths, configuration parameters, and production minification. Includes a helper script for loading MathJax. ```gohtml {{/* MathJax */}} {{- if eq $math.type "mathjax" -}} {{/* TODO improve MathJax setup. e.g. content encryption, Twikoo math etc. */}} {{- $mathjax := $math.mathjax -}} {{- $source := "js/lib/load-mathjax.js" -}} {{- $options := dict "targetPath" "js/lib/load-mathjax.min.js" "minify" hugo.IsProduction -}} {{- $mathjaxOpts := $mathjax.options | default dict -}} {{- $mathjaxOpts = dict "enableMenu" $mathjaxOpts.enablemenu | merge $mathjaxOpts -}} {{- $params := dict "cdn" $mathjax.cdn "tex" ($mathjax.tex | default dict) "packages" ($mathjax.packages | default dict) "macros" ($mathjax.macros | default dict) "loader" ($mathjax.loader | default dict) "options" $mathjaxOpts -}} {{- $options = dict "params" $params | merge $options -}} {{- if not hugo.IsProduction -}} {{- $options = dict "sourceMap" "external" | merge $options -}} {{- end -}} {{- dict "Source" $source "Build" $options "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} {{- end -}} {{- end -}} ``` -------------------------------- ### Include KaTeX CSS and Copy-tex Extension Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Loads KaTeX CSS for mathematical rendering and the copy-tex extension for copying LaTeX source. It includes options for preloading and deferring script execution. ```gohtml {{/* Mathematical formulas */}} {{- $math := .Store.Get "math" -}} {{- if $math.enable -}} {{/* KaTeX */}} {{- if (eq $math.type "katex") | and (.Store.Get "hasKaTeX") -}} {{- $source := $cdn.katexCSS | default "lib/katex/katex.min.css" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Preload" true | dict "Page" . "Data" | partial "store/style.html" -}} {{/* Copy-tex extension */}} {{- if $math.katex.copyTex -}} {{- $source := $cdn.katexCopyTexJS | default "lib/katex/copy-tex.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} {{- end -}} {{- end -}} ``` -------------------------------- ### Clone FixIt Repository Source: https://github.com/hugo-fixit/fixit/blob/main/CONTRIBUTING.md Clones the FixIt repository from GitHub and navigates into the project directory. This is the first step to setting up your local development environment. ```bash git clone https://github.com/hugo-fixit/FixIt.git && cd FixIt ``` -------------------------------- ### Create New Project with CLI Source: https://github.com/hugo-fixit/fixit/blob/main/README.md Uses the fixit-cli tool to create a new Hugo project with the FixIt theme. This command initializes a new blog structure. ```bash pnpx fixit-cli create my-blog ``` -------------------------------- ### Include Sharer.js Library Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Loads the Sharer.js library asynchronously and deferred for social sharing functionality. It uses a CDN path or a local fallback. ```gohtml {{/* Sharer.js */}} {{- if $params.share.enable -}} {{- $source := $cdn.sharerJS | default "lib/sharer/sharer.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} {{- end -}} ``` -------------------------------- ### Set Main Section Pages in Hugo Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/init/global.html This section identifies and collects pages belonging to the main sections of the Hugo site. It uses the `where` function to filter `RegularPages` based on their `Section` and `Type` properties, combining them into a single list stored in the site's store. ```hugo {{- /* Set pages of main sections */ -}} {{- $pages := where .Site.RegularPages "Section" "in" .Site.MainSections -}} {{- $pages = $pages | union (where .Site.RegularPages "Type" "in" .Site.MainSections) -}} {{- .Site.Store.Set "mainSectionPages" $pages -}} ``` -------------------------------- ### Hugo Site Time Configuration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/footer.html This snippet shows how to enable and configure the display of site running time in the footer. It uses Hugo's `Site.Store` to get the site time information and conditionally renders an icon and text indicating the site is running. ```gohtml {{- $siteTime := .Site.Store.Get "siteTime" -}} {{- if $siteTime.enable -}} {{- if $siteTime.enable | and $siteTime.value -}} {{- with $siteTime -}} {{- $siteTimeIcon := printf (cond .Animate "%v fa-fw animate-icon" "%v fa-fw") .Icon -}} {{- dict "Class" $siteTimeIcon | partial "plugin/icon.html" -}} {{- with .Pre -}}{{ . }}{{- end -}} {{- printf `%v` (T "footer.siteRunning") | safeHTML -}} {{- end -}} {{- end -}} {{- end -}} ``` -------------------------------- ### Include TypeIt.js Library Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Loads the TypeIt.js library for animated typing effects, with configurable options for speed, cursor, and duration. It supports local or CDN sources. ```gohtml {{/* TypeIt */}} {{- if .Store.Get "hasTyped" -}} {{- $typeit := .Site.Params.typeit -}} {{- $source := $cdn.typeitJS | default "lib/typeit/index.umd.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} {{- $config = dict "speed" $typeit.speed "cursorSpeed" $typeit.cursorSpeed "cursorChar" $typeit.cursorChar "duration" $typeit.duration "loop" $typeit.loop | dict "typeit" | merge $config -}} {{- end -}} ``` -------------------------------- ### Configure Site Home Permalink in Hugo Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/init/global.html This snippet sets the site's home relative permalink. It trims common suffixes like 'archives/' and 'offline/' from the home page's permalink and stores the cleaned version in the site's store for later use. ```hugo {{- /* Set site home relative permalink */ -}} {{- $homeRelPermalink := .Site.Home.RelPermalink -}} {{- $homeRelPermalink = strings.TrimSuffix "archives/" $homeRelPermalink -}} {{- $homeRelPermalink = strings.TrimSuffix "offline/" $homeRelPermalink -}} {{- .Site.Store.Set "homeRelPermalink" $homeRelPermalink -}} ``` -------------------------------- ### Auto Bookmark Configuration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Handles configuration for an 'Auto Bookmark' feature, likely related to page navigation or content highlighting. The configuration is applied if the `autoBookmark` parameter is present for a page. ```go-template {{ if eq .Kind "page" -}} {{ with $params.autoBookmark -}} {{ $conf ``` -------------------------------- ### Decode and Extract URL Path in Hugo Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/function/path.html This Hugo template snippet decodes a URL and extracts its path component. It first calls a partial named 'escapeurl.html' to get a URL string, then pipes it through 'urlize' for encoding and 'urls.Parse' to create a URL object. Finally, it returns the 'Path' attribute of the parsed URL. ```hugo-template {{- /* https://discourse.gohugo.io/t/how-decode-urls-in-hugo/7549/4 */ -}} {{- $URL := partial "function/escapeurl.html" . -}} {{- $URL = $URL | urlize | urls.Parse -}} {{- return $URL.Path -}} ``` -------------------------------- ### MetingJS Integration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Includes the MetingJS JavaScript library, often used with APlayer for fetching music metadata from services like NetEase Cloud Music. It defaults to a local path but can be overridden. ```go-template {{ $source := $cdn.metingJS | default "lib/meting/Meting.min.js" }} {{ dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" }} ``` -------------------------------- ### Douyin Get Iframe Player API Reference Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_shortcodes/douyin.html This section details the API endpoint for retrieving an iframe player for a Douyin video. It includes the method signature, parameters, and expected return values, referencing the official Douyin developer documentation for comprehensive details. This is an API documentation entry. ```APIDOC OpenDouyin API: Get Iframe Player by Video Reference: https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/video-management/douyin/iframe-player/get-iframe-by-video This API allows developers to obtain an iframe embed code for a specific Douyin video. Method: GET Endpoint: /video/iframe/get Parameters: - video_id (string, required): The unique identifier of the Douyin video. - app_id (string, required): Your application's unique identifier. - access_token (string, required): The access token obtained through OAuth 2.0. Returns: - data (object): - iframe_url (string): The URL for the video's iframe player. - width (integer): Recommended width for the iframe. - height (integer): Recommended height for the iframe. - extra (object): - log_id (string): Unique identifier for the request log. Example Usage: GET /video/iframe/get?video_id=YOUR_VIDEO_ID&app_id=YOUR_APP_ID&access_token=YOUR_ACCESS_TOKEN ``` -------------------------------- ### APlayerJS Integration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Includes the APlayer JavaScript library for audio playback. It defaults to a CDN source but can be overridden. ```go-template {{ $source := $cdn.aplayerJS | default "lib/aplayer/APlayer.min.js" }} {{ dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" }} ``` -------------------------------- ### Get Author Map Partial Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/function/get-author-map.html Processes author data from front matter or site parameters, merging default values and optionally generating an avatar URL using Gravatar. It handles author information provided as a string name or a map, ensuring a consistent output structure. ```Go Template {{- /* Get author in map format. @param {String|Map} . the author name or map @returns {Map} @example {{- $author := partial "function/get-author-map.html" .Params.author -}} */ -}} {{- if not (reflect.IsMap site.Params.author) -}} {{- errorf "FixIt params error: site.Params.author must be a map, got %T." site.Params.author -}} {{- end -}} {{- $default := dict "name" "" "link" "" "email" "" "avatar" "" -}} {{- $author := site.Params.author | merge $default -}} {{- $authorParam := dict -}} {{- if reflect.IsMap . -}} {{- $authorParam = . -}} {{- else -}} {{- with . -}} {{- $authorParam = dict "name" . -}} {{- end -}} {{- end -}} {{- if isset $authorParam "name" | and (ne $authorParam.name site.Params.author.name) -}} {{- $author = $authorParam | merge $default | merge $author -}} {{- else -}} {{- with $authorParam.link -}}{{ $author = dict "link" . | merge $author }}{{- end -}} {{- with $authorParam.email -}}{{ $author = dict "email" . | merge $author }}{{- end -}} {{- with $authorParam.avatar -}}{{ $author = dict "avatar" . | merge $author }}{{- end -}} {{- end -}} {{- $gravatar := site.Params.gravatar -}} {{- if $gravatar.enable | and $author.email -}} {{- with $gravatar -}} {{- /* TODO migrate to gravatar */ -}} {{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v" (path.Clean .Host | default "www.gravatar.com") (md5 $author.email) (.Style | default "")) | merge $author -}} {{- end -}} {{- end -}} {{- return $author -}} ``` -------------------------------- ### Hugo Image Rendering Options Configuration Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_shortcodes/image.html This snippet demonstrates how to construct a configuration map for Hugo's image rendering partial. It dynamically sets parameters like image source, alt text, captions, responsive breakpoints, optimization settings (resize, format, quality), and lazy loading. ```go-template {{- $options := cond .IsNamedParams (.Get "src") (.Get 0) | dict "Src" -}} {{- $options = cond .IsNamedParams (.Get "alt") (.Get 1) | .Page.RenderString | dict "Alt" | merge $options -}} {{- $caption := cond .IsNamedParams (.Get "caption") (.Get 2) | .Page.RenderString -}} {{- $options = dict "Caption" $caption | merge $options -}} {{- $options = dict "Resources" .Page.Resources | merge $options -}} {{- $optim := slice (dict "Process" "resize 800x webp q75" "descriptor" "800w") (dict "Process" "resize 1200x webp q75" "descriptor" "1200w") (dict "Process" "resize 1600x webp q75" "descriptor" "1600w") -}} {{- $options = dict "OptimConfig" $optim | merge $options -}} {{- if .IsNamedParams -}} {{- $options = dict "Title" (.Get "title") | merge $options -}} {{- $options = dict "Height" (.Get "height") | merge $options -}} {{- $options = dict "Width" (.Get "width") | merge $options -}} {{- $options = .Get "linked" | ne false | dict "Linked" | merge $options -}} {{- $options = dict "Rel" (.Get "rel") | merge $options -}} {{- $options = dict "Loading" (.Get "loading" | default "lazy") | merge $options -}} {{- with (.Get "optimise") -}}{{- $options = dict "Optimise" . | merge $options -}}{{- end -}} {{- with (.Get "cacheRemote") -}}{{- $options = dict "CacheRemote" . | merge $options -}}{{- end -}} {{- else -}} {{- $options = cond $caption true false | dict "Linked" | merge $options -}} {{- end -}} {{- $options = dict "Responsive" true | merge $options -}} {{- with $caption -}} {{- partial "plugin/image.html" $options -}} {{- else -}} {{- partial "plugin/image.html" $options -}} {{- end -}} ``` -------------------------------- ### Include Mapbox GL Library Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Loads Mapbox GL JS for interactive maps, including its CSS, JavaScript, and language plugin. It also configures the access token and RTL text plugin. ```gohtml {{/* Mapbox GL */}} {{- if .HasShortcode "mapbox" -}} {{- $source := $cdn.mapboxGLCSS | default "lib/mapbox-gl/mapbox-gl.css" -}} {{- dict "Source" $source "Minify" true "Fingerprint" $fingerprint "Preload" true | dict "Page" . "Data" | partial "store/style.html" -}} {{- $source = $cdn.mapboxGLJS | default "lib/mapbox-gl/mapbox-gl.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} {{- dict "Source" "lib/mapbox-gl/mapbox-gl-language.js" "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} {{- $config = dict "accessToken" $params.mapbox.accessToken "RTLTextPlugin" "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js" | dict "mapbox" | merge $config -}} {{- end -}} ``` -------------------------------- ### Hugo Go Template Regex Replacement Example Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/function/escape.html This snippet demonstrates how to use the `replaceRE` function in Hugo's Go templates. It defines a regular expression to find characters within optional curly braces and replaces the matched pattern with the captured character, effectively stripping the braces if present. ```go-template {{- /* Escape character */ -}} {{- /* {?X} -> X */ -}} {{- $REin := `\{\?(.)\}` -}} {{- $REout := `$1` -}} {{- return replaceRE $REin $REout . -}} ``` -------------------------------- ### Hugo Reward Section Template Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/plugin/reward.html This Go template snippet demonstrates how to conditionally display donation options based on site configuration. It iterates through defined payment methods, displays an icon, a translated title, and an associated image if provided. Dependencies include the 'plugin/icon.html' and 'plugin/image.html' partials, and translation keys starting with 'single.reward.'. ```go-template {{- $reward := .Reward -}} {{- $id := .Id -}} {{- $author := .Author | default "" -}} {{- if $reward.enable -}} {{ $reward.comment }} {{- dict "Class" "fa-solid fa-qrcode fa-fw" | partial "plugin/icon.html" -}} {{- T "single.reward.donate" -}} {{- range $way, $image := $reward.ways -}} {{- with T (printf "single.reward.%v" $way) -}}{{ $way = . }}{{- end -}} {{- if $image -}} {{- dict "Src" $image "Alt" (strings.TrimPrefix " " (printf "%v %v" $author $way)) | partial "plugin/image.html" -}} {{ $way }} {{- end -}} {{- end -}} {{- end -}} ``` -------------------------------- ### HTML Details Element Rendering with Hugo Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_shortcodes/details.html This snippet demonstrates how to use the Hugo `details` shortcode to render HTML `
` elements. It supports parameters for class, name, summary content, title, and an initial open state. The shortcode also includes examples of how to apply CSS classes for styling the details, summary, and content sections. ```hugo {{/* Renders an HTML details element. @param {string} [class] The value of the element's class attribute. @param {string} [name] The value of the element's name attribute. @param {string} [summary] The content of the child summary element. @param {string} [title] The value of the element's title attribute. @param {bool} [open=false] Whether to initially display the content of the details element. @reference https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details @examples {{< details >}} A basic collapsible section. {{< /details >}} {{< details summary="Custom Summary Text" >}} Showing custom `summary` text. {{< /details >}} {{< details summary="Open Details" open=true >}} Contents displayed initially by using `open`. {{< /details >}} {{< details summary="Styled Content" class="my-custom-class" >}} Content can be styled with CSS by specifying a `class`. Target details element: ```css details.my-custom-class { } ``` Target summary element: ```css details.my-custom-class > summary > * { } ``` Target inner content: ```css details.my-custom-class > :not(summary) { } ``` {{< /details >}} {{< details summary="Grouped Details" name="my-details" >}} Specifying a `name` allows elements to be connected, with only one able to be open at a time. {{< /details >}} */}} {{/* Get arguments. */}} {{ $summary := .Get "summary" | default (.Get 0) | default "Details" }} {{ $open := .Get "open" | default (.Get 1) | default false }} {{ $class := .Get "class" | default (.Get 2) | default "" }} {{ $name := or (.Get "name") "" }} {{ $title := or (.Get "title") "" }} {{/* Render. */}} {{ $summary | .Page.RenderString }} {{ .Inner | .Page.RenderString (dict "display" "block") }} {{/* EOF */}} ``` ```css /* Target details element: */ details.my-custom-class { } /* Target summary element: */ details.my-custom-class > summary > * { } /* Target inner content: */ details.my-custom-class > :not(summary) { } ``` -------------------------------- ### Hugo Template: Get Parameters (Named vs Positional) Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_shortcodes/spotify.html This snippet demonstrates how to retrieve template parameters, supporting both named parameters (e.g., `type="value"`) and positional parameters (e.g., `value1 value2`). It uses Hugo's conditional functions to check for named parameters first, falling back to positional arguments if named parameters are not present. This pattern is common for creating flexible shortcodes. ```go-template {{- $type := cond .IsNamedParams (.Get "type") (.Get 0) -}} {{- $id := cond .IsNamedParams (.Get "id") (.Get 1) -}} {{- $width := cond .IsNamedParams (.Get "width") (.Get 2) -}} {{- $height := cond .IsNamedParams (.Get "height") (.Get 3) -}} {{- /* EOF */ -}} ``` -------------------------------- ### Theme JavaScript Loading Source: https://github.com/hugo-fixit/fixit/blob/main/layouts/_partials/assets.html Loads the main theme JavaScript file ('js/theme.js'). It configures minification and source maps based on the production environment, and includes fingerprinting for cache busting. ```html {{ $options := dict "targetPath" "js/theme.min.js" "minify" hugo.IsProduction }} {{ if not hugo.IsProduction }} {{ $options = dict "sourceMap" "external" | merge $options }} {{ end }} {{ dict "Source" (resources.Get "js/theme.js") "Build" $options "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" }} ```