banner
朝闻道

朝闻道

做个知行合一的人
email

Simplify the common operations of Hugo

Blogging Tools I Use#

  • hugo: Blog website generation tool
  • vscode: File editing tool
  • git: Tool for uploading files to Github
  • Shell scripting: Write one-click command code

When using vscode and git, every time I update my blog, I need to enter a series of repetitive code in the terminal. The following content may be helpful for users who are troubled by this.

Inconveniences of Using vscode and git#

  • Every time a new file is created, you need to enter hugo new posts/new_filename.md in the vscode terminal to create a new file.
  • Every time a file is uploaded, you need to enter at least 5 commands in the vscode terminal... hugo, cd public, git add ....
  • If you have to enter 5 commands every time you make a change and upload it, it can be unpleasant and tiresome.

So, is there a better solution?
The answer is yes.

Solutions#

One-click File Creation#

  1. First, create a new.sh file in the top-level folder of the blog.
  2. Enter the following content in the file:
time=$(date "+%Y-%m-%d")
echo $time
hugo new posts/$time.md
exit
  1. When creating a new file, enter new in the terminal, then press Tab, and finally press Enter to create a new file in the posts/ directory with the current date as the file name.

One-click File Upload#

  1. First, create a hugo.sh file in the top-level folder of the blog.
  2. Enter the following content in the file:
hugo
time=$(date "+%Y-%m-%d %H:%M:%S")
echo $time
cd public
git add .
git commit -m "Automated build script execution 🎓$time"
git push
exit
  1. When updating (uploading) a file, enter hugo in the terminal, press Tab, and then press Enter to automatically upload the updated blog to Github with the current date as the update message.

If you have any questions, please contact me via email.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.