Hugo—搭建草稿箱

配置草稿环境

在archetypes文件夹下创建draft.md文件,核心是设置draft: true

md

---
title: '{{ replace .File.ContentBaseName "-" " " | title }}'
tags:
series:
categories:
date: {{ .Date }}
modified: {{ .Date }}
draft: true
---

通过以下脚本,可以在content/drafts/ 创建一个当前时间的草稿

sh

@echo off
rem Get the date components
for /F "tokens=2-4 delims=/ " %%A in ('date /t') do (
    set month=%%A
    set day=%%B
    set year=%date:~0,4%
)
rem Get the time components
for /F "tokens=1-2 delims=: " %%a in ('time /t') do (
    set hour=%%a
    set minute=%%b
)

rem Remove leading space in hour if necessary
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%

rem Format date and time
set formatteddate=%year%-%month%-%day%
set formattedtime=%hour%%minute%

rem Create the filename
set filename=%formatteddate%-draft%formattedtime%.md

rem Use Hugo to create a new draft post
hugo new --kind draft drafts/%filename%
pause

复制默认的 hugo.toml文件为 hugo_draft.toml,追加以下配置

TOML

[menu]
  [[menu.main]]
    identifier = "drafts"
    pre = ""
    post = ""
    name = "草稿箱"
    url = "/drafts/"
    title = ""
    weight = 6

添加以下脚本,用于启动草稿环境

SH

@echo off
hugo server --buildDrafts --buildFuture --config hugo_draft.toml
pause