Logo

dev-resources.site

for different kinds of informations.

[HUGO]: How to use variables from .env

Published at
6/3/2023
Categories
hugo
env
security
Author
anastasiia_xfr
Categories
3 categories in total
hugo
open
env
open
security
open
Author
14 person written this
anastasiia_xfr
open
[HUGO]: How to use variables from .env

The initial task you need to accomplish on Hugo is how to add variables from .env to JavaScript when building the site using hugo server or hugo --gc --minify after deploying on Netlify.
And what I understand after researching for this:

  • touch .env file and add variables with names that start with HUGO_PARAMS_ as required read

  • Add to config.toml

[security]
  enableInlineShortcodes = false
  [security.funcs]
    getenv = ['^HUGO_']
Enter fullscreen mode Exit fullscreen mode
  • Add to Netlify Deploy Environment variables from .env

  • Add to \layouts_default\baseof.html something like this

<script>
const apiKey = "{{ getenv "HUGO_PARAMS_FIREBASE_API_KEY" }}";
//console.log('apiKey', apiKey);
</script>
Enter fullscreen mode Exit fullscreen mode
  • Deploy that That's all, it will be a success.

To run it locally, you will need to write all the variables in the following format:

env HUGO_TITLE="Some Title" hugo server
Enter fullscreen mode Exit fullscreen mode

(I couldn't find any other way, and it's terribly inconvenient)
read


Sources: 1 2 3 4

env Article's
30 articles in total
Favicon
How to Use Environment Variables in a React.js App with Vite
Favicon
next-runtime-env usage in Documenso source code
Favicon
How to Build an Elm Land Project for Production
Favicon
การใช้ GitLab สำหรับแชร์ Configuration ให้คนในทีม โดยไม่ใช้แชท
Favicon
How to create a fullstack application using Django and Python Part 5
Favicon
Exploring DotenvX
Favicon
Setting up a React environment
Favicon
Using environment variables in React and Vite
Favicon
Exploring Node.js 20.6: Built-in Support for .env Files
Favicon
docker-compose will always load .env
Favicon
How to fix 'process' is not defined (React+Vite)
Favicon
Virtual Environments in Python Applications
Favicon
Decoding the Matrix: The Evolution of Environment Variables in Software
Favicon
Use Doppler instead of traditional .env files 🍕
Favicon
Além do básico: Uso de Variáveis de Ambiente em Aplicações Node e Nest
Favicon
Running scripts in Production
Favicon
Better DX for .env
Favicon
Navigating Environment Variables in Flutter Projects: Strategies for Effective Integration
Favicon
TIL - Today I Learn 12-11 18-11
Favicon
Generate a Random JWT Secret Key
Favicon
Next JS might be exposing your backend environment variables
Favicon
Environment variables and configuration anti patterns in Node.js applications
Favicon
Node(20.6.0) now supports built-in .env files
Favicon
How to keep your tokens secret?
Favicon
Criando um comando Artisan personalizado para definir valores de variáveis no .env no Laravel
Favicon
How to Effectively Remove .env File from Git Repo/History
Favicon
Vite environment variable's type casting/transforming
Favicon
Did you know docker-compose only takes environment variables from`.env` only?
Favicon
[HUGO]: How to use variables from .env
Favicon
Python – AWS Secrets Manager: Remote env vars

Featured ones: