๐ ๋ธ๋ก๊ทธ์คํ ๋ณธ๋ฌธ์ ๋ชฉ์ฐจ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ
๋ธ๋ก๊ทธ์คํ(Blogger) ํ ๋ง ์ค ์ผ๋ถ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ณธ๋ฌธ ๋ชฉ์ฐจ ๊ธฐ๋ฅ์ด ์์ต๋๋ค. ํ์ง๋ง HTML ํธ์ง์ ํตํด ๊ฐ๋จํ ์ฝ๋๋ง ์ถ๊ฐํ๋ฉด ๋ชฉ์ฐจ ๊ธฐ๋ฅ์ ํ์ฑํํ ์ ์์ต๋๋ค.
์ด ๋ชฉ์ฐจ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ํ ์๋ ํํ์ด๋ฉฐ, H2์ H3 ์์ ๋ชฉ๋ง ์๋์ผ๋ก ๋ฐ์๋๋ฉฐ ํด๋ฆญํ๋ฉด ํด๋น ๋ถ๋ถ์ผ๋ก ์ด๋ํ๋ ๊ธฐ๋ฅ๊น์ง ํฌํจ๋์ด ์์ต๋๋ค.
1️⃣ HTML ํธ์ง๊ธฐ์์ ์ฝ๋ ์ถ๊ฐํ๊ธฐ
- ๋ธ๋ก๊ทธ์คํ ๊ด๋ฆฌ์ ํ์ด์ง๋ก ์ด๋
- "ํ ๋ง" → "HTML ํธ์ง" ํด๋ฆญ
Ctrl + F๋ฅผ ๋๋ฌ</head>๋ฅผ ๊ฒ์- ์๋ ๋ชฉ์ฐจ ์ฝ๋๋ฅผ
</head>์์ ๋ถ์ฌ๋ฃ๊ธฐ
2️⃣ ๋ธ๋ก๊ทธ์คํ ๋ณธ๋ฌธ ๋ชฉ์ฐจ ์ฝ๋
๐ ์คํฌ๋ฆฝํธ (JavaScript)
html
<script>
//<![CDATA[
function insertTOC() {
var postBody = document.querySelector('.post-body');
if (!postBody) return;
var toc = document.createElement('div');
toc.className = 'toc';
toc.innerHTML = '<div class="toc-header"><b>๋ชฉ์ฐจ</b><span class="toc-toggle">▼</span></div><div class="toc-content"><ul></ul></div>';
var headings = postBody.querySelectorAll('h2, h3');
var tocList = toc.querySelector('ul');
headings.forEach(function(heading, index) {
var anchor = 'toc-' + index;
heading.id = anchor;
var li = document.createElement('li');
var a = document.createElement('a');
a.textContent = heading.textContent;
a.href = '#' + anchor;
if (heading.tagName === 'H3') li.style.marginLeft = '20px';
li.appendChild(a);
tocList.appendChild(li);
});
var tocHeader = toc.querySelector('.toc-header');
var tocToggle = toc.querySelector('.toc-toggle');
var tocContent = toc.querySelector('.toc-content');
tocHeader.addEventListener('click', function() {
tocContent.style.display = tocContent.style.display === 'none' ? 'block' : 'none';
tocToggle.textContent = tocContent.style.display === 'none' ? '▼' : '▲';
});
tocContent.style.display = 'none';
tocToggle.textContent = '▼';
postBody.insertBefore(toc, postBody.firstChild);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', insertTOC);
} else {
insertTOC();
}
//]]>
</script>
๐ ์คํ์ผ (CSS)
css
<style>
.toc {
background-color: #f8f9fa;
border: 1px solid #d3d3d3;
border-radius: 8px;
padding: 10px 13px;
margin-bottom: 20px;
font-size: 14px;
line-height: 1.6;
}
.toc-header {
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
user-select: none;
}
.toc h2 {
margin: 0;
font-size: 18px;
}
.toc-toggle {
font-size: 16px;
}
.toc ul {
list-style-type: none;
padding-left: 0;
margin: 10px 0 0;
}
.toc ul li {
margin-bottom: 5px;
}
.toc a {
text-decoration: none;
color: #0645ad;
}
.toc a:hover {
text-decoration: underline;
}
</style>
3️⃣ ์ ์ฅ ํ ์ ์ฉ ํ์ธ
- ์ฝ๋ ์ ๋ ฅ ํ "์ ์ฅ(๐พ)" ๋ฒํผ ํด๋ฆญ
- ๋ธ๋ก๊ทธ ๋ฉ์ธ ํ์ด์ง์์ ๋ณธ๋ฌธ์ ํ์ธ
- ์ ์์ ์ผ๋ก
๋ชฉ์ฐจ๊ฐ ์ถ๊ฐ๋์๋์ง ์ฒดํฌ
✅ ๋ชฉ์ฐจ ๊ธฐ๋ฅ ์ค๋ช
H1์์H3๊น์ง์ ํ๊ทธ๋ฅผ ์๋์ผ๋ก ๊ฐ์งํ์ฌ ๋ชฉ์ฐจ๋ฅผ ์์ฑ- ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชฉ์ฐจ๋ ์ ํ ์์ผ๋ฉฐ, ํด๋ฆญํ๋ฉด ํผ์ณ์ง
- ๋ชฉ์ฐจ์ ํญ๋ชฉ์ ํด๋ฆญํ๋ฉด ํด๋น ์ ๋ชฉ(H1, H2, H3)์ผ๋ก ์ด๋
๐ ์ด์ ๋ธ๋ก๊ทธ์คํ์์๋ ํธ๋ฆฌํ ๋ชฉ์ฐจ ๊ธฐ๋ฅ์ ์ถ๊ฐํ์ฌ ๊ฐ๋ ์ฑ์ ๋์ฌ๋ณด์ธ์! ๐
๋๊ธ ์ฐ๊ธฐ