Here’s a custom Hugo shortcode that creates an image gallery in a masonry style using GLightbox. This approach will display images from a specified folder in a masonry layout, and each image will open in a lightbox when clicked.
When I built this website, I checked for a free static hosting solution that was easy to use and maintain. After a little research, I landed on Netlify. I found hosting a Hugo site on Netlify to be an effective solution for deploying static websites. Combining Hugo’s speed with Netlify’s robust features, such as continuous deployment, a user-friendly dashboard, and advanced build settings, made everything feel seamless.
Why Use Netlify?
Netlify is popular for its ease of use, free hosting tier, and powerful features like automated builds, custom domain support, and built-in SSL. With Hugo’s efficient static site generation, deploying on Netlify enables fast, seamless updates and management.
Step 1: Set up netlify.toml
configuration
The netlify.toml
file is essential for configuring build settings in Netlify. Here’s a setup tailored for various deployment environments, including production, deploy previews, and branch deploys.
Add the following netlify.toml
file to your Hugo project’s root directory:
[build]
publish = "public"
command = "hugo --gc --minify"
[context.production.environment]
HUGO_VERSION = "0.134.0"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "false"
[context.split1]
command = "hugo --gc --minify --enableGitInfo"
[context.split1.environment]
HUGO_VERSION = "0.134.0"
HUGO_ENV = "production"
[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
[context.deploy-preview.environment]
HUGO_VERSION = "0.134.0"
[context.branch-deploy]
command = "hugo -b $DEPLOY_PRIME_URL"
[context.branch-deploy.environment]
HUGO_VERSION = "0.134.0"
[context.next.environment]
HUGO_ENABLEGITINFO = "false"
Explanation of key parameters
- Build Command:
hugo --gc --minify
triggers garbage collection (--gc
) and minifies output. HUGO_VERSION
: Specifies the Hugo version to avoid compatibility issues.HUGO_ENABLEGITINFO
: Used for tracking commit metadata in production.- Deployment Contexts:
- Production: Builds optimized, production-ready files.
- Deploy Preview: Builds the site using the pull request URL, helpful for staging.
- Branch Deploy: Enables previews for branches other than the main one.
Step 2: Connect your repository to netlify
Log in to Netlify: Go to Netlify.
Create a new site: Choose “New site from Git” from the dashboard.
Select your repository: Choose GitHub, GitLab, or Bitbucket, authenticate, and select your Hugo site repository.
Configure build settings:
- Build command: Leave as
hugo
. - Publish directory: Set as
public
(Netlify automatically reads fromnetlify.toml
if it’s present).
- Build command: Leave as
Deploy your site: Click “Deploy site” to initiate the first build. Netlify will pull from your repository, build, and deploy the site, which you can access via the provided default Netlify URL (e.g.,
https://example-site.netlify.app
).
Step 3: Preview and customize your site
Once the build completes, visit the live preview URL to verify that your site is working correctly.
Step 4: Set Up a custom domain (Optional)
To configure a custom domain:
- Go to the Netlify dashboard, select “Domain settings,” and add your domain.
- Follow the provided DNS setup instructions. If you want Netlify to manage DNS, you can transfer the domain or add a Netlify DNS record.
- Netlify automatically provisions an SSL certificate through Let’s Encrypt, adding secure HTTPS to your site.
Step 5: Enable continuous deployment
Netlify supports continuous deployment by default. Each push to your repository triggers a new build and redeploys the latest changes. This is the feature I love the most, and it makes easy to manage updates or collaborate with others on site changes.
Conclusion
Deploying a Hugo site on Netlify offers a streamlined experience, leveraging Hugo’s fast builds with Netlify’s advanced hosting features. With a few simple steps, your site is live, secure, and ready for easy content updates directly from Git.
I hope this setup is ideal for efficient deployment with customized environments, making it easy to manage development and production versions and maintain a polished, dynamic website.
What are your thoughts on this post?
I’d love to hear from you! Click this link to email me—I reply to every message!
Also use the share button below if you liked this post. It makes me smile, when I see it.