banner
朝闻道

朝闻道

做个知行合一的人
email

Simplify the method of common operations in 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, I need to enter hugo new posts/newfilename.md in vscode terminal to create a new file.
  • Every time a file is uploaded, I need to enter at least 5 commands in the vscode terminal... hugo, cd public, git add ....
  • If I have to enter 5 commands every time I make a change and upload, it becomes 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, press Tab, and then press Enter. This will 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. This will 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.