@devalon.dev/credits 1.0.0 → 1.0.1
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/LICENSE +21 -0
- package/README.md +5 -1
- package/dist/chunk-NG7NWZWD.mjs +16 -0
- package/dist/chunk-YBXS4SND.mjs +11 -0
- package/dist/core/backlink.d.ts +21 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/next/index.d.ts +4 -0
- package/dist/next/index.js +9 -9
- package/dist/next/index.mjs +1 -1
- package/dist/next/source.d.ts +12 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +19 -19
- package/dist/react/index.mjs +1 -1
- package/dist/vite/index.js +23 -23
- package/dist/vite/index.mjs +4 -4
- package/dist/vite/plugin.d.ts +1 -1
- package/docs/nextjs/05-performance-checklist.md +1 -1
- package/docs/nextjs/06-backlink-component.md +50 -27
- package/docs/react/02-csr-vite.md +6 -0
- package/docs/react/03-i18n.md +8 -8
- package/docs/react/05-backlink-component.md +15 -10
- package/docs/react/08-validator.md +1 -1
- package/package.json +3 -2
- package/scripts/backlink.test.mjs +178 -0
- package/dist/chunk-QU6SEFG7.mjs +0 -16
- package/dist/chunk-YF7SVQTC.mjs +0 -11
|
@@ -28,35 +28,37 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
28
28
|
Rendered HTML:
|
|
29
29
|
|
|
30
30
|
```html
|
|
31
|
-
<span>
|
|
31
|
+
<span>Designed and built by
|
|
32
32
|
<a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
|
|
33
33
|
</span>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
No JavaScript, no image, no hydration. The link is in the static HTML, so crawlers see it without executing anything.
|
|
36
|
+
No JavaScript, no image, no hydration. The link is in the static HTML, so crawlers see it without executing anything. When a source is detected the `href` gains UTM parameters (see below); with no source it stays clean.
|
|
37
37
|
|
|
38
38
|
## Props
|
|
39
39
|
|
|
40
40
|
| Prop | Required | Notes |
|
|
41
41
|
| --- | --- | --- |
|
|
42
|
-
| `site_url` |
|
|
42
|
+
| `site_url` | no | Absolute http(s) URL of the client site. Only its hostname is used, for `utm_source`; `www.` is stripped. Auto-detected when omitted. Invalid explicit URLs throw a `TypeError`. |
|
|
43
43
|
| `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
|
|
44
44
|
| `sentence` | no | Overrides the built-in sentence. Must not be empty. |
|
|
45
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 **
|
|
46
|
+
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **true**. With no detectable source the link stays clean instead of throwing. Pass `false` to force a clean link. |
|
|
47
47
|
| `className` | no | Your own class for the wrapper `<span>`. The component ships no CSS. |
|
|
48
48
|
|
|
49
49
|
Built-in sentences:
|
|
50
50
|
|
|
51
51
|
| locale | sentence |
|
|
52
52
|
| --- | --- |
|
|
53
|
-
| `en` |
|
|
54
|
-
| `ro` |
|
|
55
|
-
| `ru` |
|
|
56
|
-
| `de` |
|
|
57
|
-
| `da` |
|
|
58
|
-
| `fr` |
|
|
59
|
-
| `es` |
|
|
53
|
+
| `en` | Designed and built by |
|
|
54
|
+
| `ro` | Proiectat și realizat de |
|
|
55
|
+
| `ru` | Дизайн и разработка от |
|
|
56
|
+
| `de` | Entworfen und entwickelt von |
|
|
57
|
+
| `da` | Designet og udviklet af |
|
|
58
|
+
| `fr` | Conçu et développé par |
|
|
59
|
+
| `es` | Diseñado y desarrollado por |
|
|
60
|
+
|
|
61
|
+
Prefer the longer wording? Pass it explicitly, e.g. `sentence="Acest site a fost proiectat și construit de"`.
|
|
60
62
|
|
|
61
63
|
## Any subset of the 7 languages
|
|
62
64
|
|
|
@@ -91,24 +93,44 @@ export default async function LocaleLayout({
|
|
|
91
93
|
}
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
`Locale` from your type guard is a subset of `devalon_locale`, so no cast is needed.
|
|
96
|
+
`Locale` from your type guard is a subset of `devalon_locale`, so no cast is needed. The auto-detected source is site-wide, so it is identical in all languages.
|
|
97
|
+
|
|
98
|
+
## UTM attribution (on by default)
|
|
99
|
+
|
|
100
|
+
`utm` defaults to `true`. The component reads the build-time environment and uses the **hostname only** as `utm_source`:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# .env.local / deployment env
|
|
104
|
+
NEXT_PUBLIC_SITE_URL=https://example.com
|
|
105
|
+
# -> https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`NEXT_PUBLIC_SITE_URL` is recommended because Next.js inlines it into both the server and client bundles, so auto-detection never causes a hydration mismatch. The generic `SITE_URL` and platform variables (`VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`) are used by the Vite plugin and by HTML-string helpers. Bare hostnames are accepted; paths are ignored. Invalid values are skipped.
|
|
95
109
|
|
|
96
|
-
|
|
110
|
+
With **no** detectable source the link stays clean — `https://devalon.dev` — and nothing throws. Pass `utm={false}` to force a clean link even when a source exists. An explicit `site_url` always wins over detection. The parameters do not change the destination page and do not affect the value of the backlink.
|
|
97
111
|
|
|
98
|
-
|
|
112
|
+
### Live host detection (opt-in, makes the route dynamic)
|
|
99
113
|
|
|
100
|
-
|
|
114
|
+
If you need the request host rather than a build-time value, read it yourself and pass it in. This opts the layout into dynamic rendering, so only do it where that trade-off is acceptable:
|
|
101
115
|
|
|
102
116
|
```tsx
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
import { headers } from "next/headers";
|
|
118
|
+
import {
|
|
119
|
+
DevalonBacklink,
|
|
120
|
+
devalonBacklinkSiteUrlFromHeaders,
|
|
121
|
+
} from "@devalon.dev/credits/next";
|
|
122
|
+
|
|
123
|
+
export default async function Footer() {
|
|
124
|
+
const site_url = devalonBacklinkSiteUrlFromHeaders(await headers());
|
|
125
|
+
return <DevalonBacklink site_url={site_url} />;
|
|
126
|
+
}
|
|
105
127
|
```
|
|
106
128
|
|
|
107
|
-
The
|
|
129
|
+
The helper returns `undefined` when no usable host is present, which again yields a clean link.
|
|
108
130
|
|
|
109
131
|
## Combine it with the JSON-LD component
|
|
110
132
|
|
|
111
|
-
Use one source of truth for `site_url`
|
|
133
|
+
Use one source of truth for `site_url` in the JSON-LD; the visible credit detects its own source from the environment and stays in agreement:
|
|
112
134
|
|
|
113
135
|
```tsx
|
|
114
136
|
import { DevalonBacklink, DevalonJsonLd } from "@devalon.dev/credits/next";
|
|
@@ -130,7 +152,7 @@ const SITE_NAME = "Example Inc.";
|
|
|
130
152
|
</footer>
|
|
131
153
|
```
|
|
132
154
|
|
|
133
|
-
The JSON-LD renders a `<script>`; the backlink renders an `<a>`. They are independent and can live in different files.
|
|
155
|
+
The JSON-LD renders a `<script>`; the backlink renders an `<a>`. They are independent and can live in different files. Set `NEXT_PUBLIC_SITE_URL` to the same value so the detected backlink source agrees with `SITE_URL` (or pass `site_url={SITE_URL}` to the backlink explicitly).
|
|
134
156
|
|
|
135
157
|
## Pages Router
|
|
136
158
|
|
|
@@ -171,7 +193,7 @@ yarn check:credits https://client.com --deployed # after deployment
|
|
|
171
193
|
|
|
172
194
|
See [07 — Credit link validator](07-validator.md).
|
|
173
195
|
|
|
174
|
-
|
|
196
|
+
If no source is detectable and the link stays clean, 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
197
|
|
|
176
198
|
## Performance rules
|
|
177
199
|
|
|
@@ -179,7 +201,7 @@ For measurement without UTM, create a GA4 **Custom channel group** named `Partne
|
|
|
179
201
|
- Do not add `"use client"` to the rendering file to style it — use `className`.
|
|
180
202
|
- Do not inject the link with `useEffect` / `document.createElement`; it must exist in the initial HTML.
|
|
181
203
|
- 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.
|
|
204
|
+
- The output is computed at render time from static props plus build-time env, so static generation bakes it into the HTML. Avoid `cookies()` / `headers()` in that layout; the opt-in live-host helper above is the one exception and makes that route dynamic.
|
|
183
205
|
|
|
184
206
|
## Common mistakes
|
|
185
207
|
|
|
@@ -188,16 +210,17 @@ For measurement without UTM, create a GA4 **Custom channel group** named `Partne
|
|
|
188
210
|
| `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
|
|
189
211
|
| `rel="nofollow"` / `rel="sponsored"` for a genuine credit | Leave it a follow link. |
|
|
190
212
|
| `display:none`, `font-size:1px`, white-on-white | Keep the text visibly readable. |
|
|
191
|
-
|
|
|
192
|
-
| Pass a relative URL like `/despre` as `site_url` | Pass an absolute `https://...` URL. |
|
|
213
|
+
| Expect UTM with no environment source set | Set `NEXT_PUBLIC_SITE_URL`, or accept the clean link. |
|
|
214
|
+
| Pass a relative URL like `/despre` as `site_url` | Pass an absolute `https://...` URL, or let detection supply it. |
|
|
193
215
|
| Put the credit on a staging or `noindex` site | Run the validator first. |
|
|
194
216
|
|
|
195
217
|
## Verify
|
|
196
218
|
|
|
197
219
|
```bash
|
|
198
220
|
yarn build
|
|
199
|
-
curl -s http://localhost:3000/ | grep -o 'https://devalon.dev' # expect 1 clean link
|
|
200
221
|
curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
|
|
201
|
-
curl -s http://localhost:3000/ro | grep -o '
|
|
202
|
-
curl -s http://localhost:3000/ru | grep -o '
|
|
222
|
+
curl -s http://localhost:3000/ro | grep -o 'Proiectat și realizat de'
|
|
223
|
+
curl -s http://localhost:3000/ru | grep -o 'Дизайн и разработка от'
|
|
224
|
+
# With NEXT_PUBLIC_SITE_URL set, expect an attributed link:
|
|
225
|
+
curl -s http://localhost:3000/ | grep -o 'utm_source=example.com'
|
|
203
226
|
```
|
|
@@ -73,6 +73,12 @@ dist/_headers ← Devalon response headers for Netlify / Cloudflare Pages
|
|
|
73
73
|
|
|
74
74
|
The plugin is **idempotent**: marked blocks are replaced on every build, so repeated builds never duplicate credits. `source` in `agentFilesConfig` is the client's own `llms.txt` text; the Devalon block is merged into it. Existing `_headers` / `vercel.json` content is preserved — see [06 — Server headers](06-server-headers.md).
|
|
75
75
|
|
|
76
|
+
### Backlink source detection
|
|
77
|
+
|
|
78
|
+
UTM attribution is on by default for the injected backlink. The plugin reads the build environment and uses the **hostname only** as `utm_source`. Keys are checked in this order: `NEXT_PUBLIC_SITE_URL`, `SITE_URL`, `VITE_SITE_URL`, `VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`. Bare hostnames are accepted, paths and ports are ignored, and invalid values are skipped. With no usable value the link stays clean — no build failure.
|
|
79
|
+
|
|
80
|
+
An explicit `backlink.site_url` always wins over detection, and `backlink: { utm: false }` still forces a clean link. Detection happens at build time, so the output stays a single static HTML document.
|
|
81
|
+
|
|
76
82
|
## Without the plugin
|
|
77
83
|
|
|
78
84
|
`@devalon.dev/credits/react` exposes the pure transform if you prefer to wire your own build step:
|
package/docs/react/03-i18n.md
CHANGED
|
@@ -57,7 +57,7 @@ import { DevalonBacklink } from "@devalon.dev/credits/react";
|
|
|
57
57
|
<DevalonBacklink locale={locale} />
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
The detected source is site-wide and identical in every language — only the hostname becomes `utm_source`, so a different root would split your referral data. If you pass `site_url` explicitly, keep it identical across locales.
|
|
61
61
|
|
|
62
62
|
## Per-request headers
|
|
63
63
|
|
|
@@ -84,13 +84,13 @@ See [06 — Server headers](06-server-headers.md) for Express / CDN variants.
|
|
|
84
84
|
|
|
85
85
|
| locale | sentence |
|
|
86
86
|
| --- | --- |
|
|
87
|
-
| `en` |
|
|
88
|
-
| `ro` |
|
|
89
|
-
| `ru` |
|
|
90
|
-
| `de` |
|
|
91
|
-
| `da` |
|
|
92
|
-
| `fr` |
|
|
93
|
-
| `es` |
|
|
87
|
+
| `en` | Designed and built by |
|
|
88
|
+
| `ro` | Proiectat și realizat de |
|
|
89
|
+
| `ru` | Дизайн и разработка от |
|
|
90
|
+
| `de` | Entworfen und entwickelt von |
|
|
91
|
+
| `da` | Designet og udviklet af |
|
|
92
|
+
| `fr` | Conçu et développé par |
|
|
93
|
+
| `es` | Diseñado y desarrollado por |
|
|
94
94
|
|
|
95
95
|
Override any of them with `sentence`, or pass `anchor` to change the link text.
|
|
96
96
|
|
|
@@ -21,7 +21,7 @@ export function Footer() {
|
|
|
21
21
|
Rendered HTML:
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<span>
|
|
24
|
+
<span>Proiectat și realizat de
|
|
25
25
|
<a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
|
|
26
26
|
</span>
|
|
27
27
|
```
|
|
@@ -36,7 +36,7 @@ When the body of your document is assembled as a string (custom SSR template, st
|
|
|
36
36
|
import { devalonBacklinkHtml } from "@devalon.dev/credits/react";
|
|
37
37
|
|
|
38
38
|
const credit = devalonBacklinkHtml({ locale: "ro", className: "credit" });
|
|
39
|
-
// <span class="credit">
|
|
39
|
+
// <span class="credit">Proiectat și realizat de <a href="https://devalon.dev" ...>Devalon</a></span>
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Or inject it automatically with `devalonInjectHtml(html, { ..., backlink: { locale: "ro" } })` — see [01 — SSR setup](01-ssr-setup.md) and [02 — CSR / Vite](02-csr-vite.md).
|
|
@@ -45,21 +45,26 @@ Or inject it automatically with `devalonInjectHtml(html, { ..., backlink: { loca
|
|
|
45
45
|
|
|
46
46
|
| Prop | Required | Notes |
|
|
47
47
|
| --- | --- | --- |
|
|
48
|
-
| `site_url` |
|
|
48
|
+
| `site_url` | no | Absolute http(s) URL of the client site. Only its hostname is used, for `utm_source`; `www.` is stripped. Auto-detected when omitted. Invalid explicit URLs throw a `TypeError`. |
|
|
49
49
|
| `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
|
|
50
50
|
| `sentence` | no | Overrides the built-in sentence. Must not be empty. |
|
|
51
51
|
| `anchor` | no | Visible link text. Defaults to `Devalon`. Must not be empty. |
|
|
52
|
-
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **
|
|
52
|
+
| `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **true**. With no detectable source the link stays clean instead of throwing. Pass `false` to force a clean link. |
|
|
53
53
|
| `className` | no | Your class for the wrapper `<span>`. The component ships no CSS. |
|
|
54
54
|
|
|
55
|
-
##
|
|
55
|
+
## UTM attribution (on by default)
|
|
56
|
+
|
|
57
|
+
`utm` defaults to `true`. In Node SSR and HTML-string helpers the source is detected from `process.env`; in the browser there is no server environment, so the Vite plugin bakes the source into the HTML at build time. Only the hostname is used:
|
|
56
58
|
|
|
57
59
|
```tsx
|
|
58
|
-
<DevalonBacklink
|
|
60
|
+
<DevalonBacklink />
|
|
61
|
+
// with SITE_URL=https://example.com/ro in the build environment:
|
|
59
62
|
// https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
|
|
60
63
|
```
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
Env keys, in priority order: `NEXT_PUBLIC_SITE_URL`, `SITE_URL`, `VITE_SITE_URL`, `VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`. Bare hostnames are accepted, paths are ignored, invalid values are skipped. An explicit `site_url` wins over detection. With no detectable source the link stays clean. UTM does not change the destination page or the value of the backlink.
|
|
66
|
+
|
|
67
|
+
Use `detect_site_url(env)` from either entrypoint to inspect what would be detected for a given env object.
|
|
63
68
|
|
|
64
69
|
## Quality rules
|
|
65
70
|
|
|
@@ -76,14 +81,14 @@ UTM does not change the destination page and does not affect the value of the ba
|
|
|
76
81
|
| `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
|
|
77
82
|
| `rel="nofollow"` for a genuine credit | Leave it a follow link. |
|
|
78
83
|
| `display:none`, white-on-white | Keep the text visibly readable. |
|
|
79
|
-
|
|
|
80
|
-
| Pass a relative `site_url` | Pass an absolute `https://...` URL. |
|
|
84
|
+
| Expect UTM with no environment source set | Set a build-time env var, or accept the clean link. |
|
|
85
|
+
| Pass a relative `site_url` | Pass an absolute `https://...` URL, or let detection supply it. |
|
|
81
86
|
| Put the credit on a `noindex` staging site | Run the validator first — [08 — Validator](08-validator.md). |
|
|
82
87
|
|
|
83
88
|
## Verify
|
|
84
89
|
|
|
85
90
|
```bash
|
|
86
91
|
curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
|
|
87
|
-
curl -s http://localhost:3000/ro | grep -o '
|
|
92
|
+
curl -s http://localhost:3000/ro | grep -o 'Proiectat și realizat de'
|
|
88
93
|
curl -s http://localhost:3000/ | grep -o 'https://devalon.dev' | wc -l # expect 1 in the body credit
|
|
89
94
|
```
|
|
@@ -42,7 +42,7 @@ Only put the credit on sites that are live, indexed and have real traffic. A cre
|
|
|
42
42
|
|
|
43
43
|
- Keep one canonical `site_url` per client across all integrations (JSON-LD, headers, `llms.txt`, backlink UTM).
|
|
44
44
|
- Re-run the validator after each deployment.
|
|
45
|
-
-
|
|
45
|
+
- With UTM on by default, create a GA4 **Custom channel group** named `Partner credits` with *Session source matches regex* containing your client domains (`client1\.com|client2\.com|...`). If no source was detectable and the link stayed clean, the default referral report is enough.
|
|
46
46
|
|
|
47
47
|
## Common failures
|
|
48
48
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devalon.dev/credits",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Devalon technology-partner attribution for Next.js, React and Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -39,12 +39,13 @@
|
|
|
39
39
|
"!.env.*"
|
|
40
40
|
],
|
|
41
41
|
"bin": {
|
|
42
|
-
"devalon-check": "
|
|
42
|
+
"devalon-check": "scripts/check-devalon-credits.mjs"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts --format esm,cjs --clean --minify && tsc --emitDeclarationOnly --declarationMap false --outDir dist && rm -rf dist/src",
|
|
46
46
|
"dev": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts --format esm,cjs --watch",
|
|
47
47
|
"check:credits": "node scripts/check-devalon-credits.mjs",
|
|
48
|
+
"test": "yarn build && node --test scripts/*.test.mjs",
|
|
48
49
|
"prepublishOnly": "yarn build"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
devalonBacklinkHtml,
|
|
6
|
+
devalonInjectHtml,
|
|
7
|
+
detect_site_url,
|
|
8
|
+
resolve_backlink,
|
|
9
|
+
} from "../dist/react/index.mjs";
|
|
10
|
+
import { devalonBacklinkSiteUrlFromHeaders } from "../dist/next/index.mjs";
|
|
11
|
+
import { devalonVite } from "../dist/vite/index.mjs";
|
|
12
|
+
|
|
13
|
+
const CLEAN = "https://devalon.dev";
|
|
14
|
+
const UTM =
|
|
15
|
+
"https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits";
|
|
16
|
+
|
|
17
|
+
describe("backlink defaults", () => {
|
|
18
|
+
it("uses the short localized sentences", () => {
|
|
19
|
+
assert.equal(resolve_backlink({ locale: "en" }).text, "Designed and built by");
|
|
20
|
+
assert.equal(resolve_backlink({ locale: "ro" }).text, "Proiectat și realizat de");
|
|
21
|
+
assert.equal(resolve_backlink({ locale: "de" }).text, "Entworfen und entwickelt von");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("emits a clean link when no source is available", () => {
|
|
25
|
+
assert.equal(resolve_backlink({}).href, CLEAN);
|
|
26
|
+
assert.equal(resolve_backlink({ locale: "ro" }).href, CLEAN);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("appends hostname-only UTM by default", () => {
|
|
30
|
+
const result = resolve_backlink({
|
|
31
|
+
site_url: "https://www.Example.com/ro/about?x=1",
|
|
32
|
+
locale: "ro",
|
|
33
|
+
});
|
|
34
|
+
assert.equal(result.href, UTM);
|
|
35
|
+
assert.equal(result.link_text, "Devalon");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("honours utm: false and an explicit sentence/anchor", () => {
|
|
39
|
+
assert.equal(
|
|
40
|
+
resolve_backlink({ site_url: "https://example.com", utm: false }).href,
|
|
41
|
+
CLEAN,
|
|
42
|
+
);
|
|
43
|
+
const result = resolve_backlink({ sentence: "Custom text", anchor: "Studio" });
|
|
44
|
+
assert.equal(result.text, "Custom text");
|
|
45
|
+
assert.equal(result.link_text, "Studio");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("still rejects invalid explicit site_url values", () => {
|
|
49
|
+
assert.throws(() => resolve_backlink({ site_url: "/despre" }), TypeError);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("source detection", () => {
|
|
54
|
+
it("normalizes bare hosts and strips paths", () => {
|
|
55
|
+
assert.equal(detect_site_url({ SITE_URL: "Example.com/ro" }), "https://example.com");
|
|
56
|
+
assert.equal(
|
|
57
|
+
detect_site_url({ SITE_URL: "http://example.com:8080/x" }),
|
|
58
|
+
"http://example.com",
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("respects priority and skips unusable values", () => {
|
|
63
|
+
assert.equal(
|
|
64
|
+
detect_site_url({
|
|
65
|
+
NEXT_PUBLIC_SITE_URL: "ok.com",
|
|
66
|
+
SITE_URL: "ftp://bad.example",
|
|
67
|
+
}),
|
|
68
|
+
"https://ok.com",
|
|
69
|
+
);
|
|
70
|
+
assert.equal(
|
|
71
|
+
detect_site_url({ SITE_URL: "not a url", VERCEL_URL: "app.vercel.app" }),
|
|
72
|
+
"https://app.vercel.app",
|
|
73
|
+
);
|
|
74
|
+
assert.equal(detect_site_url({}), undefined);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("derives an absolute URL from request headers", () => {
|
|
78
|
+
assert.equal(
|
|
79
|
+
devalonBacklinkSiteUrlFromHeaders(
|
|
80
|
+
new Headers({ host: "example.com", "x-forwarded-proto": "http" }),
|
|
81
|
+
),
|
|
82
|
+
"http://example.com",
|
|
83
|
+
);
|
|
84
|
+
assert.equal(
|
|
85
|
+
devalonBacklinkSiteUrlFromHeaders(
|
|
86
|
+
new Headers({
|
|
87
|
+
"x-forwarded-host": "www.Example.com, proxy",
|
|
88
|
+
host: "internal.local",
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
"https://example.com",
|
|
92
|
+
);
|
|
93
|
+
assert.equal(devalonBacklinkSiteUrlFromHeaders(undefined), undefined);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("auto-detects from process.env in the HTML helper", () => {
|
|
97
|
+
const original = process.env.SITE_URL;
|
|
98
|
+
process.env.SITE_URL = "env-site.com";
|
|
99
|
+
try {
|
|
100
|
+
const html = devalonBacklinkHtml({ locale: "ro" });
|
|
101
|
+
assert.match(html, /Proiectat și realizat de/);
|
|
102
|
+
assert.match(html, /utm_source=env-site\.com/);
|
|
103
|
+
} finally {
|
|
104
|
+
if (original === undefined) delete process.env.SITE_URL;
|
|
105
|
+
else process.env.SITE_URL = original;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("injects a UTM link into HTML from build-time env", () => {
|
|
110
|
+
const original = process.env.SITE_URL;
|
|
111
|
+
process.env.SITE_URL = "vite-site.com";
|
|
112
|
+
try {
|
|
113
|
+
const plugin = devalonVite({
|
|
114
|
+
site_url: "https://vite-site.com",
|
|
115
|
+
site_name: "Vite Site",
|
|
116
|
+
backlink: { locale: "ro" },
|
|
117
|
+
});
|
|
118
|
+
const html = plugin.transformIndexHtml.handler(
|
|
119
|
+
"<html><head></head><body></body></html>",
|
|
120
|
+
);
|
|
121
|
+
assert.match(html, /utm_source=vite-site\.com/);
|
|
122
|
+
assert.match(html, /Proiectat și realizat de/);
|
|
123
|
+
} finally {
|
|
124
|
+
if (original === undefined) delete process.env.SITE_URL;
|
|
125
|
+
else process.env.SITE_URL = original;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("prefers explicit site_url over detection and still honours utm: false", () => {
|
|
130
|
+
const original = process.env.SITE_URL;
|
|
131
|
+
process.env.SITE_URL = "vite-site.com";
|
|
132
|
+
try {
|
|
133
|
+
const explicit = devalonVite({
|
|
134
|
+
site_url: "https://vite-site.com",
|
|
135
|
+
site_name: "Vite Site",
|
|
136
|
+
backlink: { locale: "ro", site_url: "https://explicit.com/ro" },
|
|
137
|
+
});
|
|
138
|
+
const explicit_html = explicit.transformIndexHtml.handler(
|
|
139
|
+
"<html><head></head><body></body></html>",
|
|
140
|
+
);
|
|
141
|
+
assert.match(explicit_html, /utm_source=explicit\.com/);
|
|
142
|
+
assert.doesNotMatch(explicit_html, /utm_source=vite-site\.com/);
|
|
143
|
+
|
|
144
|
+
const disabled = devalonVite({
|
|
145
|
+
site_url: "https://vite-site.com",
|
|
146
|
+
site_name: "Vite Site",
|
|
147
|
+
backlink: { locale: "ro", utm: false },
|
|
148
|
+
});
|
|
149
|
+
const disabled_html = disabled.transformIndexHtml.handler(
|
|
150
|
+
"<html><head></head><body></body></html>",
|
|
151
|
+
);
|
|
152
|
+
assert.match(disabled_html, /href="https:\/\/devalon\.dev"/);
|
|
153
|
+
assert.doesNotMatch(disabled_html, /utm_source=/);
|
|
154
|
+
} finally {
|
|
155
|
+
if (original === undefined) delete process.env.SITE_URL;
|
|
156
|
+
else process.env.SITE_URL = original;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("keeps devalonInjectHtml clean with no detectable source", () => {
|
|
161
|
+
const original = process.env.SITE_URL;
|
|
162
|
+
delete process.env.SITE_URL;
|
|
163
|
+
try {
|
|
164
|
+
const html = devalonInjectHtml(
|
|
165
|
+
"<html><head></head><body></body></html>",
|
|
166
|
+
{
|
|
167
|
+
site_url: "https://example.com",
|
|
168
|
+
site_name: "Example",
|
|
169
|
+
backlink: { locale: "ro" },
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
assert.match(html, /href="https:\/\/devalon\.dev"/);
|
|
173
|
+
assert.doesNotMatch(html, /utm_source=/);
|
|
174
|
+
} finally {
|
|
175
|
+
if (original !== undefined) process.env.SITE_URL = original;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
package/dist/chunk-QU6SEFG7.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{a as d,b as g,e as h,i as v,j as f,m as y,r as w}from"./chunk-SHIXBOQB.mjs";function u(e){let n;try{n=new URL(e)}catch{throw new TypeError("site_url must be an absolute HTTP(S) URL.")}if(n.protocol!=="https:"&&n.protocol!=="http:")throw new TypeError("site_url must be an absolute HTTP(S) URL.");return n.hash="",n.search="",n.pathname=n.pathname.replace(/\/+$/,"")||"/",n.toString().replace(/\/$/,"")}var x="<!-- devalon:start -->",k="<!-- devalon:end -->",E="/* devalon:start */",m="/* devalon:end */";function L(e){return new Response(e,{headers:{"Content-Type":"text/plain; charset=utf-8"}})}function N(e){let n=f,t=new Set;for(let r of e){let o=n[r]??r,s=v[o];if(!s)throw new TypeError(`Unknown Devalon service: ${String(r)}`);t.add(s.name)}return[...t]}function T(e){let n=N(e.services??[]),t=[x,"## Credits","",`Built and maintained by [Devalon](${d}), an AI & software development studio.`];return n.length>0&&t.push(`Services: ${n.join(", ")}.`),t.push(k),t.join(`
|
|
2
|
-
`)}function b(e){let n=e.site_name.trim();if(!n)throw new TypeError("site_name must not be empty.");let t=e.description?.trim()??`Official website of ${n}.`;return[`# ${n}`,"",`> ${t}`,"",`- Canonical: ${u(e.site_url)}`,"",T(e),""].join(`
|
|
3
|
-
`)}function H(e,n,t,r){let o=e.indexOf(n),s=e.indexOf(t);if(o!==-1&&s!==-1&&s>o)return e.slice(0,o)+r+e.slice(s+t.length);let i=e.trimEnd();return i?`${i}
|
|
4
|
-
|
|
5
|
-
${r}
|
|
6
|
-
`:`${r}
|
|
7
|
-
`}function A(e,n){return H(e,x,k,T(n))}function G(e){return L(e.source?.trim()?A(e.source,e):b(e))}function D(e){return[E,"Developer: Devalon",`URL: ${d}`,m].join(`
|
|
8
|
-
`)}function $(e){let n=e.site_name.trim();if(!n)throw new TypeError("site_name must not be empty.");return["/* TEAM */",D(e),"","/* SITE */",`Name: ${n}`,`URL: ${u(e.site_url)}`,""].join(`
|
|
9
|
-
`)}function U(e,n){let t=D(n),r=e.indexOf(E),o=e.indexOf(m);if(r!==-1&&o!==-1&&o>r)return e.slice(0,r)+t+e.slice(o+m.length);let s="/* TEAM */",i=e.indexOf(s);if(i!==-1){let l=i+s.length,a=e.indexOf("/*",l),_=a===-1?e.length:a,p=e.slice(0,_).trimEnd(),C=e.slice(_);return`${p}
|
|
10
|
-
${t}
|
|
11
|
-
|
|
12
|
-
${C.trimStart()}`}let c=e.trimEnd();return c?`${c}
|
|
13
|
-
|
|
14
|
-
${t}
|
|
15
|
-
`:`${t}
|
|
16
|
-
`}function F(e){return L(e.source?.trim()?U(e.source,e):$(e))}function J(e){return{"llms.txt":e.source?.trim()?A(e.source,e):b(e),"humans.txt":$(e)}}function I(e){let t=f[e]??e;if(!(t in v))throw new TypeError(`Unknown Devalon service: ${String(e)}`);return t}function j(e){let n=new Set;for(let t of e){let r=y[t];if(!r)throw new TypeError(`Unknown Devalon contribution: ${String(t)}`);n.add(r.relationship)}return[...n]}function S(e){let{site_url:n,services:t=[],contributions:r=["development","engineering"],locale:o}=e,s=u(n),i=[...new Set(t.map(I))],c=j(r);if(o!==void 0&&!h.includes(o))throw new TypeError(`Unsupported Devalon locale: ${String(o)}`);let l=[{key:"X-Devalon-Creator",value:"Devalon"},{key:"X-Devalon-Creator-Url",value:d},{key:"X-Devalon-Creator-Id",value:g},{key:"X-Devalon-Project",value:s},{key:"X-Built-By",value:`Devalon (${d})`},{key:"Link",value:`<${d}>; rel="author"`}];i.length>0&&l.push({key:"X-Devalon-Services",value:i.join(", ")});let a=[...new Set(r)];return a.length>0&&l.push({key:"X-Devalon-Contributions",value:a.join(", ")}),c.length>0&&l.push({key:"X-Devalon-Relationships",value:c.join(", ")}),o&&l.push({key:"X-Devalon-Locale",value:o}),l}function Y(e){return(n,t,r)=>{let{localeFromPath:o,...s}=e,i=s.locale;if(!i&&o?.length){let a=(n.url?.split("?")[0]??"").split("/")[1];a&&o.includes(a)&&(i=a)}let c=S(i?{...s,locale:i}:s);for(let{key:l,value:a}of c){if(l.toLowerCase()==="link"){let _=t.getHeader("Link")??t.getHeader("link"),p=Array.isArray(_)?_.join(", "):typeof _=="string"?_:"";t.setHeader("Link",p?`${p.replace(/,\s*$/,"")}, ${a}`:a);continue}t.setHeader(l,a)}r()}}function Z(e,n){for(let{key:t,value:r}of S(n)){if(t.toLowerCase()==="link"){let o=e.headers.get("link");e.headers.set("link",o?`${o.replace(/,\s*$/,"")}, ${r}`:r);continue}e.headers.set(t,r)}return e}var R={en:"This site was designed and built by",ro:"Acest site a fost proiectat \u0219i construit de",ru:"\u042D\u0442\u043E\u0442 \u0441\u0430\u0439\u0442 \u0441\u043F\u0440\u043E\u0435\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043E\u0442\u0430\u043D",de:"Diese Website wurde entworfen und entwickelt von",da:"Denne hjemmeside er designet og udviklet af",fr:"Ce site a \xE9t\xE9 con\xE7u et d\xE9velopp\xE9 par",es:"Este sitio fue dise\xF1ado y desarrollado por"},V="Devalon";function X(e){let n;try{n=new URL(e)}catch{throw new TypeError("site_url must be an absolute HTTP(S) URL.")}if(n.protocol!=="https:"&&n.protocol!=="http:")throw new TypeError("site_url must be an absolute HTTP(S) URL.");return n.hostname.replace(/^www\./,"")}function te(e){let{site_url:n,locale:t="en",sentence:r,anchor:o=V,utm:s=!1}=e;if(!(t in R))throw new TypeError(`Unsupported Devalon backlink locale: ${String(t)}`);let i=(r??R[t]).trim(),c=o.trim();if(!i)throw new TypeError("sentence must not be empty.");if(!c)throw new TypeError("anchor must not be empty.");let l=d;if(s){if(!n)throw new TypeError("site_url is required when utm is enabled.");let a=X(n);l=`${d}/?utm_source=${encodeURIComponent(a)}&utm_medium=credit&utm_campaign=devalon-credits`}return{text:i,link_text:c,href:l}}function O(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function B(e){let n=JSON.stringify(e);if(n===void 0)throw new TypeError("Devalon JSON-LD could not be serialized.");return n.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function M(e){return B(w(e))}function ae(e){let{nonce:n,...t}=e;return`<script type="application/ld+json"${n?` nonce="${O(n)}"`:""}>${M(t)}</script>`}export{T as a,b,A as c,G as d,D as e,$ as f,U as g,F as h,J as i,te as j,S as k,Y as l,Z as m,O as n,M as o,ae as p};
|
package/dist/chunk-YF7SVQTC.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{j as f,n as l,p as k}from"./chunk-QU6SEFG7.mjs";import{q as d}from"./chunk-SHIXBOQB.mjs";var i="<!-- devalon:head:start -->",s="<!-- devalon:head:end -->",c="<!-- devalon:backlink:start -->",_="<!-- devalon:backlink:end -->";function v(e){let{canonical:o,languages:a}=d(e),n=[`<link rel="canonical" href="${l(o)}" />`];for(let[t,r]of Object.entries(a))r&&n.push(`<link rel="alternate" hreflang="${l(t)}" href="${l(r)}" />`);return n.join(`
|
|
2
|
-
`)}function $(e){let{alternates:o,...a}=e,n=[k(a)];return o&&n.push(v(o)),n.join(`
|
|
3
|
-
`)}function b(e){let{text:o,link_text:a,href:n}=f(e),t=e.className?.trim();return`<span${t?` class="${l(t)}"`:""}>${l(o)} <a href="${l(n)}" target="_blank" rel="noopener" referrerpolicy="origin">${l(a)}</a></span>`}function p(e,o,a){let n=e.indexOf(o),t=e.indexOf(a);return n!==-1&&t!==-1&&t>n}function g(e,o,a,n){let t=e.indexOf(o),r=e.indexOf(a);return e.slice(0,t)+n+e.slice(r+a.length)}function A(e,o){let a=`${i}
|
|
4
|
-
${$(o)}
|
|
5
|
-
${s}`,n;if(p(e,i,s))n=g(e,i,s,a);else{let t=/<head\b[^>]*>/i.exec(e);if(t){let r=t.index+t[0].length;n=`${e.slice(0,r)}
|
|
6
|
-
${a}${e.slice(r)}`}else n=`${a}
|
|
7
|
-
${e}`}if(o.backlink){let t=`${c}
|
|
8
|
-
${b(o.backlink)}
|
|
9
|
-
${_}`;if(p(n,c,_))n=g(n,c,_,t);else{let r=/<\/body\s*>/i.exec(n);r?n=`${n.slice(0,r.index)}${t}
|
|
10
|
-
${n.slice(r.index)}`:n=`${n}
|
|
11
|
-
${t}`}}return n}export{i as a,s as b,c,_ as d,v as e,$ as f,b as g,A as h};
|