About a year has passed since I moved to a Hugo + Netlify environment, and because nothing in particular had gone wrong I had left it alone, but I finally got around to setting up netlify.toml.
The theme used on this site: Beautifulhugo (submodule)
netlify.toml The official page has the format for netlify.toml, so create it under hugo with the following content
Copy [build] publish = "public" command = "hugo --gc --minify" [context.production.environment] HUGO_VERSION = "0.74.3" HUGO_ENV = "production" HUGO_ENABLEGITINFO = "true" [context.split1] command = "hugo --gc --minify --enableGitInfo" [context.split1.environment] HUGO_VERSION = "0.74.3" HUGO_ENV = "production" [context.deploy-preview] command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL" [context.deploy-preview.environment] HUGO_VERSION = "0.74.3" [context.branch-deploy] command = "hugo --gc --minify -b $DEPLOY_PRIME_URL" [context.branch-deploy.environment] HUGO_VERSION = "0.74.3" [context.next.environment] HUGO_ENABLEGITINFO = "true" When the theme is a submodule You need to specify the theme in the build command, so add --theme=beautifulhugo
[Read More]
HTML Written Inside Markdown Not Showing Up in Hugo
HTML such as div and iframe is not being displayed
Symptoms I had not written an article in Hugo for a while, and when I posted one after a long break I noticed that the iframes and HTML inside the Markdown were not being displayed.
Cause When I looked into it, it turns out that with Goldmark, the Markdown parser newly adopted from Hugo v0.60, HTML tags inside Markdonw are ignored under the default settings
Solution Since ignoring (stripping) HTML tags inside Markdonw is the default, it seems all you have to do is explicitly configure it not to ignore them
[Read More]
GCC Error Keeps Hugo from Starting on CentOS 7
hugo does not start because of a gcc error
When I installed the latest version of Hugo on CentOS7, it would no longer start because of the error below
./hugo version
./hugo: /lib64/libstdc++.so.6: version GLIBCXX_3.4.20' not found (required by ./hugo) ./hugo: /lib64/libstdc++.so.6: version GLIBCXX_3.4.21’ not found (required by ./hugo)
Checking the GCC version Copy # strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX GLIBCXX_3.4 GLIBCXX_3.4.1 GLIBCXX_3.4.2 GLIBCXX_3.4.3 GLIBCXX_3.4.4 GLIBCXX_3.4.5 GLIBCXX_3.4.6 GLIBCXX_3.4.7 GLIBCXX_3.4.8 GLIBCXX_3.4.9 GLIBCXX_3.4.10 GLIBCXX_3.4.11 GLIBCXX_3.4.12 GLIBCXX_3.4.13 GLIBCXX_3.4.14 GLIBCXX_3.4.15 GLIBCXX_3.4.16 GLIBCXX_3.4.17 GLIBCXX_3.4.18 GLIBCXX_3.4.19 It looks like the GCC version on CentOS is still old
[Read More]
Switching the Beautifulhugo Submodule Back to the master Branch
Notes on changing the branch of a git submodule
The beautifulhugo theme this site uses was pinned to a particular branch and was not being updated to the latest version, so these are my notes on switching it to master
There had been updates on the official site and yet the theme inside the submodule was not updating; I wondered why, and it turned out to be because it was on a specific branch. (I thought I had set it to master when I first installed it…?)
[Read More]
socket: too many open files When Starting Hugo on a Mac
Raising the macOS file descriptor limit so that hugo can start
When I tried to run a certain theme with Hugo on MacOS Sierra, the error below appeared and it would not start
Error: listen tcp 127.0.0.1:1313: socket: too many open files
Looking into it, it turned out that the ulimit on the Mac needs to be changed, and I solved it by referring to macOS Sierraでulimitを変更する方法 - Carpe Diem (in Japanese).
Changing the ulimit
# cat /Library/LaunchDaemons/limit.maxfiles.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>524288</string>
<string>524288</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
# cat /Library/LaunchDaemons/limit.maxproc.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>2048</string>
<string>2048</string>
</array>
<key>RunAtLoad</key>
<true />
<key>ServiceIPC</key>
<false />
</dict>
</plist># chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
# chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
# chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist
# chmod 644 /Library/LaunchDaemons/limit.maxproc.plistRestarting the Mac
Checking the change
$ ulimit -a
Maximum size of core files created (kB, -c) 0
Maximum size of a process’s data segment (kB, -d) unlimited
Maximum size of files created by the shell (kB, -f) unlimited
Maximum size that may be locked into memory (kB, -l) unlimited
Maximum resident set size (kB, -m) unlimited
Maximum number of open file descriptors (-n) 524288
Maximum stack size (kB, -s) 8192
Maximum amount of cpu time in seconds (seconds, -t) unlimited
Maximum number of processes available to a single user (-u) 2048
Maximum amount of virtual memory available to the shell (kB, -v) unlimitedWhy I Switched from WordPress to Hugo, and What It Cost Me
The reasons for leaving WordPress for a static site generator
Why I switched from WordPress to Hugo I had been using WordPress for more than 10 years to write articles, but lately I update it less often, and even so I have to update WordPress itself and its plugins frequently, which is also a nuisance from a security point of view. On top of that, the articles on this site do not really need to be a blog; they are closer to static pages.
[Read More]
Patching Beautifulhugo to Work with Hugo 0.57
Fixing the theme to keep up with the spec changes in the Hugo upgrade
With the Hugo version upgrade it looks like some variable formats will stop working from now on, so I made the theme handle them.
In Beautifulhugo they are not handled in versions from before May, so this may end up being only a temporary fix.
Environment Hugo 0.57
Beautifulhugo :handled from 2019-05-08 onwards (the information below is from before 2019−05-08)
Edited files layouts/_default/list.html layouts/index.html layouts/partials/footer.html layouts/partials/head.html Changes Before After {{ .Hugo.Generator }} {{ hugo.Generator }} {{ .RSSLink }} {{ with .OutputFormats.Get “RSS” }}{{ . RelPermalink }}{{ end }} {{ .Hugo.Version }} {{ .Site.Hugo.Version }} {{ .URL }} {{ .Permalink }}, {{ .RelPermalink }} .Data.Pages .Site.RegularPages Edited sections layouts/_default/list.html Copy @@ -47,12 +47,12 @@ <ul class="pager main-pager"> {{ if .Paginator.HasPrev }} <li class="previous"> - <a href="{{ .URL }}page/{{ .Paginator.Prev.PageNumber }}/">← {{ i18n "newerPosts" }}</a> + <a href="{{ .Permalink }}page/{{ .Paginator.Prev.PageNumber }}/">← {{ i18n "newerPosts" }}</a> </li> {{ end }} {{ if .Paginator.HasNext }} <li class="next"> - <a href="{{ .URL }}page/{{ .Paginator.Next.PageNumber }}/">{{ i18n "olderPosts" }} →</a> + <a href="{{ .Permalink }}page/{{ .Paginator.Next.PageNumber }}/">{{ i18n "olderPosts" }} →</a> </li> {{ end }} </ul> layouts/index.html Copy @@ -9,7 +9,7 @@ {{ end }} <div class="posts-list"> - {{ $pag := .Paginate (where .Data.Pages "Type" "post") }} + {{ $pag := .Paginate (where .Site.RegularPages "Type" "post") }} {{ range $pag.Pages }} <article class="post-preview"> <a href="{{ .Permalink }}"> @@ -49,12 +49,12 @@ <ul class="pager main-pager"> {{ if .Paginator.HasPrev }} <li class="previous"> - <a href="{{ .URL }}page/{{ .Paginator.Prev.PageNumber }}/">← {{ i18n "newerPosts" }}</a> + <a href="{{ .Permalink }}page/{{ .Paginator.Prev.PageNumber }}/">← {{ i18n "newerPosts" }}</a> </li> {{ end }} {{ if .Paginator.HasNext }} <li class="next"> - <a href="{{ .URL }}page/{{ .Paginator.Next.PageNumber }}/">{{ i18n "olderPosts" }} →</a> + <a href="{{ .Permalink }}page/{{ .Paginator.Next.PageNumber }}/">{{ i18n "olderPosts" }} →</a> </li> {{ end }} </ul> layouts/partials/footer.html Copy @@ -17,10 +17,8 @@ {{ end }} {{ if .Site.Params.rss }} <li> - {{ if .RSSLink }} - <a href="{{ .RSSLink }}" title="RSS"> - {{ else }} - <a href="{{ .Site.RSSLink }}" title="RSS"> + {{ with .OutputFormats.Get "RSS" }} + <a href='{{ .RelPermalink }}' title='RSS'> {{ end }} layouts/partials/head.html Copy @@ -61,7 +61,7 @@ <meta property="og:type" content="website" /> <meta property="og:site_name" content="{{ .Site.Title }}" /> <!-- Hugo Version number --> - {{ .Hugo.Generator -}} + {{ hugo.Generator -}} References:
[Read More]
Things to Decide First When You Start a Hugo Site
Items worth deciding before you build a site with Hugo
A note to myself on the items I want to decide first in Hugo Choosing a theme The way front matter and shortcodes are written differs from theme to theme, and layout and CSS matter too, so I want to take my time at the start and settle on a theme that is easy to customize
Hugo Themes: Complete List Since a Hugo version upgrade can turn some syntax invalid, it may be better to pick a theme that is updated frequently
My personal recommendations would be Academic, Tranquilpeak, Learn and Beautifulhugo
[Read More]
How to Make Hugo Output .html URLs with uglyURLs
How do you make the site output .html?
The output format of a site differs from theme to theme, but when you write an article called content, the output format is normally something like the following.
Copy https://your-site/post/content/ https://your-site/content/ When you want to make this your-site/content.html, that is, end it in .html
Add the following inside config.toml
Copy uglyURLs = true Note: If “url:xxxx” is written in the front matter of an article, it takes precedence, so uglyURLS has no effect and you do not get the html format. If it is written, only that article gets output as something like your-site/xxxx/
[Read More]
Preventing Copy and Paste of Posts in Beautifulhugo
Applying copy-and-paste protection
Preventing copy and paste of posts
Referring to “テキストのドラッグ、画像のコピーを禁止して、記事をコピーさせない方法 ” (in Japanese), I disable text selection (dragging)
Note that this is applied for the Beautifulhugo theme, so adapt it as appropriate for other themes.
Adding the script
Add this inside the body tag
- beautifulhugo/layouts/_default/baseof.html
<body onMouseDown="return false;" onSelectStart="return false">Fixing the CSS
Add this to the css for body
- beautifulhugo/static/css/main.css
user-select:none;
-webkit-user-select:none;
-ms-user-select: none;
-moz-user-select:none;
-khtml-user-select:none;
-webkit-user-drag:none;
-khtml-user-drag:none;The point
In short, all you need to do is write the Javascript inside the body tag and apply the CSS to body in the CSS