ZH
测试版翻译

@core / site

1.1.2 ▾
已验证MIT
GitHub

站点设置、可编辑的多级菜单,以及防循环和开放重定向的重定向管理

代码10 个文件上下文约 583 个 token扫描通过

安装

$genpm add @core/site

你将获得

  • 源代码位于 src/lib/site/,共 10 个文件。 (19.7 kB)
  • AI 规则位于 src/lib/site/AGENTS.md,另附 IDE 规则文件。
  • 添加到 .env.example 的环境变量:SITE_URL, SITE_REDIRECT_HOSTS。
  • 自动为你解析 @core/content, @core/contracts, @core/db。

README

@core/site

genpm license

Site settings, editable nested menus and managed redirects with loop and open-redirect protection

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/site, pinned to a verified commit, and you own it.

Install

genpm add @core/site

No 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/site.

Or let your AI agent do it: run genpm mcp setup once, then ask "add @core/site 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

What every site has: settings (name, logo, contact, social profiles, legal page paths) as a @core/content singleton, editable menus up to 3 levels as a content collection (slug = location: header, footer), and redirects managed from the admin with loop detection, safe targets (site paths or https to allowed hosts) and hit counters. No page content, no SEO tags (@core/seo reads these settings).

Setup

After genpm add, follow these steps (your AI agent finds the same steps in src/lib/site/AGENTS.md and can do them for you):

  1. Env: SITE_URL (https://example.com), optional SITE_REDIRECT_HOSTS (comma-separated external hosts allowed as redirect targets). Migrations as in src/lib/db/AGENTS.md.
  2. Import this module once at startup (it registers the site_settings and menus content definitions).
  3. Seed initial values with seedEntry (@core/content): settings and the header/footer menus, using the site's current ones.
  4. Render: const settings = await getSiteSettings({ locale }), const items = await getMenu('header', { locale }).
  5. Redirects: Hono app.use(redirectMiddleware); Next.js middleware.ts with runtime: 'nodejs' calling redirectFor(req).
  6. Add ...siteAdminResources() to src/genpm/admin.ts.
  7. Verify: create a redirect /old → /new and request /old (301 to /new).

What's inside

Paths are relative to src/lib/site.

  • index.ts — public API: getSiteSettings, getMenu, upsertRedirect (by from), updateRedirect (by id), resolveRedirect, redirectResponse, siteAdminResources.
  • content.ts — siteSettings, menus and their schemas. redirects.ts — redirect logic. links.ts — link validation.
  • adapters/hono.ts — redirectMiddleware. adapters/next.ts — redirectFor(req).

At a glance

  • GenPM dependencies (installed with it): @core/db, @core/content, @core/contracts
  • npm dependencies (proposed, never installed without asking): zod
  • Environment variables (added to .env.example): SITE_URL, SITE_REDIRECT_HOSTS
  • AI rules: AGENTS.md, loaded by your agent only when it works in src/lib/site

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

MIT — see LICENSE. Browse the full catalog at genpm.net.

举报 @core/site

使用 GitHub 登录后才能举报包。