自动化搭建博客工具
这篇文章介绍了一个用于自动化初始化 Hugo 博客环境的桌面工具,核心目标是把“手工搭建站点”转成可执行脚本流水线。工具定位与使用方式该工具面向本地博客初始化场景,先决条件是本机已安装 Git。文中提供了视频演示和项目地址,便于快速上手。同时给出配套写作工具链接,补齐“搭建后写作效率”问题。项目结构说明src 保存 Q…
软件使用 使用前请下载好git工具 视频教程 example项目介绍 项目所在地 温馨提示:本地搭建完网站框架后,每次新建文章的写作体验较差,可以看看我的另一个 hugo 博客自动化写作工具 AutoHugoSetup src目录:存放图形化项目的源代码,使用 Qt6 可直接启动 QHugoInit 项目。 bin目录:存放项目的可执行二进制文件。exec_code.bat:用于写入代码执行脚本hugo.exe:构建博客的基石QHugoInit.exe:软件启动程序log.txt:整个程序执行的日志项目关键源码 通过多线程防止下载步骤把画面给阻塞//TODO 简单封装一个用于多线程通信的类 class run_thread:public QThread{ public: run_thread() = delete; run_thread(const std::function<void()>&Runnable,QObject* parent = nullptr):m_task(nullptr){ m_task = Runnable; } void run()override{ if(m_task!=nullptr); m_task(); } private: std::function<void()>m_task; }; 通过文件io控制命令行的代码执行来执行对应的每一步void MainWindow::on_right_Btn_clicked() { auto path = ui->input->text(); if(!QDir(path).exists()||path.isEmpty()){ QMessageBox::warning(nullptr,"提示","文件夹路径不存在"); return; } ui->w2->setVisible(false); ui->w4->setVisible(false); ui->w3->setVisible(true); ui->l1->setText("一切即将准备就绪"); ui->l2->setText("正在初始化您的hugo网站"); ui->l3->setOpenExternalLinks(true); ui->l3->setText(R"(<html> <style> a { color:#3281b8; } </style><head/><body><p>这可能会耗费几分钟,请不要强制关闭应用程序<br/><br/>闲得无聊?<a href="https://github.com/ACking-you/AutoHugoSetup">给个star</a></p></body></html>)"); QProcess qp; std::ofstream writer; m_Path = path; auto std_str = m_Path.toStdString(); //first step writer.open("./exec_code.bat"); if(!writer.is_open()){ QMessageBox::warning(nullptr,"提示","第一次写入文件打开失败"); writer.close(); QCoreApplication::exit(1); } ui->info_text->setText("正在初始化 hugo 博客"); std::replace(std_str.begin(),std_str.end(),'/','\\'); //这里注意:cmd32命令只支持反斜杠! writer<<R"(chcp 65001)"<<'\n'; //设置编码为utf-8 writer<<R"(copy .\hugo.exe )"<<std_str<<'\n'; //copy一份hugo.exe到目标目录下 writer<<"cd /d"<<std_str<<'\n'; //切换到创建目录,这里/d代表直接一步到位的切换目录 writer<<R"(.\hugo new site myBlog)"<<'\n'; //初始化hugo命令 writer.close(); qp.startCommand(R"(.\exec_code.bat)"); if(qp.waitForFinished()){ QString str = qp.readAll(); m_logWriter<<"-----1st step-----\n\r"<<str.toStdString()<<'\n'; ui->info_text->setText(" hugo 博客初始化完成"); } //second step:执行此步之前先判断git是否可用,此步执行时间最久,不…
正在初始化 WebAssembly 引擎…
首次编译原生模块可能需要数秒
就绪后,页面交互将以接近原生的速度运行