@dualmark/nextjs

中文文档
0.11.0发布于 2026/08/24Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 1.1万

Next.js App Router adapter for the Dualmark AEO framework. Drop-in proxy/middleware + route-handler factory + withDualmark() config wrapper. Same API surface as @dualmark/astro.

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Architecture
  4. Built-in converter names
  5. Why Next.js needs getEntries
  6. License

@dualmark/nextjs

Next.js App Router adapter for the Dualmark AEO framework.

Same one-line install as @dualmark/astro — withDualmark() for the config, createDualmarkMiddleware() for proxy.ts (or middleware.ts on Next ≤15), createDualmarkRouteHandler() for the markdown twin route handler, and createLlmsTxtHandler() for /llms.txt.

Install

bun add @dualmark/nextjs @dualmark/core @dualmark/converters

Usage

import { withDualmark } from "@dualmark/nextjs";

export default withDualmark(
  { reactStrictMode: true },
  {
    siteUrl: "https://example.com",
    collections: {
      blog: {
        converter: "blog",
        getEntries: () => yourPosts,
      },
    },
    llmsTxt: {
      enabled: true,
      brandName: "Acme",
      sections: [{ title: "Pages", links: [{ title: "Home", href: "/" }] }],
    },
  },
);
import { createDualmarkMiddleware } from "@dualmark/nextjs";

const middleware = createDualmarkMiddleware({
  siteUrl: "https://example.com",
});

export default middleware;
export const config = middleware.config;

On Next.js ≤15, name the file middleware.ts instead. The body is identical.

import { createDualmarkRouteHandler } from "@dualmark/nextjs";
import { POSTS } from "@/lib/posts";

const handler = createDualmarkRouteHandler({
  siteUrl: "https://example.com",
  collections: {
    blog: {
      converter: "blog",
      getEntries: () => POSTS,
    },
  },
  staticPages: [{ pattern: "/", render: () => "# Home\n\nWelcome." }],
});

export const GET = handler.GET;
export const generateStaticParams = handler.generateStaticParams;
export const dynamic = "force-static";
import { createLlmsTxtHandler } from "@dualmark/nextjs";

const handler = createLlmsTxtHandler({
  brandName: "Acme",
  sections: [{ title: "Pages", links: [{ title: "Home", href: "/" }] }],
});

export const GET = handler.GET;
export const dynamic = "force-static";

Architecture

┌─────────────────────────────────────────────────────────────┐
│ proxy.ts                                                    │
│   - if path ends in .md     → rewrite to /md/<path>        │
│   - if AI bot UA OR Accept: text/markdown                   │
│       → rewrite to /md/<path>                               │
│   - if Accept rules out html+md → 406                       │
│   - else (HTML) → next() + Link rel=alternate header        │
└─────────────────────────────────────────────────────────────┘

app/
├── ...your existing pages
├── md/[...path]/route.ts   ← createDualmarkRouteHandler (renders .md)
└── llms.txt/route.ts       ← createLlmsTxtHandler (renders /llms.txt)

/md/... is an internal namespace your users never see — the proxy rewrites to it, and the route handler dispatches to your collections, static pages, or parameterized routes. Configurable via internalNamespace if you need a different name.

Built-in converter names

blog, case-study, changelog, compare, docs, feature, glossary, legal, pricing, pseo, status-page, tool, video. Pass any of them as converter, or pass a function (entry) => string for custom output.

Why Next.js needs getEntries

Astro has astro:content to discover collection entries automatically. Next.js has no equivalent — content can come from the filesystem, a CMS, a database, anything. So you supply getEntries: () => Entry[] | Promise<Entry[]> and the adapter does the rest.

License

Apache 2.0

版本与发布记录

@dualmark/nextjs 共发布 7 个版本,首次发布于 2026/05/07;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.11.0latest2026/08/242 个月前
0.10.02026/06/184 个月前
0.8.02026/05/305 个月前
0.7.02026/05/215 个月前
0.5.22026/05/126 个月前
0.5.12026/05/106 个月前

关于 @dualmark/nextjs 的常见问题

@dualmark/nextjs 是什么?

Next.js App Router adapter for the Dualmark AEO framework. Drop-in proxy/middleware + route-handler factory + withDualmark() config wrapper. Same API surface as @dualmark/astro.

如何安装 @dualmark/nextjs?

在项目目录运行 npm install @dualmark/nextjs,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=14.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dualmark/nextjs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dualmark/nextjs 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dualmark/nextjs 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dualmark/nextjs 可以商用吗?

@dualmark/nextjs 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dualmark/nextjs 的下载量有多少?

根据 npm 官方下载统计,@dualmark/nextjs 在 2026/10/13 – 2026/11/11 这 30 天内被下载 11,027 次,日均约 368 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dualmark/nextjs 还在维护吗?

最新版本 0.11.0 发布于 2026/08/24(2 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/05/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。