hugo new site <sitename>
명령을 실행한 디렉토리가 아니면 hugo new [title]
명령을 실행할 수 없다고 했습니다. 그런데, 그 디렉토리로 이동하는 것이 귀찮았습니다. 아무데서나 실행해도 되는 그런 개쩌는 커맨드는 없을까요? 없으면 스크립트를 만드는 건 어떨까요? 어떤 분은 .zshrc
에 쉘 스크립트를 정의하기도 하는 것 같습니다.
1
2
3
4
| local BLOG_PATH=<the path to my Hugo files>
function hugonew() {
cd $BLOG_PATH && hugo new content/post/$1.md
}
|
powershell을 사용해 볼까요?
해당 디렉토리로 이동해서 포스트 만들기
현재의 디렉토리가 어느 곳이던지, 블로그 포스트를 만드는 스크립트를 만들고 싶었습니다. 이름은 New-HugoPost
version 1
1
2
3
4
5
| Function New-HugoPost {
param([string] $title)
cd $env:userprofile\blog
hugo new $title
}
|
parameter의 validation 넣어줄까요?
version 2
1
2
3
4
5
| Function New-HugoPost {
param([string] $title = ${throw "no title given."})
cd $env:userprofile\blog
hugo new $title
}
|
블로그 포스트 타이틀을 만들 때, .md
를 잊고 쓰기도 합니다. 쓰지 않으면 자동으로 쓰게 해주면 어떨까요? 자동으로 .md
확장자가 붙도록 처리했습니다.
version 3
1
2
3
4
5
6
7
8
9
| Function New-HugoPost {
param([string] $title = ${throw "no title given."})
if (! $title.EndsWith(".md")) {
$title += ".md"
}
cd $env:userprofile\blog
hugo new $title
}
|
실행 예
1
2
| PS C:\Users\Administrator\blog> new-hugopost "hugo/Configure Markup 읽어보기"
C:\Users\Administrator\blog\content\hugo\Configure Markup 읽어보기.md created
|
그런데, 따옴표를 쓰기가 귀찮았습니다. 따옴표를 안쓰면 안될까요?
1
2
3
4
5
6
7
8
9
10
11
| Function New-HugoPost {
param([string[]] $titles = ${throw "no title given."})
$title = $titles -join ' '
if (! $title.EndsWith(".md")) {
$title += ".md"
}
cd $env:userprofile\blog
hugo new $title
}
|
포스트 이름부터 쓰고 명령을 내리는 것은 어떨까요? 예를 들면 파이프라인을 사용해서 말이죠
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Function New-HugoPost {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[string[]] $titles = ${throw "no title given."})
$title = $titles -join ' '
if (! $title.EndsWith(".md")) {
$title += ".md"
}
cd $env:userprofile\blog
hugo new $title
}
|
powershell function accept pipeline input
으로 검색해 보았습니다.
[Parameter(ValueFromPipeline)]
에 대한 문서페이지로 이동할 수 있었습니다.
1
2
| PS C:\Users\Administrator\blog> "hugo/파이프라인을 이용해서 만들어보았습니다" | new-hugopost
C:\Users\Administrator\blog\content\hugo\파이프라인을이용해서 만들어보았습니다.md created
|
이건 어떻게 할가요?
new-hugopost "hugo/post만들 때 draft false 하기.md"
hugo language
만일 post안에 hugo markup을 사용해서 템플릿을 만들어야 한다면, 다음의 Snippet을 제공하는 Extension을 사용해 보는 것도 좋습니다.
https://marketplace.visualstudio.com/items?itemName=budparr.language-hugo-vscode