@youneed/ssr-plugin-canonical
v0.1.0
Published
SSR page middleware for @youneed: emit <link rel="canonical"> and hreflang alternates per page.
Readme
@youneed/ssr-plugin-canonical
<link rel="canonical"> + hreflang alternates as SSR page middleware for
@youneed/ssr.
By default every page gets a canonical link derived from the SSR origin + the
request path. Override or opt out per page via the canonical option (added to
PageOptions); declare hreflang variants via alternates.
import { ssr } from "@youneed/server-plugin-ssr";
import { canonical } from "@youneed/ssr-plugin-canonical";
class Pricing extends Page("/pricing", {
canonical: "/pricing", // string | false | (ctx) => string
alternates: [{ hreflang: "de", href: "/de/preise" }],
}) { /* … */ }
app.plugin(ssr({
origin: "https://example.com",
pages: [Pricing],
modules: [canonical({ trailingSlash: "strip" })],
}));Set auto: false to only emit canonical for pages that declare one.
Build
pnpm --filter @youneed/ssr-plugin-canonical run build