๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

[Step by Step Tutorial] 05. Includes

Includes

์ด์ œ ์‚ฌ์ดํŠธ๊ฐ€ ํ•ฉ์ณ์ง€๊ณ  ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ํŽ˜์ด์ง€ ์‚ฌ์ด์— ๋„ค๋น„๊ฒŒ์ด์…˜์ด ์—†๋‹ค.

๋„ค๋น„๊ฒŒ์ด์…˜์€ ๋ฐ˜๋“œ์‹œ ๋ชจ๋“  ํŽ˜์ด์ง€์— ์žˆ์–ด์•ผ ํ•˜๋ฏ€๋กœ ๋ ˆ์ด์•„์›ƒ์— ๋„ฃ๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•˜๋‹ค. ๋ ˆ์ด์•„์›ƒ์— ์ง์ ‘์ ์œผ๋กœ ๋„ฃ๋Š” ๋ฐฉ๋ฒ• ๋Œ€์‹ ์— include ๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์›Œ๋ณด๋ ค๊ณ ํ•œ๋‹ค.


Include ํƒœ๊ทธ#


include ํƒœ๊ทธ๋Š” _includes ํด๋”์— ์žˆ๋Š” ๋‹ค๋ฅธ ํŒŒ์ผ์˜ ์ฝ˜ํ…์ธ ๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. include ๋Š” ์‚ฌ์ดํŠธ ์ „๋ฐ˜์— ๋ฐ˜๋ณต๋˜๋Š” ์†Œ์Šค์ฝ”๋“œ์— ๋Œ€ํ•œ ๋‹จ์ผ ์†Œ์Šค๋ฅผ ๊ฐ–๊ฒŒ ํ•ด์ฃผ๊ณ , ๊ฐ€๋…์„ฑ์„ ๋†’์—ฌ์ค€๋‹ค.

๋„ค๋น„๊ฒŒ์ด์…˜ ์†Œ์Šค์ฝ”๋“œ๋Š” ๋‚˜์ค‘์— ๋ณต์žกํ•ด์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— include ๋ฅผ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.


Include ์‚ฌ์šฉ๋ฒ•#


๋„ค๋น„๊ฒŒ์ด์…˜ ํŒŒ์ผ์„ _includes/navigation.html ์— ์ƒ์„ฑํ•œ๋‹ค.

<nav>    <a href="/">Home</a>    <a href="/about.html">About</a></nav>

๋„ค๋น„๊ฒŒ์ด์…˜์„ include ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด layout ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

_layouts/default.html

<!DOCTYPE html><html>    <head>        <meta charset="utf-8" />        <title>{{ page.title }}</title>    </head>    <body>        {% include navigation.html %} {{ content }}    </body></html>

ํ˜„์žฌ ํŽ˜์ด์ง€ ํ•˜์ด๋ผ์ดํŒ…#


๋„ค๋น„๊ฒŒ์ด์…˜์—์„œ ํ˜„์žฌ ์œ„์น˜๋ฅผ ํ•˜์ด๋ผ์ดํŒ… ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ํ•„์š”ํ•˜๋‹ค.

_includes/navigation.html ์€ ์ž์‹ ์ด ์‚ฝ์ž…๋œ ํ˜„์žฌ ํŽ˜์ด์ง€์˜ URL์„ ์•Œ ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. Jekyll์˜ ์œ ์šฉํ•œ ๋ณ€์ˆ˜ page.url ์„ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๋ ‡๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

page.url ์„ ์ด์šฉํ•ด์„œ ๊ฐ ๋งํฌ๊ฐ€ ํ˜„์žฌ ํŽ˜์ด์ง€์ธ์ง€ ํ™•์ธํ•˜๊ณ  ์ฐธ์ด๋ฉด ๋นจ๊ฐ„์ƒ‰์œผ๋กœ ์ƒ‰์น ํ•œ๋‹ค.

<nav>  <a href="/" {% if page.url == "/" %}style="color: red;"{% endif %}>    Home  </a>  <a href="/about.html" {% if page.url == "/about.html" %}style="color: red;"{% endif %}>    About  </a></nav>