@devalon.dev/credits 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -2
- package/dist/chunk-QU6SEFG7.mjs +16 -0
- package/dist/chunk-SHIXBOQB.mjs +1 -0
- package/dist/chunk-YF7SVQTC.mjs +11 -0
- package/dist/core/agent-files.d.ts +46 -0
- package/dist/core/alternates.d.ts +4 -0
- package/dist/core/backlink.d.ts +24 -0
- package/dist/core/escape.d.ts +2 -0
- package/dist/core/headers.d.ts +34 -0
- package/dist/core/html.d.ts +27 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/json-ld.d.ts +11 -0
- package/dist/core/url.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/next/agent-files.d.ts +2 -0
- package/dist/next/alternates.d.ts +4 -0
- package/dist/next/backlink.d.ts +5 -0
- package/dist/next/headers.d.ts +2 -0
- package/dist/next/index.d.ts +10 -0
- package/dist/next/index.js +16 -0
- package/dist/next/index.mjs +1 -0
- package/dist/next/json-ld.d.ts +5 -0
- package/dist/next/schema.d.ts +1 -0
- package/dist/next/types.d.ts +1 -0
- package/dist/react/agent-files.d.ts +2 -0
- package/dist/react/alternates.d.ts +5 -0
- package/dist/react/backlink.d.ts +5 -0
- package/dist/react/headers.d.ts +2 -0
- package/dist/react/html.d.ts +2 -0
- package/dist/react/index.d.ts +14 -0
- package/dist/react/index.js +26 -0
- package/dist/react/index.mjs +1 -0
- package/dist/react/json-ld.d.ts +5 -0
- package/dist/react/schema.d.ts +1 -0
- package/dist/react/types.d.ts +1 -0
- package/dist/schema.d.ts +1183 -0
- package/dist/types.d.ts +75 -0
- package/dist/vite/index.d.ts +2 -0
- package/dist/vite/index.js +32 -0
- package/dist/vite/index.mjs +7 -0
- package/dist/vite/plugin.d.ts +51 -0
- package/docs/nextjs/01-app-router.md +101 -0
- package/docs/nextjs/02-app-router-i18n.md +166 -0
- package/docs/nextjs/03-pages-router.md +127 -0
- package/docs/nextjs/04-metadata-and-csp.md +113 -0
- package/docs/nextjs/05-performance-checklist.md +67 -0
- package/docs/nextjs/06-backlink-component.md +203 -0
- package/docs/nextjs/07-validator.md +55 -0
- package/docs/nextjs/08-server-headers.md +122 -0
- package/docs/nextjs/09-llms-and-humans-txt.md +163 -0
- package/docs/react/01-ssr-setup.md +112 -0
- package/docs/react/02-csr-vite.md +116 -0
- package/docs/react/03-i18n.md +104 -0
- package/docs/react/04-metadata-and-csp.md +105 -0
- package/docs/react/05-backlink-component.md +89 -0
- package/docs/react/06-server-headers.md +150 -0
- package/docs/react/07-agent-files.md +136 -0
- package/docs/react/08-validator.md +56 -0
- package/docs/react/09-performance-checklist.md +76 -0
- package/package.json +71 -4
- package/scripts/check-devalon-credits.mjs +175 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# 02 — App Router with 3 languages (ro / ru / en)
|
|
2
|
+
|
|
3
|
+
**When to read this:** the client site serves the same project in multiple languages.
|
|
4
|
+
|
|
5
|
+
## The one rule
|
|
6
|
+
|
|
7
|
+
`site_url` and `site_name` are the **same for every language**. Only `in_language` and `page_url` change.
|
|
8
|
+
|
|
9
|
+
| Prop | `/ro` | `/ru` | `/en` |
|
|
10
|
+
| --- | --- | --- | --- |
|
|
11
|
+
| `site_url` | `https://example.com` | `https://example.com` | `https://example.com` |
|
|
12
|
+
| `site_name` | `Example Inc.` | `Example Inc.` | `Example Inc.` |
|
|
13
|
+
| `in_language` | `"ro"` | `"ru"` | `"en"` |
|
|
14
|
+
| `page_url` | `https://example.com/ro` | `https://example.com/ru` | `https://example.com/en` |
|
|
15
|
+
| `services` / `contributions` | same | same | same |
|
|
16
|
+
|
|
17
|
+
Why `site_url` must stay fixed: it identifies the client project. Changing it per language would split one project into three separate identities in the eyes of search engines. The translated names/descriptions of the services are chosen automatically from `in_language`, so you never write them three times.
|
|
18
|
+
|
|
19
|
+
Both Next.js components accept all 7 `devalon_locale` values (`en`, `ro`, `ru`, `de`, `da`, `fr`, `es`); your site can expose any subset of them. `DevalonBacklink` uses `locale` to pick a built-in sentence in the same 7 languages — see [06 — Backlink component](06-backlink-component.md).
|
|
20
|
+
|
|
21
|
+
## Step 1 — type guard for your locales
|
|
22
|
+
|
|
23
|
+
`in_language` accepts 7 languages, but your site has 3. The value from the URL is a plain `string`, so narrow it once:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// lib/i18n.ts
|
|
27
|
+
export const locales = ["ro", "ru", "en"] as const;
|
|
28
|
+
export type Locale = (typeof locales)[number];
|
|
29
|
+
|
|
30
|
+
export function isLocale(value: string): value is Locale {
|
|
31
|
+
return (locales as readonly string[]).includes(value);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`Locale` is a subset of the accepted languages, so it can be passed to `in_language` directly with no cast.
|
|
36
|
+
|
|
37
|
+
## Step 2 — make `[locale]` the root layout
|
|
38
|
+
|
|
39
|
+
For native Next.js i18n the cleanest setup is to have **no** `app/layout.tsx`. The `<html>` lives in `app/[locale]/layout.tsx`:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
app/
|
|
43
|
+
[locale]/
|
|
44
|
+
layout.tsx <- <html>, <body>, <DevalonJsonLd>, metadata
|
|
45
|
+
page.tsx
|
|
46
|
+
...
|
|
47
|
+
lib/
|
|
48
|
+
i18n.ts
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If you already have `app/layout.tsx` with `<html>`/`<body>`, keep it and just render `<DevalonJsonLd>` (no html tags) inside `app/[locale]/layout.tsx`. Both work.
|
|
52
|
+
|
|
53
|
+
## Step 3 — the complete layout
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
// app/[locale]/layout.tsx
|
|
57
|
+
import type { Metadata } from "next";
|
|
58
|
+
import { notFound } from "next/navigation";
|
|
59
|
+
import {
|
|
60
|
+
DevalonJsonLd,
|
|
61
|
+
build_devalon_alternates_metadata,
|
|
62
|
+
} from "@devalon.dev/credits/next";
|
|
63
|
+
import { isLocale } from "@/lib/i18n";
|
|
64
|
+
|
|
65
|
+
const SITE_URL = "https://example.com";
|
|
66
|
+
const SITE_NAME = "Example Inc.";
|
|
67
|
+
|
|
68
|
+
type Props = {
|
|
69
|
+
params: Promise<{ locale: string }>; // Next 15+: params is a Promise
|
|
70
|
+
children: React.ReactNode;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export function generateStaticParams() {
|
|
74
|
+
return ["ro", "ru", "en"].map((locale) => ({ locale }));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
78
|
+
const { locale } = await params;
|
|
79
|
+
if (!isLocale(locale)) notFound();
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
alternates: build_devalon_alternates_metadata({
|
|
83
|
+
canonical: `${SITE_URL}/${locale}`,
|
|
84
|
+
pages: {
|
|
85
|
+
ro: `${SITE_URL}/ro`,
|
|
86
|
+
ru: `${SITE_URL}/ru`,
|
|
87
|
+
en: `${SITE_URL}/en`,
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default async function LocaleLayout({ params, children }: Props) {
|
|
94
|
+
const { locale } = await params;
|
|
95
|
+
if (!isLocale(locale)) notFound();
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<html lang={locale}>
|
|
99
|
+
<body>
|
|
100
|
+
{children}
|
|
101
|
+
|
|
102
|
+
<DevalonJsonLd
|
|
103
|
+
site_url={SITE_URL}
|
|
104
|
+
site_name={SITE_NAME}
|
|
105
|
+
in_language={locale}
|
|
106
|
+
page_url={`${SITE_URL}/${locale}`}
|
|
107
|
+
services={["web_development", "ai_agents_automation"]}
|
|
108
|
+
contributions={["developing", "maintaining"]}
|
|
109
|
+
/>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`generateStaticParams()` prebuilds all 3 languages: the JSON-LD is baked into static HTML at build time and served from cache. `notFound()` on an invalid locale keeps a bad URL from producing an attribution with a wrong `inLanguage`.
|
|
117
|
+
|
|
118
|
+
## Nested pages and hreflang
|
|
119
|
+
|
|
120
|
+
For a nested route such as `/ro/servicii`, pass the real page URL as `page_url`, for example from `app/[locale]/servicii/page.tsx`:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
<DevalonJsonLd
|
|
124
|
+
site_url={SITE_URL}
|
|
125
|
+
site_name={SITE_NAME}
|
|
126
|
+
in_language={locale}
|
|
127
|
+
page_url={`${SITE_URL}/${locale}/servicii`}
|
|
128
|
+
services={["web_development"]}
|
|
129
|
+
contributions={["developing"]}
|
|
130
|
+
/>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If you do this in the page, **remove** the component from the layout for that route — one component per final URL. In `generateMetadata` of that page, keep the same `pages` map so hreflang points to the translated equivalents of that page, not the homepage.
|
|
134
|
+
|
|
135
|
+
## Common mistakes
|
|
136
|
+
|
|
137
|
+
| Don't | Do |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| Change `site_url` to `https://example.com/ro` per language. | Keep `site_url` at the root; change only `page_url` and `in_language`. |
|
|
140
|
+
| Render the component in the layout and again in the page. | Render it once for that URL. |
|
|
141
|
+
| Forget to `await params`. | `const { locale } = await params;` in Next 15+. |
|
|
142
|
+
| Pass the raw `string` from params to `in_language` with `as any`. | Use the `isLocale` type guard and `notFound()`. |
|
|
143
|
+
| Hand-write the `<link rel="alternate" hreflang>` tags. | Use `build_devalon_alternates_metadata()`. |
|
|
144
|
+
| Read `cookies()` in the locale layout to detect language. | Use the URL segment (`[locale]`); it keeps the page static. |
|
|
145
|
+
|
|
146
|
+
## Using next-intl or a similar plugin
|
|
147
|
+
|
|
148
|
+
Same pattern. Get the locale from the plugin's `params` in the server layout, validate it with `isLocale`, and pass it as `in_language`. Do not use a client-side `useLocale()` hook here — it would force you into a Client Component.
|
|
149
|
+
|
|
150
|
+
## Verify
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
yarn build
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Check all 3 rendered pages:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
for l in ro ru en; do
|
|
160
|
+
echo "--- $l"
|
|
161
|
+
curl -s "http://localhost:3000/$l" | grep -o '"inLanguage":"[a-z]*"'
|
|
162
|
+
curl -s "http://localhost:3000/$l" | grep -o 'hreflang="[a-z]*"'
|
|
163
|
+
done
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Expect one `inLanguage` per page matching its URL, and `hreflang` links for `ro`, `ru`, `en` on each page.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# 03 — Pages Router
|
|
2
|
+
|
|
3
|
+
**When to read this:** you use `pages/` instead of `app/`.
|
|
4
|
+
|
|
5
|
+
The React component is a Server Component and is not available here. Instead, build the data with `build_devalon_json_ld()` and put it into a `<script>` yourself.
|
|
6
|
+
|
|
7
|
+
## Step 1 — a safe serializer (copy this once)
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// lib/devalon-json-ld.ts
|
|
11
|
+
export function serializeDevalonJsonLd(value: unknown): string {
|
|
12
|
+
const json = JSON.stringify(value);
|
|
13
|
+
if (json === undefined) throw new TypeError("Devalon JSON-LD could not be serialized.");
|
|
14
|
+
|
|
15
|
+
return json
|
|
16
|
+
.replace(/</g, "\\u003c")
|
|
17
|
+
.replace(/>/g, "\\u003e")
|
|
18
|
+
.replace(/&/g, "\\u0026")
|
|
19
|
+
.replace(/\u2028/g, "\\u2028")
|
|
20
|
+
.replace(/\u2029/g, "\\u2029");
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The escaping is not cosmetic: it prevents a value containing `</script>` from closing the tag early. Never use raw `JSON.stringify()` here.
|
|
25
|
+
|
|
26
|
+
## Step 2 — site-wide attribution in `_document.tsx`
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
// pages/_document.tsx
|
|
30
|
+
import Document, { Html, Head, Main, NextScript } from "next/document";
|
|
31
|
+
import { build_devalon_json_ld } from "@devalon.dev/credits/next";
|
|
32
|
+
import { serializeDevalonJsonLd } from "@/lib/devalon-json-ld";
|
|
33
|
+
|
|
34
|
+
const jsonLd = serializeDevalonJsonLd(
|
|
35
|
+
build_devalon_json_ld({
|
|
36
|
+
site_url: "https://example.com",
|
|
37
|
+
site_name: "Example Inc.",
|
|
38
|
+
in_language: "en",
|
|
39
|
+
page_url: "https://example.com/",
|
|
40
|
+
services: ["web_development"],
|
|
41
|
+
contributions: ["developing", "maintaining"],
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export default class MyDocument extends Document {
|
|
46
|
+
render() {
|
|
47
|
+
return (
|
|
48
|
+
<Html lang="en">
|
|
49
|
+
<Head>
|
|
50
|
+
<script
|
|
51
|
+
type="application/ld+json"
|
|
52
|
+
dangerouslySetInnerHTML={{ __html: jsonLd }}
|
|
53
|
+
/>
|
|
54
|
+
</Head>
|
|
55
|
+
<body>
|
|
56
|
+
<Main />
|
|
57
|
+
<NextScript />
|
|
58
|
+
</body>
|
|
59
|
+
</Html>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Computing `jsonLd` at module scope means it is built **once** and reused for every request — good for performance. Only do this when the values are the same for every page.
|
|
66
|
+
|
|
67
|
+
## Step 3 — per-page attribution
|
|
68
|
+
|
|
69
|
+
For a single page (or when values depend on `router.query`/locale), use `next/head` in that page:
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
// pages/servicii.tsx
|
|
73
|
+
import Head from "next/head";
|
|
74
|
+
import { build_devalon_json_ld } from "@devalon.dev/credits/next";
|
|
75
|
+
import { serializeDevalonJsonLd } from "@/lib/devalon-json-ld";
|
|
76
|
+
|
|
77
|
+
export default function ServicesPage() {
|
|
78
|
+
const jsonLd = serializeDevalonJsonLd(
|
|
79
|
+
build_devalon_json_ld({
|
|
80
|
+
site_url: "https://example.com",
|
|
81
|
+
site_name: "Example Inc.",
|
|
82
|
+
in_language: "ro",
|
|
83
|
+
page_url: "https://example.com/servicii",
|
|
84
|
+
services: ["web_development"],
|
|
85
|
+
contributions: ["developing"],
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<Head>
|
|
92
|
+
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: jsonLd }} />
|
|
93
|
+
</Head>
|
|
94
|
+
<main>...</main>
|
|
95
|
+
</>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
For static pages, compute the string outside the component (or in `getStaticProps`) so it happens at build time instead of on every render.
|
|
101
|
+
|
|
102
|
+
## Multi-language Pages Router
|
|
103
|
+
|
|
104
|
+
Use `next-i18next` / `next-intl` routing as usual, and pass the active locale:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
in_language: locale as devalon_locale, // validate against ["ro", "ru", "en"] first
|
|
108
|
+
page_url: `https://example.com/${locale}${pathname}`,
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Keep `site_url` fixed at the root for all languages. If you render in `_document`, you cannot read the page locale there — use per-page `<Head>` instead, or generate one document variant per locale.
|
|
112
|
+
|
|
113
|
+
## Performance rules
|
|
114
|
+
|
|
115
|
+
- Build the JSON once at module scope or in `getStaticProps`; do not rebuild it on every request.
|
|
116
|
+
- Keep it in the initial HTML. **Never** inject it with `useEffect` / `document.createElement("script")` — crawlers may miss it and you add client JS for nothing.
|
|
117
|
+
- Do not import `DevalonJsonLd` in a Pages Router app; it is an App Router component.
|
|
118
|
+
- Avoid `getServerSideProps` just for this data. Static generation is enough and much cheaper.
|
|
119
|
+
|
|
120
|
+
## Verify
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
yarn build
|
|
124
|
+
curl -s http://localhost:3000/ | grep -o 'application/ld+json'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Exactly one match, and the script content must be present in the raw HTML (view source, not DevTools DOM after JS runs).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# 04 — Metadata (hreflang) and CSP nonce
|
|
2
|
+
|
|
3
|
+
**When to read this:** you want canonical/hreflang links alongside the attribution, or your site has a strict `Content-Security-Policy`.
|
|
4
|
+
|
|
5
|
+
## hreflang / canonical (App Router)
|
|
6
|
+
|
|
7
|
+
`build_devalon_alternates_metadata()` returns a ready-to-use `Metadata["alternates"]` value:
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
// app/[locale]/layout.tsx
|
|
11
|
+
import type { Metadata } from "next";
|
|
12
|
+
import { build_devalon_alternates_metadata } from "@devalon.dev/credits/next";
|
|
13
|
+
|
|
14
|
+
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise<Metadata> {
|
|
15
|
+
const { locale } = await params;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
alternates: build_devalon_alternates_metadata({
|
|
19
|
+
canonical: `https://example.com/${locale}`,
|
|
20
|
+
pages: {
|
|
21
|
+
ro: "https://example.com/ro",
|
|
22
|
+
ru: "https://example.com/ru",
|
|
23
|
+
en: "https://example.com/en",
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Next.js renders the canonical and `hreflang` link tags for you. Do not hand-write them in `<Head>` as well — that duplicates the tags.
|
|
31
|
+
|
|
32
|
+
For a nested page, call it in that page's `generateMetadata` with the translated URLs of that same page.
|
|
33
|
+
|
|
34
|
+
## hreflang (Pages Router)
|
|
35
|
+
|
|
36
|
+
There is no `Metadata` object here. Use the data helper and render the links yourself:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import Head from "next/head";
|
|
40
|
+
import { build_devalon_alternates } from "@devalon.dev/credits/next";
|
|
41
|
+
|
|
42
|
+
const { canonical, languages } = build_devalon_alternates({
|
|
43
|
+
canonical: "https://example.com/ro",
|
|
44
|
+
pages: {
|
|
45
|
+
ro: "https://example.com/ro",
|
|
46
|
+
ru: "https://example.com/ru",
|
|
47
|
+
en: "https://example.com/en",
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
<Head>
|
|
52
|
+
<link rel="canonical" href={canonical} />
|
|
53
|
+
{Object.entries(languages).map(([lang, href]) => (
|
|
54
|
+
<link key={lang} rel="alternate" hrefLang={lang} href={href} />
|
|
55
|
+
))}
|
|
56
|
+
</Head>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Both helpers normalize URLs: trailing slashes, query strings and hashes are removed. Pass clean absolute URLs.
|
|
60
|
+
|
|
61
|
+
## CSP nonce (App Router)
|
|
62
|
+
|
|
63
|
+
If your CSP only allows inline scripts with a nonce (e.g. `script-src 'self' 'nonce-abc123'`), pass it to the component:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { headers } from "next/headers";
|
|
67
|
+
|
|
68
|
+
export default async function LocaleLayout({ params, children }: Props) {
|
|
69
|
+
const { locale } = await params;
|
|
70
|
+
const nonce = (await headers()).get("x-nonce") ?? undefined; // from your middleware
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<html lang={locale}>
|
|
74
|
+
<body>
|
|
75
|
+
{children}
|
|
76
|
+
<DevalonJsonLd
|
|
77
|
+
nonce={nonce}
|
|
78
|
+
site_url="https://example.com"
|
|
79
|
+
site_name="Example Inc."
|
|
80
|
+
in_language={locale}
|
|
81
|
+
page_url={`https://example.com/${locale}`}
|
|
82
|
+
services={["web_development"]}
|
|
83
|
+
/>
|
|
84
|
+
</body>
|
|
85
|
+
</html>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The nonce is emitted as the `nonce` attribute on the JSON-LD `<script>`, so the browser accepts it.
|
|
91
|
+
|
|
92
|
+
**Performance tradeoff:** reading `headers()` makes that layout dynamically rendered — the HTML can no longer be fully static. Use a nonce only when your CSP requires it. If you do use one, make sure it is **per request**; a hardcoded build-time nonce defeats the purpose of a CSP.
|
|
93
|
+
|
|
94
|
+
## CSP nonce (Pages Router)
|
|
95
|
+
|
|
96
|
+
Set the attribute on your own script tag:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<script nonce={nonce} type="application/ld+json" dangerouslySetInnerHTML={{ __html: jsonLd }} />
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Get `nonce` from the request (middleware → header) and pass it via `getServerSideProps` or your document props. Here too, a per-request nonce means per-request HTML.
|
|
103
|
+
|
|
104
|
+
## Verify
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# hreflang/canonical present
|
|
108
|
+
curl -s http://localhost:3000/en | grep -o 'hreflang="[a-z]*"'
|
|
109
|
+
|
|
110
|
+
# nonce present on the JSON-LD script, with the CSP header value
|
|
111
|
+
curl -sI http://localhost:3000/en | grep -i content-security-policy
|
|
112
|
+
curl -s http://localhost:3000/en | grep -o '<script[^>]*application/ld+json[^>]*>'
|
|
113
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# 05 — Performance checklist and verification
|
|
2
|
+
|
|
3
|
+
**When to read this:** before shipping, or when you want the cheapest possible integration.
|
|
4
|
+
|
|
5
|
+
## DO
|
|
6
|
+
|
|
7
|
+
| Action | Why |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| Render `DevalonJsonLd` once per final URL. | One script, one page identity, no duplicate data. |
|
|
10
|
+
| Keep it in a Server Component (no `"use client"`). | Zero client JS and zero hydration. |
|
|
11
|
+
| Use `generateStaticParams()` / static generation. | JSON-LD is produced at build time and served from cache. |
|
|
12
|
+
| Use the URL segment (`[locale]`) for language. | Keeps pages static; no runtime locale detection. |
|
|
13
|
+
| Validate the locale and call `notFound()` on bad values. | No malformed attribution on unknown routes. |
|
|
14
|
+
| Pass only the services actually delivered. | Smaller payload, more accurate data. |
|
|
15
|
+
| Use `build_devalon_alternates_metadata()` for hreflang. | Correct tags without duplicate markup. |
|
|
16
|
+
| In Pages Router, build the JSON at module scope or in `getStaticProps`. | Avoid rebuilding the string on every request. |
|
|
17
|
+
| Keep the credit link clean (`utm` off) unless you run a campaign. | Fewer parameters, no footprint; referral reporting works without UTM. |
|
|
18
|
+
| Run `yarn check:credits <url>` before deploying a credit. | Avoids spending a link on a blocked or unindexed site. |
|
|
19
|
+
|
|
20
|
+
## DON'T
|
|
21
|
+
|
|
22
|
+
| Don't | Instead |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| Put `DevalonJsonLd` in both a layout and a page for the same URL. | Choose one location per URL. |
|
|
25
|
+
| Add `"use client"` to the file rendering it. | Keep the file a Server Component. |
|
|
26
|
+
| Read `cookies()`, `headers()` or `searchParams` in that layout just to configure it. | Use static values / route params; dynamic rendering costs a server render on every request. |
|
|
27
|
+
| Inject the script with `useEffect` / `document.createElement`. | Render it in the server HTML; crawlers don't need to run JS. |
|
|
28
|
+
| Serialize with plain `JSON.stringify()` in Pages Router. | Use the escaping helper from guide 03 (`<`, `>`, `&`, U+2028, U+2029). |
|
|
29
|
+
| Change `site_url` per language. | Keep the root; change `in_language` and `page_url`. |
|
|
30
|
+
| Set a hardcoded CSP nonce to keep the page static. | Use a real per-request nonce (and accept dynamic rendering) or omit it. |
|
|
31
|
+
| Declare dozens of services "just in case". | Declare what was delivered; duplicates are deduplicated but the markup still grows. |
|
|
32
|
+
| Use a CSP that blocks the inline script. | Pass a valid `nonce` (guide 04). |
|
|
33
|
+
|
|
34
|
+
## Quick verification
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
yarn build # must pass unchanged
|
|
38
|
+
npm pack --dry-run # confirms README.md + docs/ are in the package
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For a running server, check the raw HTML of each route:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
curl -s http://localhost:3000/en | grep -c 'application/ld+json' # expect 1
|
|
45
|
+
curl -s http://localhost:3000/en | grep -o '"inLanguage":"[a-z]*"' # expect en
|
|
46
|
+
curl -s http://localhost:3000/ro | grep -o '"inLanguage":"[a-z]*"' # expect ro
|
|
47
|
+
curl -s http://localhost:3000/en | grep -o 'hreflang="[a-z]*"' # expect ro, ru, en
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If a page uses `<script>` injected on the client, `curl` will show **zero** matches — that is the most common performance/SEO mistake.
|
|
51
|
+
|
|
52
|
+
## Build output check
|
|
53
|
+
|
|
54
|
+
In `next build`, the route should be marked static (`○` / as a static route). If it shows `ƒ` (dynamic), look for `headers()`, `cookies()`, `searchParams`, or a per-request nonce in the layout that renders the component.
|
|
55
|
+
|
|
56
|
+
## Final pre-ship checklist
|
|
57
|
+
|
|
58
|
+
- [ ] One `<script type="application/ld+json">` per URL, present in raw HTML.
|
|
59
|
+
- [ ] `site_url` identical for all languages.
|
|
60
|
+
- [ ] `in_language` matches the URL language.
|
|
61
|
+
- [ ] `page_url` is the canonical URL of that exact page.
|
|
62
|
+
- [ ] `hreflang` links present and matching the `pages` map.
|
|
63
|
+
- [ ] No `"use client"` on the rendering file.
|
|
64
|
+
- [ ] Routes still static in the build output.
|
|
65
|
+
- [ ] CSP nonce passed only if the CSP requires it.
|
|
66
|
+
- [ ] Credit link present in the footer, anchor is the `Devalon` brand, `rel="noopener"`.
|
|
67
|
+
- [ ] `yarn check:credits <url>` passes for every client site before deployment.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# 06 — Backlink component (visible credit link)
|
|
2
|
+
|
|
3
|
+
**When to read this:** you want a visible credit on the client site that sends a clean `follow` link back to `devalon.dev`.
|
|
4
|
+
|
|
5
|
+
`DevalonBacklink` is the visible counterpart of `DevalonJsonLd`: the JSON-LD script tells crawlers who built the project, this link confirms it for people and brings referral traffic.
|
|
6
|
+
|
|
7
|
+
## Minimal example (App Router)
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
// app/layout.tsx (or app/[locale]/layout.tsx)
|
|
11
|
+
import { DevalonBacklink } from "@devalon.dev/credits/next";
|
|
12
|
+
|
|
13
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
14
|
+
return (
|
|
15
|
+
<html lang="en">
|
|
16
|
+
<body>
|
|
17
|
+
{children}
|
|
18
|
+
|
|
19
|
+
<footer>
|
|
20
|
+
<DevalonBacklink />
|
|
21
|
+
</footer>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Rendered HTML:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<span>This site was designed and built by
|
|
32
|
+
<a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
|
|
33
|
+
</span>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
No JavaScript, no image, no hydration. The link is in the static HTML, so crawlers see it without executing anything.
|
|
37
|
+
|
|
38
|
+
## Props
|
|
39
|
+
|
|
40
|
+
| Prop | Required | Notes |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `site_url` | only with `utm` | Absolute http(s) URL of the client site. Only its hostname is used, for `utm_source`; `www.` is stripped. Invalid URLs throw a `TypeError`. |
|
|
43
|
+
| `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
|
|
44
|
+
| `sentence` | no | Overrides the built-in sentence. Must not be empty. |
|
|
45
|
+
| `anchor` | no | Visible link text. Defaults to the brand name `Devalon`. Must not be empty. |
|
|
46
|
+
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **false** — the link stays clean. |
|
|
47
|
+
| `className` | no | Your own class for the wrapper `<span>`. The component ships no CSS. |
|
|
48
|
+
|
|
49
|
+
Built-in sentences:
|
|
50
|
+
|
|
51
|
+
| locale | sentence |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `en` | This site was designed and built by |
|
|
54
|
+
| `ro` | Acest site a fost proiectat și construit de |
|
|
55
|
+
| `ru` | Этот сайт спроектирован и разработан |
|
|
56
|
+
| `de` | Diese Website wurde entworfen und entwickelt von |
|
|
57
|
+
| `da` | Denne hjemmeside er designet og udviklet af |
|
|
58
|
+
| `fr` | Ce site a été conçu et développé par |
|
|
59
|
+
| `es` | Este sitio fue diseñado y desarrollado por |
|
|
60
|
+
|
|
61
|
+
## Any subset of the 7 languages
|
|
62
|
+
|
|
63
|
+
Your site can expose 3 of the 7 languages and pass the validated value straight through:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
// app/[locale]/layout.tsx
|
|
67
|
+
import { DevalonBacklink } from "@devalon.dev/credits/next";
|
|
68
|
+
import { notFound } from "next/navigation";
|
|
69
|
+
import { isLocale } from "@/lib/i18n"; // your subset: ["ro", "ru", "en"]
|
|
70
|
+
|
|
71
|
+
export default async function LocaleLayout({
|
|
72
|
+
params,
|
|
73
|
+
children,
|
|
74
|
+
}: {
|
|
75
|
+
params: Promise<{ locale: string }>;
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
}) {
|
|
78
|
+
const { locale } = await params;
|
|
79
|
+
if (!isLocale(locale)) notFound();
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<html lang={locale}>
|
|
83
|
+
<body>
|
|
84
|
+
{children}
|
|
85
|
+
<footer>
|
|
86
|
+
<DevalonBacklink locale={locale} />
|
|
87
|
+
</footer>
|
|
88
|
+
</body>
|
|
89
|
+
</html>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`Locale` from your type guard is a subset of `devalon_locale`, so no cast is needed. Keep `site_url` identical in all languages if you enable `utm`.
|
|
95
|
+
|
|
96
|
+
## Optional UTM tracking
|
|
97
|
+
|
|
98
|
+
By default the href is just `https://devalon.dev`. GA4 already records the client domain as a referral, which is enough when you are not running campaigns.
|
|
99
|
+
|
|
100
|
+
Turn UTM on only when you need campaign segmentation:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<DevalonBacklink site_url="https://example.com" utm />
|
|
104
|
+
// -> https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The UTM parameters do not change the destination page and do not affect the value of the backlink.
|
|
108
|
+
|
|
109
|
+
## Combine it with the JSON-LD component
|
|
110
|
+
|
|
111
|
+
Use one source of truth for `site_url` so the invisible and the visible credits always agree:
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { DevalonBacklink, DevalonJsonLd } from "@devalon.dev/credits/next";
|
|
115
|
+
|
|
116
|
+
const SITE_URL = "https://example.com";
|
|
117
|
+
const SITE_NAME = "Example Inc.";
|
|
118
|
+
|
|
119
|
+
<DevalonJsonLd
|
|
120
|
+
site_url={SITE_URL}
|
|
121
|
+
site_name={SITE_NAME}
|
|
122
|
+
in_language="en"
|
|
123
|
+
page_url={`${SITE_URL}/`}
|
|
124
|
+
services={["web_development"]}
|
|
125
|
+
contributions={["developing", "maintaining"]}
|
|
126
|
+
/>
|
|
127
|
+
|
|
128
|
+
<footer>
|
|
129
|
+
<DevalonBacklink />
|
|
130
|
+
</footer>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The JSON-LD renders a `<script>`; the backlink renders an `<a>`. They are independent and can live in different files.
|
|
134
|
+
|
|
135
|
+
## Pages Router
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
// pages/_app.tsx
|
|
139
|
+
import type { AppProps } from "next/app";
|
|
140
|
+
import { DevalonBacklink } from "@devalon.dev/credits/next";
|
|
141
|
+
|
|
142
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
143
|
+
return (
|
|
144
|
+
<>
|
|
145
|
+
<Component {...pageProps} />
|
|
146
|
+
<footer>
|
|
147
|
+
<DevalonBacklink locale="ro" />
|
|
148
|
+
</footer>
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
There is no effect, state or extra JS emitted by the component itself.
|
|
155
|
+
|
|
156
|
+
## What this link does and does not do
|
|
157
|
+
|
|
158
|
+
- It is a **credit / relationship link**: discovery, brand awareness, entity consistency and referral traffic.
|
|
159
|
+
- It does **not** replace topical backlinks from sites in your niche, and it is not a ranking lever for commercial keywords.
|
|
160
|
+
- Keep it a normal `follow` link: `rel="noopener"`, never `noreferrer`, never `nofollow` or `sponsored` for a genuine credit.
|
|
161
|
+
- Keep it visibly readable. Hidden or tiny links carry no value and can be treated as spam.
|
|
162
|
+
|
|
163
|
+
## Quality gate before deploying
|
|
164
|
+
|
|
165
|
+
Only put the credit on sites that are live, indexed and have real traffic. Run the validator before each deployment:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
yarn check:credits https://client.com
|
|
169
|
+
yarn check:credits https://client.com --deployed # after deployment
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
See [07 — Credit link validator](07-validator.md).
|
|
173
|
+
|
|
174
|
+
For measurement without UTM, create a GA4 **Custom channel group** named `Partner credits` with the rule *Session source matches regex* containing your client domains (`client1\.com|client2\.com|...`). Clean links, clean reporting.
|
|
175
|
+
|
|
176
|
+
## Performance rules
|
|
177
|
+
|
|
178
|
+
- Render once in the layout footer, not repeated in every page component.
|
|
179
|
+
- Do not add `"use client"` to the rendering file to style it — use `className`.
|
|
180
|
+
- Do not inject the link with `useEffect` / `document.createElement`; it must exist in the initial HTML.
|
|
181
|
+
- Do not load a remote logo image — that would add a request and a `remotePatterns` config. Text-only is intentional.
|
|
182
|
+
- The output is computed at render time from static props, so static generation bakes it into the HTML. Avoid `cookies()` / `headers()` in that layout.
|
|
183
|
+
|
|
184
|
+
## Common mistakes
|
|
185
|
+
|
|
186
|
+
| Don't | Do |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
|
|
189
|
+
| `rel="nofollow"` / `rel="sponsored"` for a genuine credit | Leave it a follow link. |
|
|
190
|
+
| `display:none`, `font-size:1px`, white-on-white | Keep the text visibly readable. |
|
|
191
|
+
| Enable `utm` "just in case" | Leave it off; referral reporting is enough without a campaign. |
|
|
192
|
+
| Pass a relative URL like `/despre` as `site_url` | Pass an absolute `https://...` URL. |
|
|
193
|
+
| Put the credit on a staging or `noindex` site | Run the validator first. |
|
|
194
|
+
|
|
195
|
+
## Verify
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
yarn build
|
|
199
|
+
curl -s http://localhost:3000/ | grep -o 'https://devalon.dev' # expect 1 clean link
|
|
200
|
+
curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
|
|
201
|
+
curl -s http://localhost:3000/ro | grep -o 'Acest site a fost proiectat'
|
|
202
|
+
curl -s http://localhost:3000/ru | grep -o 'Этот сайт спроектирован'
|
|
203
|
+
```
|