ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。
https://ckai.xyz
更好的阅读体验
前言
hugo博客新建和推送时需要很多指令,那么每次都输入同样的指令多么无趣,影响了写作体验,可以通过脚本来解决这个问题
脚本
思路
我们要明确的就是几个功能,比如新建、本地运行和推送
那么就只需要几个判断就能解决这个问题
主要的指令用个语言自带的库来系统调用就行
选择
我选择了cpp来写,无论是什么系统,cpp编译后就是可执行的文件,方便且快;另一个本来就不需要特别复杂的库的功能,所以不需要特别高级地语言
贴代码
#include <iostream>
#include <cstdlib>
using namespace std;
string command;
void New(){
string input;
cout << "1. post 2. page 3. categories 4. tags";
cin >> input;
string title;
cout << "Enter the title of the new article: ";
cin.ignore();
getline(cin, title);
if (input == "1") {
command = "hugo new post/" + title + "/index.md";
} else if (input == "2") {
command = "hugo new page/" + title + "/index.md";
} else if (input == "3") {
command = "hugo new categories/" + title + "/_index.md";
} else {
command = "hugo new tags/" + title + "/_index.md";
}
}
void Server(){
command = "hugo server -D -p 16888";
}
void Deploy(){
command = "hugo && cd public && git add . && git status && git commit -m \"add commit\" && git push";
}
int main() {
string input;
cout << "1. New 2. Server 3. Deploy";
cin >> input;
if (input == "1") {
New();
} else if (input == "2") {
Server();
} else if (input == "3") {
Deploy();
}
system(command.c_str());
return 0;
}
PS: 我用的stack主题,大家可以根据自己主题情况来修改
使用
写入个cpp文件,然后用g++编译
点击可运行文件就可以愉快地使用了~~~
PS: C++学的很烂,大佬们可以帮本蒟蒻纠错