์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฉํ ํฐ์คํ ๋ฆฌ ์นดํ ๊ณ ๋ฆฌ๋ณ ์ฝํ ์ธ ๋ ธ์ถ ํ๊ธฐ
ํฐ์คํ ๋ฆฌ ๋ธ๋ก๊ทธ๋ฅผ ์ด์ํ๊ฒ ๋๋ฉด, ๊ธฐ๋ณธ์ ์ผ๋ก ์ต์ ๊ธ๊ณผ ์ธ๊ธฐ๊ธ์ ์ฌ์ด๋๋ฐ์ ๋ ธ์ถํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๋ธ๋ก๊ทธ ์ด์์๊ฐ ํน์ ์นดํ ๊ณ ๋ฆฌ์ ๊ธ์ ์ ๋ณ์ ์ผ๋ก ๋ ธ์ถํด์ผ ํ๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค. ๊ทธ๋์ ์ด๋ฒ์๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ผ๋ก ๋๋ง์ ์นดํ ๊ณ ๋ฆฌ ์ต์ ๊ธ์ ์ฌ์ด๋๋ฐ์ ๋ ธ์ถํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
์๋ฐ์คํฌ๋ฆฝํธ(JavaScript)๋ฅผ ํ์ฉํ์ฌ ํน์ ์นดํ ๊ณ ๋ฆฌ์ ๊ธ์ ์๋์ผ๋ก ๋ถ๋ฌ์ค๋ ๋ฐฉ๋ฒ๊ณผ, ์ด๋ฅผ ํตํด ๊ด๋ จ๋ ๊ธ์ ๊ด๊ณ ๋ฅผ ๋ ธ์ถํจ์ผ๋ก์จ ๊ด๊ณ ์์ต์ ์กฐ๊ธ์ด๋ผ๋ ๋ ํ๋ณดํ๋ ์ฐจ์์์ ์ ์ฉํด๋ณด์์ต๋๋ค.
๋ธ๋ก๊ทธ ์ด์์์๊ฒ ๊ฐ์ฅ ํฐ ๊ณ ๋ฏผ์ ๊ณผ๊ฑฐ์ ์์ง์ ๊ธ์ด ๋ฌปํ๋ ๊ฒ๊ณผ, ๋ฐฉ๋ฌธ์๊ฐ ํ ๊ฐ์ ๊ธ๋ง ์ฝ๊ณ ์ดํํ๋ ์ ์ ๋๋ค. ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์ฐ๊ด ์ฝํ ์ธ ์ ์๋ ๋ ธ์ถ์ ์ ํ์ด ์๋ ํ์๋ผ๊ณ ํ ์ ์์ต๋๋ค. ํนํ, ๋ธ๋ก๊ทธ ์ด์์์ ์๋๋ฅผ ์ต๋ํ ์ ๋ฐ์ํ์ฌ ์ฌ์ด๋๋ฐ์ ๋ ธ์ถํ๋ ๊ฒ์ ํ์์ ์ด๋ผ๊ณ ํ ์ ์์ต๋๋ค.
- ๋ฐฉ๋ฌธ์ ์ฒด๋ฅ ์๊ฐ(Duration Time) ์ฆ๊ฐ: ๊ด๋ จ ์นดํ ๊ณ ๋ฆฌ์ ์ต์ ๊ธ์ ๋ณด์ฌ์ค์ผ๋ก์จ ํด๋ฆญ์ ์ ๋ํฉ๋๋ค.
- ํฌ๋กค๋ง ๋น๋ ์ต์ ํ: ํ์ด์ง ๋ด ๋งํฌ ๊ตฌ์กฐ๊ฐ ์ต์ ๊ธ ์์ฃผ๋ก ๊ณ์ ๊ฐฑ์ ๋๋ฉด ๊ฒ์ ์์ง ๋ด์ด ๋ ์์ฃผ ๋ฐฉ๋ฌธํฉ๋๋ค.
- ์ฌ์ฉ์ ๊ฒฝํ(UX) ๊ฐ์ : ๊ฒฝ์ ์ ๋ณด์ฒ๋ผ ์์์ฑ์ด ์ค์ํ ์ฝํ ์ธ ๋ ์ต์ ์ ๋ณด๋ฅผ ์ฆ์ ๋ ธ์ถํ๋ ๊ฒ์ด ์ ๋ขฐ๋๋ฅผ ๋์ ๋๋ค.

