ddys-astro is the official Astro integration for the DDYS API. It injects Astro pages, API endpoints, server helpers, .astro components, a content loader, SEO routes, diagnostics, secure request-form handling, icons, and ready-to-copy examples.
npm install ddys-astroAdd the integration:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import ddys from 'ddys-astro';
export default defineConfig({
output: 'server',
integrations: [
ddys({
mountPath: '/ddys',
apiPrefix: '/api/ddys'
})
]
});output: 'server' is recommended when using injected DDYS endpoints and request forms.
DDYS_API_BASE_URL=https://ddys.io/api/v1
DDYS_SITE_BASE_URL=https://ddys.io
DDYS_API_KEY=
DDYS_FORM_SECRET=
DDYS_REQUEST_FORM_ENABLED=false
DDYS_DIAGNOSTICS_ENABLED=false
DDYS_REVALIDATE_TOKEN=Keep DDYS_API_KEY, DDYS_FORM_SECRET, and DDYS_REVALIDATE_TOKEN server-only. Do not expose them as public client variables.
- Uses the Astro Integration API and
astro:config:setup. - Injects pages under
/ddysby default. - Injects API endpoints under
/api/ddysby default. - Registers
Astro.locals.ddysthrough middleware. - Serves icons copied from the DDYS public icon set at
/ddys-astro/images. - Ships a content loader for Astro Content Collections.
- Ships SEO helpers for metadata, sitemap, robots, manifest, and Movie JSON-LD.
/ddys/ddys/latest/ddys/hot/ddys/movies/ddys/search/ddys/calendar/ddys/movie/[slug]/ddys/movie/[slug]/sources/ddys/collections/ddys/shares/ddys/types/ddys/genres/ddys/regions/ddys/request/ddys/diagnostics
GET /api/ddys/proxyGET /api/ddys/requestPOST /api/ddys/requestGET /api/ddys/diagnosticsPOST /api/ddys/diagnosticsPOST /api/ddys/revalidateGET /sitemap.xmlGET /robots.txtGET /manifest.webmanifest
The proxy uses an allow-list before mapping routes to the DDYS API.
---
import DdysView from 'ddys-astro/components/DdysView';
import DdysSearch from 'ddys-astro/components/DdysSearch';
import DdysRequestForm from 'ddys-astro/components/DdysRequestForm';
import 'ddys-astro/styles.css';
---
<DdysView view="latest" params={{ limit: 12 }} />
<DdysSearch />
<DdysRequestForm />Available components:
DdysViewDdysGridDdysCardDdysMovieDetailDdysSourcesDdysSearchDdysRequestFormDdysDiagnostics
import { createDdysServerClient } from 'ddys-astro/server';
const client = createDdysServerClient();
const latest = await client.latest({ limit: 12 });The client covers movies, latest, hot, search, suggest, calendar, movie, sources, related, comments, collections, collection, shares, share, requests, activities, user, types, genres, regions, me, createRequest, createComment, deleteComment, reportInvalidResource, follow, and unfollow.
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
import { createDdysContentLoader } from 'ddys-astro/content';
export const collections = {
ddys: defineCollection({
loader: createDdysContentLoader({ view: 'latest', limit: 50 }),
schema: z.object({
title: z.string().optional(),
slug: z.string().optional()
}).passthrough()
})
};Enable it only when an API key is configured:
DDYS_API_KEY=...
DDYS_FORM_SECRET=...
DDYS_REQUEST_FORM_ENABLED=trueThe form validates title, year, type, Douban ID, IMDb ID, honeypot field, CSRF token, and rate limits before calling the authenticated DDYS API.
pnpm typecheck
node tools/check.mjs
node --test tests/structure.test.mjs
pnpm build
pnpm pack --dry-run
powershell -ExecutionPolicy Bypass -File tools/build-package.ps1 -Version 0.1.0The source ZIP is generated at dist/ddys-astro-v0.1.0.zip.