@core/content 上のブログ:記事、著者、カテゴリ、タグ、シリーズ、関連記事、アーカイブ、RSS/Atom/JSON フィード
インストール
genpm add @core/blog含まれるもの
- src/lib/blog/ にソースコード(7 ファイル)。 (20.5 KB)
- src/lib/blog/AGENTS.md に AI ルール、加えて IDE 用のルールファイル。
- .env.example に追加される環境変数: SITE_URL。
- @core/content, @core/contracts, @core/db, @core/rich-text を自動で解決します。
README
@core/blog
Blog domain on @core/content: posts, authors, categories, tags, series, related posts, archive and RSS/Atom/JSON feeds
A GenPM module: source code + AI rules + MCP config, injected into your project instead of hidden in node_modules. The code lands in src/lib/blog, pinned to a verified commit, and you own it.
Install
genpm add @core/blogNo genpm yet? curl -fsSL https://genpm.net/install.sh | sh (macOS/Linux), irm https://genpm.net/install.ps1 | iex (Windows), or one-off with npx @genpm-net/cli add @core/blog.
Or let your AI agent do it: run genpm mcp setup once, then ask "add @core/blog with genpm" in Claude Code, Cursor, VS Code, Windsurf, Codex or Gemini CLI. It shows you a dry-run plan before writing anything.
What it does
Blog domain built only from @core/content collections (posts, authors, categories, tags, series; no tables of
its own): filtered and paginated listings, a post with its relations resolved, related posts, monthly archive, series
order, RSS 2.0 / Atom / JSON Feed, sitemap and search sources and admin resources. No routes or templates (those
come from the app or @core/kit-blog), no comments or newsletter (separate modules).
Setup
After genpm add, follow these steps (your AI agent finds the same steps in src/lib/blog/AGENTS.md and can do them for you):
- Import this module at startup (it registers the collections) and set
SITE_URL. - Routes (Next.js example):
/blog→listPosts({ page, locale });/blog/[slug]→getPost(slug, { locale, draft })(404 when null) +relatedPosts(post);/blog/category/[slug]→listPosts({ category }); same fortag,author,series. - Feeds:
/blog/feed.xml→rssFeed({ title, description })(application/rss+xml),/blog/atom.xml,/blog/feed.json. - Register
blogSitemapSource()insrc/genpm/seo.ts(it includes/blog; pass{ index: false }or another path if the blog index lives elsewhere),blogSearchSource()insrc/genpm/search.tsand...blogAdminResources()insrc/genpm/admin.ts. - Render the body with
<RichText doc={post.data.body} />(@core/rich-text) and addjsonLd.article(...)(@core/seo). - Verify: publish a post, it appears in
/blog, the feed and the sitemap; a scheduled post does not.
What's inside
Paths are relative to src/lib/blog.
index.ts— public API:listPosts,getPost,relatedPosts,archive,postsInMonth,rssFeed,atomFeed,jsonFeed,blogSitemapSource,blogSearchSource,blogAdminResources.collections.ts— schemas (PostSchemausesRichTextSchema).posts.ts— reads.feeds.ts— feeds.sources.ts— sitemap/search/admin.
At a glance
- GenPM dependencies (installed with it): @core/content, @core/rich-text, @core/contracts, @core/db
- npm dependencies (proposed, never installed without asking):
zod - Environment variables (added to
.env.example):SITE_URL - AI rules:
AGENTS.md, loaded by your agent only when it works insrc/lib/blog
Security
GenPM installs a 40-character commit SHA (never a branch), verifies an Ed25519-signed manifest, never runs install scripts and scans AI rules for prompt injection. Details: genpm.net/docs/security.
License
これは AI が src/lib/blog で作業するときに読む内容そのものです。それ以外はコンテキストに追加されません。
@core/blog — rules for AI agents
Purpose
Blog domain built only from @core/content collections (posts, authors, categories, tags, series; no tables of
its own): filtered and paginated listings, a post with its relations resolved, related posts, monthly archive, series
order, RSS 2.0 / Atom / JSON Feed, sitemap and search sources and admin resources. No routes or templates (those
come from the app or @core/kit-blog), no comments or newsletter (separate modules).
Map
index.ts— public API:listPosts,getPost,relatedPosts,archive,postsInMonth,rssFeed,atomFeed,jsonFeed,blogSitemapSource,blogSearchSource,blogAdminResources.collections.ts— schemas (PostSchemausesRichTextSchema).posts.ts— reads.feeds.ts— feeds.sources.ts— sitemap/search/admin.
Integration
- Import this module at startup (it registers the collections) and set
SITE_URL. - Routes (Next.js example):
/blog→listPosts({ page, locale });/blog/[slug]→getPost(slug, { locale, draft })(404 when null) +relatedPosts(post);/blog/category/[slug]→listPosts({ category }); same fortag,author,series. - Feeds:
/blog/feed.xml→rssFeed({ title, description })(application/rss+xml),/blog/atom.xml,/blog/feed.json. - Register
blogSitemapSource()insrc/genpm/seo.ts(it includes/blog; pass{ index: false }or another path if the blog index lives elsewhere),blogSearchSource()insrc/genpm/search.tsand...blogAdminResources()insrc/genpm/admin.ts. - Render the body with
<RichText doc={post.data.body} />(@core/rich-text) and addjsonLd.article(...)(@core/seo). - Verify: publish a post, it appears in
/blog, the feed and the sitemap; a scheduled post does not.
Conventions
- Relations are slugs: create the author/category/tag entries with the same slug.
membersOnlyposts: the page must hide the body unless the user is entitled; feeds and search only expose the excerpt.- Paths default to
/blog/<slug>; pass your ownpath/postPathif the blog lives elsewhere.
Don't
- Don't query
content_entriesdirectly for posts; uselistPosts(it respects publication and locale fallback). - Don't put the full body of members-only posts in feeds, search or meta descriptions.
# @core/blog — rules for AI agents
## Purpose
Blog domain built only from @core/content collections (`posts`, `authors`, `categories`, `tags`, `series`; no tables of
its own): filtered and paginated listings, a post with its relations resolved, related posts, monthly archive, series
order, RSS 2.0 / Atom / JSON Feed, sitemap and search sources and admin resources. No routes or templates (those
come from the app or @core/kit-blog), no comments or newsletter (separate modules).
## Map
- `index.ts` — public API: `listPosts`, `getPost`, `relatedPosts`, `archive`, `postsInMonth`, `rssFeed`, `atomFeed`, `jsonFeed`, `blogSitemapSource`, `blogSearchSource`, `blogAdminResources`.
- `collections.ts` — schemas (`PostSchema` uses `RichTextSchema`). `posts.ts` — reads. `feeds.ts` — feeds. `sources.ts` — sitemap/search/admin.
## Integration
1. Import this module at startup (it registers the collections) and set `SITE_URL`.
2. Routes (Next.js example): `/blog` → `listPosts({ page, locale })`; `/blog/[slug]` → `getPost(slug, { locale, draft })`
(404 when null) + `relatedPosts(post)`; `/blog/category/[slug]` → `listPosts({ category })`; same for `tag`, `author`, `series`.
3. Feeds: `/blog/feed.xml` → `rssFeed({ title, description })` (`application/rss+xml`), `/blog/atom.xml`, `/blog/feed.json`.
4. Register `blogSitemapSource()` in `src/genpm/seo.ts` (it includes `/blog`; pass `{ index: false }` or another path
if the blog index lives elsewhere), `blogSearchSource()` in `src/genpm/search.ts` and `...blogAdminResources()` in `src/genpm/admin.ts`.
5. Render the body with `<RichText doc={post.data.body} />` (@core/rich-text) and add `jsonLd.article(...)` (@core/seo).
6. Verify: publish a post, it appears in `/blog`, the feed and the sitemap; a scheduled post does not.
## Conventions
- Relations are slugs: create the author/category/tag entries with the same slug.
- `membersOnly` posts: the page must hide the body unless the user is entitled; feeds and search only expose the excerpt.
- Paths default to `/blog/<slug>`; pass your own `path`/`postPath` if the blog lives elsewhere.
## Don't
- Don't query `content_entries` directly for posts; use `listPosts` (it respects publication and locale fallback).
- Don't put the full body of members-only posts in feeds, search or meta descriptions.
.genpmignore 適用後に組み込まれる正確なツリーです。固定先:
// Feeds RSS 2.0, Atom 1.0 y JSON Feed 1.1 con los últimos posts publicados (nunca borradores ni programados).
import { getEntry, listEntries } from '../content/index.ts';
import { type RenderOptions, toHtml } from '../rich-text/index.ts';
import type { AuthorData, PostData } from './collections.ts';
import { summarize } from './posts.ts';
export type FeedOptions = {
/** Origen https del sitio (por defecto SITE_URL). */
siteUrl?: string;
title: string;
description?: string;
/** Ruta del blog y de cada post. */
blogPath?: string;
postPath?: (slug: string) => string;
locale?: string;
limit?: number;
/** Incluir el contenido completo (si no, solo el extracto). Los posts `membersOnly` siempre van solo con extracto. */
fullContent?: boolean;
render?: RenderOptions;
};
const xml = (s: string) => s.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
async function items(o: FeedOptions) {
const base = new URL(o.siteUrl ?? process.env.SITE_URL ?? '');
const path = o.postPath ?? ((s: string) => `${o.blogPath ?? '/blog'}/${s}`);
const entries = await listEntries<PostData>('posts', { locale: o.locale, orderBy: '-publishedAt', limit: Math.min(o.limit ?? 20, 100) });
const out = [];
for (const e of entries) {
const s = summarize(e);
const names: string[] = [];
for (const a of s.authors) names.push((await getEntry<AuthorData>('authors', a))?.data.name ?? a);
out.push({
...s,
url: new URL(path(s.slug), base).toString(),
html: o.fullContent && !s.membersOnly ? toHtml(e.data.body, o.render) : `<p>${xml(s.excerpt)}</p>`,
authorNames: names,
});
}
return { base, items: out, home: new URL(o.blogPath ?? '/blog', base).toString() };
}
export async function rssFeed(o: FeedOptions): Promise<string> {
const { items: list, home } = await items(o);
const body = list
.map(
(i) =>
`<item><title>${xml(i.title)}</title><link>${xml(i.url)}</link><guid isPermaLink="true">${xml(i.url)}</guid>${i.publishedAt ? `<pubDate>${i.publishedAt.toUTCString()}</pubDate>` : ''}<description>${xml(i.excerpt)}</description>${o.fullContent ? `<content:encoded>${xml(i.html)}</content:encoded>` : ''}${i.categories.map((c) => `<category>${xml(c)}</category>`).join('')}</item>`,
)
.join('');
return `<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>${xml(o.title)}</title><link>${xml(home)}</link><description>${xml(o.description ?? o.title)}</description>${o.locale ? `<language>${xml(o.locale)}</language>` : ''}<atom:link href="${xml(`${home}/feed.xml`)}" rel="self" type="application/rss+xml"/>${body}</channel></rss>`;
}
export async function atomFeed(o: FeedOptions): Promise<string> {
const { items: list, home } = await items(o);
const updated = (list[0]?.updatedAt ?? new Date(0)).toISOString();
const body = list
.map(
(i) =>
`<entry><title>${xml(i.title)}</title><link href="${xml(i.url)}"/><id>${xml(i.url)}</id>${i.publishedAt ? `<published>${i.publishedAt.toISOString()}</published>` : ''}<updated>${i.updatedAt.toISOString()}</updated>${i.authorNames.map((n) => `<author><name>${xml(n)}</name></author>`).join('')}<summary>${xml(i.excerpt)}</summary>${o.fullContent ? `<content type="html">${xml(i.html)}</content>` : ''}</entry>`,
)
.join('');
return `<?xml version="1.0" encoding="UTF-8"?>\n<feed xmlns="http://www.w3.org/2005/Atom"${o.locale ? ` xml:lang="${xml(o.locale)}"` : ''}><title>${xml(o.title)}</title><link href="${xml(home)}"/><link rel="self" href="${xml(`${home}/atom.xml`)}"/><id>${xml(home)}</id><updated>${updated}</updated>${body}</feed>`;
}
export async function jsonFeed(o: FeedOptions): Promise<string> {
const { items: list, home } = await items(o);
return JSON.stringify({
version: 'https://jsonfeed.org/version/1.1',
title: o.title,
home_page_url: home,
feed_url: `${home}/feed.json`,
...(o.description && { description: o.description }),
...(o.locale && { language: o.locale }),
items: list.map((i) => ({
id: i.url,
url: i.url,
title: i.title,
summary: i.excerpt,
...(o.fullContent ? { content_html: i.html } : {}),
...(i.publishedAt && { date_published: i.publishedAt.toISOString() }),
date_modified: i.updatedAt.toISOString(),
...(i.authorNames.length && { authors: i.authorNames.map((name) => ({ name })) }),
tags: i.tags,
})),
});
}
このパッケージは MCP サーバーを宣言していません。
- npm
- zod ^4.0.0
- 提案
- GenPM は npm コマンドを提案し、あなたが承認した場合にのみ実行します。
- 利用元(1)
- @core/kit-blog ^1.0.0
- スキャン
- スキャン合格 · 指摘 0 件
- コミット
- v1.1.1 → 892ac5f6cda85a2adbbdd057939befaf37d56ee9 · 取得後に検証済み
- スクリプト
- なし。GenPM はパッケージのコードを実行しません。
- ライセンス
- MIT
- 品質
- 100/100
- 認識されたライセンス達成
- AGENTS.md に目的の説明がある達成
- AGENTS.md に統合手順がある達成
- AGENTS.md に規約や禁止事項がある達成
- テストを含む達成
- セキュリティスキャンに合格達成
- 過去 6 か月以内に公開達成
- 認証済みの公開者達成
- 概要とキーワード達成
- 報告
- 問題を見つけましたか?