์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฉํ ํน์ ์นดํ ๊ณ ๋ฆฌ ์ถ์ถ (PC ์ต์ ํ)
ํฐ์คํ ๋ฆฌ์ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ํ์ฉํ์ฌ ํน์ ๊ฒฝ๋ก(category/money-insight/economy)์ ๋ฐ์ดํฐ๋ฅผ ๋น๋๊ธฐ(Async) ๋ฐฉ์์ผ๋ก ํธ์ถํ ๊ฒ์ ๋๋ค. ์ด ๋ฐฉ์์ ํ์ด์ง ์ ์ฒด๋ฅผ ์๋ก๊ณ ์นจํ์ง ์๊ณ ๋ฐ์ดํฐ๋ง ์ ๋ฝ์์ค๊ธฐ ๋๋ฌธ์ ๋งค์ฐ ๋น ๋ฆ ๋๋ค.
ํนํ, ๋ชจ๋ฐ์ผ ํ๊ฒฝ์์๋ ๋ฐ์ดํฐ ์๋ชจ์ ๋ก๋ฉ ์๋๋ฅผ ๊ณ ๋ คํด ์ ํ์ ์ผ๋ก ๋ ธ์ถํ๊ณ , PC ํ๊ฒฝ์์๋ ํ๋ คํ๊ณ ์ ๋ณด๋ ฅ ์๋ ๋ ์ด์์์ ์ ๊ณตํ๋ ์ ๋ต์ ์ทจํ ์ ์์ต๋๋ค.
1. ๋ ธ์ถ ์ ์ฉ ์ฝ๋ (HTML ํธ์ง ๋ชจ๋์ฉ)
์๋ ์ฝ๋๋ฅผ ์ ์ฉํ์๋ฉด ๋ฉ๋๋ค. ์ฌ์ด๋๋ฐ ๋๋ ์ํ๋ ๋ ธ์ถ ์์น์ ๋ค์ ์ฝ๋๋ฅผ ์ฝ์ ํด ์ฃผ์ธ์:
div id="economy-posts-container" class="seo-optimized-list"
div class="loading-spinner"
p์ต์ ๊ฒฝ์ ํต์ฐฐ๋ ฅ์ ๋ถ๋ฌ์ค๋ ์ค์
๋๋ค.../p
/div
/div
์ ๋ ๊ฒฝ์ ๊ด๋ จ ์นดํ ๊ณ ๋ฆฌ๋ฅผ ๋ ธ์ถํ๊ธฐ ๋๋ฌธ์ id ์์ฑ์ economy-posts-container๋ก ์ค์ ํ์ต๋๋ค. ํ์์ ๋ฐ๋ผ ๋ณ๊ฒฝํด์ ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค.
2. CSS ์ ์ฉํ๊ธฐ
ํ์ดํ(์ ๋ชฉ)์ ์๋จ์ ๋ ธ์ถํ๊ณ , ์ด๋ฏธ์ง๋ ๊ทธ ์๋์, ๊ทธ๋ฆฌ๊ณ ๊ธ์ ์ผ๋ถ ๋ด์ฉ์ ํ๋จ์ ๋ฐฐ์นํ CSS์ ๋๋ค. ์ด์ ๊ฐ์ ๊ตฌ์ฑ์ ์์ ์ ๋ธ๋ก๊ทธ ์คํจ์ ๋ง๊ฒ ์์ ํ์ฌ ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค.
style
/* ๊ฒ์ ์์ง๊ณผ ์ฌ์ฉ์ ๋ชจ๋๋ฅผ ๋ง์กฑ์ํค๋ ๋์์ธ */
#economy-posts-container {
display: flex;
flex-direction: column;
gap: 20px;
margin: 30px 0;
}
.eco-post-item {
display: flex;
gap: 18px;
padding: 15px;
border: 1px solid #f0f0f0;
border-radius: 12px;
text-decoration: none !important;
color: #333 !important;
transition: transform 0.3s ease, box-shadow 0.3s ease;
background: #fff;
}
.eco-post-item:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.05);
border-color: #3498db;
}
.eco-post-thumb {
flex-shrink: 0;
}
.eco-post-thumb img {
width: 150px;
height: 100px;
object-fit: cover;
border-radius: 8px;
background-color: #eee;
}
.eco-post-info {
flex: 1;
min-width: 0;
}
.eco-post-title {
margin: 0 0 8px 0 !important;
font-size: 18px !important;
font-weight: 700 !important;
line-height: 1.4 !important;
color: #222 !important;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.eco-post-date {
font-size: 12px;
color: #999;
margin-bottom: 8px;
}
.eco-post-excerpt {
margin: 0 !important;
font-size: 14px !important;
color: #666 !important;
line-height: 1.6 !important;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
3. ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋
์๋ ์ฝ๋๋ HTML ํ๋จ, ์ฆ /html ํ๊ทธ ์์ ์ ๋นํ ์์น์ ์ ์ฉํ์ธ์. ๋ชจ๋ฐ์ผ ํ๊ฒฝ์์๋ ๋ก๋ฉ ์๋์ ์ํฅ์ ์ค ์ ์๊ธฐ ๋๋ฌธ์, ๋ชจ๋ฐ์ผ์์๋ ๋ ธ์ถ๋์ง ์๋๋ก ์ค์ ํ์์ต๋๋ค. ํ์์ ๋ฐ๋ผ ์ ์ฉํ์ค ์ ์์ง๋ง, ๋ชจ๋ฐ์ผ์์๋ ๋ฆฌ์์ค ์๋ชจ๊ฐ ๋ง์ผ๋ฏ๋ก ๊ถ์ฅํ์ง๋ ์์ต๋๋ค.
const targetUrl = '/category/ํน์ -์นดํ
๊ณ ๋ฆฌ-๋ช
';
style
/* ๋ชจ๋ฐ์ผ ๋์: ํ๋ฉด์ด ์์ ๊ฒฝ์ฐ ์ธ๋ค์ผ ์จ๊ธฐ๊ธฐ ์ ํ ๊ฐ๋ฅ */
@media (max-width: 768px) {
.eco-post-thumb img { width: 100px; height: 70px; }
.eco-post-title { font-size: 16px !important; }
}
/style
script
(async function() {
const container = document.getElementById('economy-posts-container');
const maxPosts = 5;
// ๋์ ์นดํ
๊ณ ๋ฆฌ URL ๊ฒฝ๋ก
const targetUrl = '/category/ํน์ -์นดํ
๊ณ ๋ฆฌ-๋ช
';
try {
const res = await fetch(targetUrl);
if (!res.ok) throw new Error('Network response was not ok');
const text = await res.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');
// ํฐ์คํ ๋ฆฌ ์คํจ๋ณ ์ ํ์(Selector) ์กฐ์ ํ์ (์: .post-item, .article-content ๋ฑ)
// ์๋๋ ์ผ๋ฐ์ ์ธ ํฐ์คํ ๋ฆฌ ๋ชฉ๋ก ๊ตฌ์กฐ๋ฅผ ํ๊ฒํ
ํฉ๋๋ค.
const items = Array.from(doc.querySelectorAll('.post-item, .list-row, .article-content')).slice(0, maxPosts);
if(items.length === 0) {
container.innerHTML = 'p style="text-align:center; color:#999; padding:20px;"ํ์ฌ ํด๋น ์นดํ
๊ณ ๋ฆฌ์ ์ต์ ๊ธ์ด ์์ต๋๋ค./p';
return;
}
let html = '';
items.forEach(item = {
const linkEl = item.querySelector('a')?.href || '#';
const titleEl = item.querySelector('.title, .link_post, dt')?.textContent?.trim() || '์ ๋ชฉ ์์';
const thumbEl = item.querySelector('img')?.src || 'https://t1.daumcdn.net/tistory_admin/static/top/pc/img_common_tistory_empty.png';
const dateEl = item.querySelector('.date, .post-date')?.textContent?.trim() || '';
const excerptEl = item.querySelector('.excerpt, .desc, dd')?.textContent?.trim() || '๋ณธ๋ฌธ ์์ฝ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค.';
html += `
article class="eco-article-card"
a href="${linkEl}" class="eco-post-item"
div class="eco-post-thumb"
img src="${thumbUrlFix(thumbEl)}" alt="${titleEl}" loading="lazy"
/div
div class="eco-post-info"
h3 class="eco-post-title"${titleEl}/h3
div class="eco-post-date"${dateEl}/div
p class="eco-post-excerpt"${excerptEl.substring(0, 120)}.../p
/div
/a
/article
`;
});
container.innerHTML = html;
} catch(e) {
console.error('Fetch error:', e);
container.innerHTML = 'p style="text-align:center; padding:20px;"์ฝํ
์ธ ๋ฅผ ๋ถ๋ฌ์ค๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค./p';
}
// ํฐ์คํ ๋ฆฌ ์ด๋ฏธ์ง ๊ฒฝ๋ก ์ต์ ํ ํจ์
function thumbUrlFix(url) {
if(url.includes('tistory.com/image')) return url;
if(url.includes('tistory.com/fname')) return url;
return url;
}
})();
/script
4. ์ค์ ์ ์ฉ ๋ฐ ์ฃผ์์ฌํญ
1) HTML ํธ์ง ๋ชจ๋ ํ์ฉ ํฐ์คํ ๋ฆฌ ๊ด๋ฆฌ์ ํ๋ฉด์ [์คํจ ํธ์ง] [html ํธ์ง]์ผ๋ก ๋ค์ด๊ฐ ์ํ๋ ์์น์ ์ฝ๋๋ฅผ ์ฝ์ ํ์ธ์.
2) ๋ชจ๋ฐ์ผ ๋ก๋ฉ ์๋ ์๋ฐ์คํฌ๋ฆฝํธ ํธ์ถ์ ๋ธ๋ผ์ฐ์ ์์์ ์๋ชจํฉ๋๋ค. async์ defer ์์ฑ์ ์ ์ ํ ํ์ฉํ๊ณ , ์ด๋ฏธ์ง๋ ๋ฐ๋์ loading="lazy" ์์ฑ์ ๋ถ์ฌํ์ฌ ์ด๊ธฐ ๋ก๋ฉ ์๋๋ฅผ ๋ฐฉํดํ์ง ์๋๋ก ํด์ผ ํฉ๋๋ค.
3) ์นดํ ๊ณ ๋ฆฌ ๊ฒฝ๋ก ํ์ธ ํฐ์คํ ๋ฆฌ ์คํจ๋ง๋ค ์นดํ ๊ณ ๋ฆฌ ์ฃผ์ ์ฒด๊ณ๊ฐ ๋ค๋ฅผ ์ ์์ต๋๋ค. ๋ณธ์ธ์ ๋ธ๋ก๊ทธ์์ ํน์ ์นดํ ๊ณ ๋ฆฌ๋ฅผ ํด๋ฆญํ์ ๋ ์ฃผ์์ฐฝ์ ๋จ๋ ๊ฒฝ๋ก(์: /category/example)๋ฅผ targetUrl ์์์ ์ ํํ ์ ๋ ฅํด์ผ ํฉ๋๋ค.