Pruning Your HBStack Project

How to remove unnecessary files and configurations from your HBStack project. Learn to clean up dependencies, optimize build size, and maintain project organization.

After setting up your HBStack project and ensuring it works correctly, the next step is to prune unnecessary files and configurations to keep your project clean, reduce its size, and make it easier to maintain.


Overview

Pruning involves removing language files you don’t need, example content, unused module configurations, and updating various configuration files to match your project requirements.

Removing Unnecessary Files

HBStack supports multiple languages through its i18n system. If you only need specific languages, you can remove the others:

1# Remove language files you don't need
2# For example, if you only need English, you can remove other language files:
3rm -rf i18n/fr.yaml i18n/es.yaml i18n/de.yaml i18n/zh-hans.yaml i18n/zh-hant.yaml
4
5# Similarly, remove language-specific content folders
6rm -rf content/fr content/es content/de content/zh-hans content/zh-hant

To identify all available language files:

1find . -name "*.yaml" -path "*/i18n/*" | sort

Example Content

Remove example content that you don’t need:

1# Remove example posts
2rm -rf content/posts/example-*
3
4# Remove example pages
5rm -rf content/pages/example-*
6
7# Remove example images
8rm -rf assets/images/examples/

Module-Specific Files

If you’re not using certain HBStack modules, you can remove their configurations:

1# For example, if you're not using the blog module:
2rm -rf config/_default/params.blog.yaml
3
4# If you're not using the docs module:
5rm -rf config/_default/params.docs.yaml

Theme Components

Review and remove theme components you don’t need:

1# Check the current theme configuration
2cat config/_default/module.yaml
3
4# Remove unnecessary theme components from the imports section
5# Edit the file manually to remove unwanted modules

Amending Configuration Files

Updating .gitignore

The default .gitignore file might include entries that aren’t relevant to your project or miss entries that you need. Here’s how to update it:

1# Open .gitignore in your editor
2nano .gitignore

Add these common entries if they’re not already present:

 1# Hugo
 2/public/
 3/resources/_gen/
 4/assets/jsconfig.json
 5hugo_stats.json
 6hugo.exe
 7hugo.darwin
 8hugo.linux
 9.hugo_build.lock
10
11# Node.js
12node_modules/
13npm-debug.log
14yarn-error.log
15yarn-debug.log
16
17# OS specific
18.DS_Store
19Thumbs.db
20
21# Editor specific
22.idea/
23.vscode/
24*.swp
25*.swo
26*~
27
28# Project specific
29/dist/
30/tmp/
31.env
32.env.local

Updating License and README

Update the license and README files to reflect your project:

1# Update the license file with your information
2nano LICENSE
3
4# Update the README with your project details
5nano README.md

Cleaning Up Docker Configuration

If you’re using Docker, review and update the Docker configuration files:

1# Review docker-compose.yml
2nano docker-compose.yml
3
4# Review Dockerfile
5nano Dockerfile

Automated Pruning

For more efficient pruning, you can create a script to automate the process:

 1#!/bin/bash
 2# prune.sh - Script to prune unnecessary files from HBStack project
 3
 4# Define languages to keep (e.g., only English)
 5KEEP_LANGS=("en")
 6
 7# Remove other language files
 8echo "Removing unnecessary language files..."
 9for file in i18n/*.yaml; do
10  lang=$(basename "$file" .yaml)
11  if [[ ! " ${KEEP_LANGS[@]} " =~ " ${lang} " ]]; then
12    echo "Removing $file"
13    rm -f "$file"
14  fi
15done
16
17# Remove language-specific content
18echo "Removing language-specific content..."
19for dir in content/*/; do
20  lang=$(basename "$dir")
21  if [[ ! " ${KEEP_LANGS[@]} " =~ " ${lang} " ]] && [[ "$lang" != "posts" ]] && [[ "$lang" != "pages" ]] && [[ "$lang" != "docs" ]]; then
22    echo "Removing $dir"
23    rm -rf "$dir"
24  fi
25done
26
27# Remove example content
28echo "Removing example content..."
29find content -name "example-*" -type d -exec rm -rf {} +
30find content -name "example-*.md" -type f -exec rm -f {} +
31
32echo "Pruning completed!"

Make the script executable and run it:

1chmod +x prune.sh
2./prune.sh

Verifying Your Changes

After pruning, make sure your project still works correctly:

1# Start the development server
2hugo server -D
3
4# Or if using Docker
5docker compose up server

Check that all pages load correctly and that there are no broken links or missing resources.

Committing Your Changes

Once you’re satisfied with the pruning, commit your changes:

1git add .
2git commit -m "Prune unnecessary files and configurations"
3git push origin main

Conclusion

By following these steps, you’ll have a cleaner, more focused HBStack project that contains only the files and configurations you need. After pruning your project, the next step is to configure it according to your needs, including setting the site name, author information, and other details specific to your project.


FAQ

No, you can keep example content that serves as a useful reference for your project. Just remove what you don’t need.

If done carefully, pruning shouldn’t break your site. Always test your site after pruning to ensure everything works correctly.

If you’ve committed your project to Git before pruning, you can restore any accidentally removed files using git checkout -- path/to/file.

Yes, if you’re not planning to use Docker for development or deployment, you can remove the Docker-related files to keep your project clean.

Review your site’s functionality and design requirements. Keep modules that provide features you need and remove those you don’t plan to use.