RSS Implementation: Claude Code 활용 가이드
rss implementation: Claude Code 활용. 실용적인 팁과 코드 예시를 포함합니다.
RSSフィードでブ로그の読者獲得を加速する
RSSフィードを提供することで、ブ로그글の업데이트をRSSリーダーで購読してもらえます。Claude Code를 활용하면 RSS 2.0やAtomフィードの생성を短시간で구현할 수 있습니다。
기본적인RSSフィード생성
> ブ로그글のRSSフィードを생성する엔드포인트를 생성해줘。
> RSS 2.0形式で、最新20件の글を配信して。
// src/pages/rss.xml.ts
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import sanitizeHtml from 'sanitize-html';
import MarkdownIt from 'markdown-it';
const parser = new MarkdownIt();
export async function GET(context: { site: string }) {
const posts = await getCollection('blog');
const sortedPosts = posts
.filter(post => !post.data.draft)
.sort((a, b) =>
new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()
)
.slice(0, 20);
return rss({
title: 'My Tech Blog',
description: 'Web開発に関する技術ブログ',
site: context.site,
items: sortedPosts.map(post => ({
title: post.data.title,
pubDate: new Date(post.data.pubDate),
description: post.data.description,
link: `/blog/${post.slug}/`,
content: sanitizeHtml(parser.render(post.body), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
}),
categories: post.data.tags,
})),
customData: `<language>ja</language>`,
});
}
Atomフィードの구현
// src/pages/atom.xml.ts
import { getCollection } from 'astro:content';
export async function GET() {
const posts = await getCollection('blog');
const siteUrl = 'https://example.com';
const sortedPosts = posts
.filter(p => !p.data.draft)
.sort((a, b) =>
new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()
)
.slice(0, 20);
const atom = `<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>My Tech Blog</title>
<link href="${siteUrl}/atom.xml" rel="self"/>
<link href="${siteUrl}"/>
<id>${siteUrl}/</id>
<updated>${sortedPosts[0]?.data.pubDate ?? new Date().toISOString()}</updated>
${sortedPosts.map(post => ` <entry>
<title>${escapeXml(post.data.title)}</title>
<link href="${siteUrl}/blog/${post.slug}/"/>
<id>${siteUrl}/blog/${post.slug}/</id>
<published>${post.data.pubDate}</published>
<summary>${escapeXml(post.data.description)}</summary>
<category term="${post.data.tags?.[0] ?? ''}" />
</entry>`).join('\n')}
</feed>`;
return new Response(atom, {
headers: { 'Content-Type': 'application/atom+xml; charset=utf-8' },
});
}
function escapeXml(str: string): string {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
}
HTML헤더へのフィードリンク추가
<head>
<link rel="alternate" type="application/rss+xml"
title="RSS Feed" href="/rss.xml" />
<link rel="alternate" type="application/atom+xml"
title="Atom Feed" href="/atom.xml" />
</head>
카테고리別フィードの생성
// src/pages/rss/[category].xml.ts
import { getCollection } from 'astro:content';
export async function getStaticPaths() {
const posts = await getCollection('blog');
const categories = [...new Set(posts.map(p => p.data.category))];
return categories.map(category => ({
params: { category },
}));
}
export async function GET({ params, site }: { params: { category: string }; site: string }) {
const posts = await getCollection('blog');
const filtered = posts
.filter(p => p.data.category === params.category && !p.data.draft)
.sort((a, b) =>
new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()
);
// RSS생성ロジック(카테고리名を제목に含める)
return generateRss({
title: `My Tech Blog - ${params.category}`,
posts: filtered,
site,
});
}
フィードの유효성 검사
생성したRSSフィードが正しい形式か、W3C Feed Validation Service에서 확인할 수 있습니다.
> RSSフィードの유효성 검사테스트を書いて。
> XMLの構造とRSS 2.0仕様に準拠しているか확인して。
import { describe, it, expect } from 'vitest';
import { XMLParser } from 'fast-xml-parser';
describe('RSS Feed', () => {
it('有効なRSS 2.0形式であること', async () => {
const response = await fetch('http://localhost:4321/rss.xml');
const xml = await response.text();
const parser = new XMLParser();
const result = parser.parse(xml);
expect(result.rss).toBeDefined();
expect(result.rss.channel.title).toBeTruthy();
expect(result.rss.channel.item.length).toBeGreaterThan(0);
expect(result.rss.channel.item.length).toBeLessThanOrEqual(20);
});
});
정리
RSSフィードの구현は、ブ로그読者の獲得とリテンションに大きく貢献します。Claude Codeを활용すれば、SEO対策と組み合わせてサイトの発見性を高められます。サイトマップと一緒に빌드時に自動생성する설정を推奨します。フィードの仕様에 대해서는RSS 2.0 Specification를 참고하세요.
무료 PDF: 5분 완성 Claude Code 치트시트
이메일 주소만 등록하시면 A4 한 장짜리 치트시트 PDF를 즉시 보내드립니다.
개인정보는 엄격하게 관리하며 스팸은 보내지 않습니다.
이 글을 작성한 사람
Masa
Claude Code를 적극 활용하는 엔지니어. 10개 언어, 2,000페이지 이상의 테크 미디어 claudecode-lab.com을 운영 중.
관련 글
Claude Code 다국어 글을 매일 발행하기 전에 확인할 7가지
누락된 언어, 깨진 CTA, 반영되지 않은 배포를 막기 위해 다국어 Claude Code 글을 매일 발행하기 전에 확인할 체크리스트입니다.
Codex Automations란? 잠자는 동안 AI가 콘텐츠 운영을 처리하게 하는 방법
Codex Automations로 트래픽 분석, 주제 선정, 글 작성, CTA 개선, 배포까지 자동화하는 실전 가이드.
Claude Code × GCP Cloud Functions 완전 가이드 | 서버리스 함수 초고속 개발
Claude Code로 GCP Cloud Functions를 효율화. HTTP/Pub/Sub/Firestore 트리거 구현부터 로컬 테스트·배포 자동화까지, Masa의 실무 경험을 토대로 실제 코드로 해설.