MyHugo
Oct 9, 2016
Technology
MyHugo
Since I switched from octopress to hugo, hugo is wonderful, but I get used to use Octopress’s naming method. For example, if I create a new post in Octopress I’d rather using following command:
$ rake new_post["PostName"]
Then the generated post name would be something like following:
$ ls -lt | more
total 3632
-rw-rw-r-- 1 dash dash 5292 Apr 1 2016 2015-11-05-good-material.markdown
-rw-rw-r-- 1 dash dash 540 Apr 1 2016 2016-01-04-purge-cloudstack-env.markdown
-rw-rw-r-- 1 dash dash 22256 Apr 1 2016 2016-01-15-linux-tips-4.markdown
While hugo use the origin name, like:
$ hugo new post/ABC.md
$ ls -lt content/post | more
-rw-rw-r-- 1 dash dash 5292 Apr 1 2016 ABC.md
So I wrote a small script for using the same naming principle of Octopress:
$ cat /usr/bin/myhugo
#!/bin/sh
# Create post using hugo.
hugo new post/$1.md
# Add current date timestamp.
mv content/post/$1.md content/post/`date --rfc-3339=date`-$1.md
# Hint for editing.
echo "Please Edit" $PWD/content/post/`date --rfc-3339=date`-$1.md
Now using myhugo for creating the post will be looked like:
$ ~/myhugo WriteLeetCode
/home/dash/Code/purplepalmdash.github.io/content/post/WriteLeetCode.md created
Please Edit
/home/dash/Code/purplepalmdash.github.io/content/post/2016-10-09-WriteLeetCode.md
Enjoy the rake new_post
style post name!
MyHugoServe
Just add an alias in ~/.zshrc
:
alias hugoserve='hugo serve -w --theme=hyde-a'
Then type hugoserve
will start local preview and you visit http://localhost:1313
for previewing your website.