hugo 文章编辑
新建文章命令
1
| hugo new "post/hugo 文章编辑/index.md"
|
[!NOTE]
新建名为《hugo 文章编辑》的文章
文章路径:.\content\post\hugo 文章编辑\index.md
新建文章.bat
执行此批处理后,终端输入文章标题,自动创建文章并用记事本打开可以编辑文章内容。
我的项目路径:电脑桌面GitHub\hugo-main
(自行修改)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| @echo off :: 设置工作目录(确保路径正确) set "hugoDir=%USERPROFILE%\Desktop\GitHub\hugo"
:: 检查目录是否存在 if not exist "%hugoDir%" ( echo 目标目录 %hugoDir% 不存在,请检查路径是否正确。 pause exit )
:: 提示用户输入文件名 set /p fileName=请输入文章名:
:: 检查是否输入了文件名 if "%fileName%"=="" ( echo 文件名不能为空,请重新运行脚本并输入有效的文件名。 pause exit )
:: 切换到 Hugo 项目目录 cd /d "%hugoDir%"
:: 使用 hugo new 命令创建新文件 echo 正在创建新文件... hugo new "post/%fileName%/index.md"
:: 检查文件是否创建成功 set "contentPath=%hugoDir%\content\post\%fileName%\index.md" if not exist "%contentPath%" ( echo 文件 %fileName% 的创建失败,请检查 Hugo 是否正确安装并配置。 pause exit )
:: 提示用户文件已创建 echo 文件 %fileName% 已成功创建在 %contentPath%!
:: 打开记事本并加载文件后退出CMD echo 正在打开记事本... start notepad.exe "%contentPath%" exit
|
文章模板
- 文章模板路径:
".\archetypes\default.md"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| --- title: "{{ replace .Name "-" " " | title }}" slug: "{{ replace .Name "-" " " | title }}" date: {{ .Date }} description: "" summary: "" math: true hidden: false comments: true draft: false showToc: true TocOpen: true autonumbering: true hidemeta: false disableShare: true searchHidden: false showbreadcrumbs: true
weight:
image:
categories: - 默认分类
tags: - Blog ---
|