Hugo Include - ํ์ผ์ ํฌํจ์ํค๊ธฐ
์๊ฐ Hugo๋ก ํํ์ด์ง๋ฅผ ์ ์ํ ๋ ์ฃผ๋ก ๋งํฌ๋ค์ด(markdown)์ผ๋ก ์์ ์ ํ๋ค. ์ฝ๋๋ธ๋ญ์ ์ฌ์ฉํ ๋ ์๋ ์์คํ์ผ์ด ๋ณ๊ฒฝ๋๋ฉด ๋ค์ ๋งํฌ๋ค์ด ๋ฌธ์๋ ์์ ์ ํด์ผํ๋ค. ์ด ๋ ์ง์ ์์ค ํ์ผ์ ์ฝ์ด์ ํ์ด์ง๋ฅผ ๋ง๋ ๋ค๋ฉด ํด๋น ์์คํ์ผ๋ง ๊ด๋ฆฌํ๋ฉด ๋ฌธ์์ ์ผ๊ด์ฑ์ด ์๊ธฐ๊ณ ๋ณ๊ฒฝํ๋๋ผ๋ ์ฆ์ ๋ฐ์๋๋ค. Hugo์์๋ shortcode๋ผ๋ ๋ฐฉ๋ฒ์ ์ ๊ณตํ์ฌ ์ฌ์ฉ์๋ง์ shortcode๋ฅผ ์์ฑํ ์ ์๋ค. Shortcode Include - ๋งํฌ๋ค์ด ํ์ผ ํฌํจํ๊ธฐ Hugo Project ๋ด์ ๋ค์ ํ์ผ์ ์์ฑ: layouts/shortcodes/include.html {{- $relPath := .Get 0 -}} {{- $baseDir := .Page.File.Dir -}} {{- $fullPath := path.Join $baseDir $relPath -}} {{- readFile $fullPath | markdownify -}} ์์ฑ๋ shortcode ์ฌ์ฉํ๊ธฐ: content/posts/mypost.md์ foo.md๋ฅผ ํฌํจํ๊ธฐ {{< include "foo.md" >}} Shortcode Code - ์ฝ๋ ํ์ผ ํฌํจํ๊ธฐ Hugo Project ๋ด์ ๋ค์ ํ์ผ์ ์์ฑ: layouts/shortcodes/code.html {{ $language := .Get "language" }} {{ $source := .Get "source" }} {{ $options := .Get "options" }} {{ with $source | readFile }} {{ highlight (trim . "\n\r") $language $options }} {{ end }} ์์ฑ๋ shortcode ์ฌ์ฉํ๊ธฐ: content/posts/mypost.md์ foo.c๋ฅผ ํฌํจํ๊ธฐ ์ฝ๋๋ธ๋ญ ๋ด์ ์๋ ์ฝ๋๋ฅผ ๋ฃ์ผ๋ฉด foo.c๋ฅผ ์ฑ์ ๋ฃ๊ณ language์ต์ ์ ๋ฐ๋ผ ์ปฌ๋ฌ๊ฐ ์ง์๋๋ค. {{< code source="example/foo.c" >}} REFERENCE How to include code examples from file with hugo: https://marcusolsson.dev/how-to-include-code-examples-from-file-with-hugo/ ...