블로그 개발 쉽게하기 (with. hugo)

블로그 개발 쉽게하기 (with. hugo)

2023년 6월 2일

hugo 최신버전 설치하기 #

우분투에서 $apt-get install hugo 로 물론 설치할 수 있다.
하지만 이렇게 설치하면 0.94.0이 최신버전이 된다. ReLearn 테마를 설치하기 위해서는 0.95.0 이상 버전의 휴고가 설치되어야 하기때문에 다른 방법을 찾아야한다.

1. go 최신버전 설치 및 환경변수 세팅 #

https://go.dev/dl/
이 사이트에서 최신버전의 go를 찾을 수 있다. 링크만 따와서 우분투에서 wget으로 가져온다

 1$ wget [download link]      # ex) go1.20.linux-amd64.tar.gz
 2$ sudo tar -xvf [go_tar_file]
 3$ sudo mv go /usr/local/   
 4
 5# 환경변수 세팅 .profile의 맨 아래에 export 추가
 6$ vi .profile   
 7export GOROOT=/usr/local/go
 8export PATH=$PATH:$GOROOT/bin:
 9
10$ source .profile
11$ go version

2. go로 hugo 빌드 및 설치 #

hugo는 일반버전과 extended 버전이 따로 있다. 특정 테마를 이용하기 위해서는 Sass/SCSS 컴파일을 지원하는 extended 버전을 설치해야한다.

1# 일반버전
2$ go install github.com/gohugoio/hugo@latest
3# extended 버전
4$ CGO_ENABLED=1 go install --tags extended github.com/gohugoio/hugo@latest
5
6$ hugo version

퀵스타트 (+테마설정) #

원하는 테마를 https://themes.gohugo.io/ 사이트에서 고른 후 아래의 방식으로 적용하면 된다.
nohup 을 이용해서 서버를 켜면 현재 터미널이 종료되더라도 계속 실행된다.

 1# 휴고 레파지토리 파기
 2$ hugo new site [folder]
 3$ cd [folder]
 4$ git init
 5$ git config --global user.name "kimdong"
 6$ git config --global user.email "parktest0325@gmail.com"
 7$ git remote add origin [remote]
 8
 9# 테마설정
10$ git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke
11$ echo "theme = 'ananke'" >> config.toml
12
13# 실행
14$ nohup hugo server --bind="0.0.0.0" &
15
16# 글쓰기. 아래 명령 이후 vim으로 열어서 내용 작성
17# 디폴트 draft 옵션이 true라서 -D 옵션을 포함해서 서버를 켜야 보인다.
18$ hugo new posts/my-first-post.md

서브모듈(테마) 삭제하는 방법 #

1$ git submodule deinit -f themes/hugo-book
2$ rm -rf .git/modules/themes/hugo-book
3$ rm -rf themes/hugo-book
4# git add, commit 을 진행해야 삭제되고 다시 다른 테마를 적용할 수 있다.

테마를 직접 clone 받아서 설치해도 적용은 되지만, 나는 내가 직접 테마를 커스텀하고 관리할 예정이기 때문에 테마개발자의 레포를 fork 하고, 내 레포를 submodule로 지정했다.

comments powered by Disqus