Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dietpi-Software | Hugo: A static-site generator for building websites #6487

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,12 @@ Available commands:
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#wordpress'
aSOFTWARE_DEPS[$software_id]='88 89 webserver'
#------------------
software_id=141
aSOFTWARE_NAME[$software_id]='Hugo'
aSOFTWARE_DESC[$software_id]='A static-site generator for building websites'
aSOFTWARE_CATX[$software_id]=6
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#hugo'
#------------------
software_id=38
aSOFTWARE_NAME[$software_id]='FreshRSS'
aSOFTWARE_DESC[$software_id]='self-hosted RSS feed aggregator'
Expand Down Expand Up @@ -7079,6 +7085,104 @@ _EOF_
/boot/dietpi/func/create_mysql_db wordpress wordpress "$GLOBAL_PW"
fi

if To_Install 141 # Hugo
then
hdir=/mnt/dietpi_userdata/hugo
G_AGI hugo
G_EXEC mkdir -p "$hdir"
Create_User -d "$hdir" hugo

G_EXEC cd "$hdir"
if ! [[ -d "${hdir}/mysite" ]]; then
G_EXEC hugo new site mysite -f toml
fi
G_EXEC cd "${hdir}/mysite"
if ! [[ -d themes/PaperMod ]]; then
Download_Install "https://github.com/adityatelange/hugo-PaperMod/archive/master.tar.gz" "${hdir}/mysite"
G_EXEC mv "${hdir}/mysite/hugo-PaperMod-master" "${hdir}/mysite/themes/PaperMod"
fi

## Create a default config with a default theme
cat << '_EOF_' > config.toml
baseURL = 'http://my.website.com'
mtekman marked this conversation as resolved.
Show resolved Hide resolved
title = 'DietPi Test Blog'
languageCode = 'en-us'
theme = "PaperMod"

[markup.goldmark.renderer]
unsafe = true

_EOF_
## Create a systemd file
cat << '_EOF_' > /etc/systemd/system/hugo.service
[Unit]
Description=Hugo (DietPi)
Wants=network-online.target
After=network-online.target

[Service]
SyslogIdentifier=Hugo
User=hugo
LogsDirectory=hugo
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really log to /var/log/hugo, or can it be configured to log to STDOUT instead?

WorkingDirectory=/mnt/dietpi_userdata/hugo/mysite
ExecStart=/usr/bin/hugo server -p 8131 --buildDrafts --navigateToChanged

[Install]
WantedBy=multi-user.target

_EOF_

## Create first post
G_EXEC mkdir -p "${hdir}/mysite/content/posts/"
cat << '_EOF_' > "${hdir}/mysite/content/posts/first.md"
---
title: "First Post"
date: 2023-01-01
draft: false
---

# The website is up!

This is the first post, which was generated by running the command

```bash
cd /mnt/dietpi_userdata/hugo/mysite/
sudo -u hugo hugo new posts/name-of-post.md
## Note that the '.md' extension is important
```

You can then modify the file with a markdown editor, and it will
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People will know, but of course any text editor will so:

Suggested change
You can then modify the file with a markdown editor, and it will
You can then modify the file with a text or markdown editor, and it will

update in real time.

e.g. `sudo -u hugo nano /mnt/dietpi_userdata/hugo/mysite/content/posts/name-of-post.md`

Please also see the [Quick Start](https://gohugo.io/getting-started/quick-start/)
guide for more configuration tips!

This also allows you to **push** markdown snippets to your DietPi

e.g. `rsync random-note.md [email protected]:/mnt/dietpi_userdata/hugo/mysite/content/posts/`

## Extras

If you are an Emacs fan, you can use the
[ox-hugo](https://ox-hugo.scripter.co/doc/installation/) package to
export an org-mode sub-tree as a post, allowing you to blog on-the-fly
from your editor!

# Configuration

Hugo's themes can be changed by editing the `/mnt/dietpi_userdata/hugo/mysite/config.toml`
file. See the [Configuration Guide](https://gohugo.io/getting-started/configuration/) for
inspiration.

Hugo server options need to be changed from the command line. This means ports, baseURL, and
site directory need to be edited in the systemd file, located at: `/etc/systemd/system/hugo.service`

_EOF_
G_EXEC chown hugo: -R "$hdir"
fi

if To_Install 38 # FreshRSS
then
# Install required PHP modules: https://github.com/FreshRSS/FreshRSS#requirements
Expand Down Expand Up @@ -13115,6 +13219,12 @@ If no WireGuard (auto)start is included, but you require it, please do the follo
Remove_Database wordpress
fi

if To_Uninstall 141 # WordPress
then
Remove_Service hugo
G_AGP hugo
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
G_AGP hugo
G_AGP hugo
[[ -f '/mnt/dietpi_userdata/hugo' ]] && G_EXEC rm -R /mnt/dietpi_userdata/hugo

fi

if To_Uninstall 38 # FreshRSS
then
crontab -u www-data -l | grep -v '/opt/FreshRSS/app/actualize_script.php' | crontab -u www-data -
Expand Down