@vdaluz/astro-affiliate 0.6.0 → 0.7.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 CHANGED
@@ -15,7 +15,7 @@ Alternatively, a pinned https tarball from a tag works too, with no registry inv
15
15
  ```jsonc
16
16
  // package.json
17
17
  "dependencies": {
18
- "@vdaluz/astro-affiliate": "https://github.com/vdaluz/astro-affiliate/archive/refs/tags/v0.6.0.tar.gz"
18
+ "@vdaluz/astro-affiliate": "https://github.com/vdaluz/astro-affiliate/archive/refs/tags/v0.7.0.tar.gz"
19
19
  }
20
20
  ```
21
21
 
@@ -159,6 +159,20 @@ fails the build. **Compliance by construction:** every program actually used by
159
159
  links in a post must be declared in that post's `affiliates:` frontmatter array, or the build
160
160
  fails with a clear error - there's no way to ship an affiliate link without its disclosure.
161
161
 
162
+ The plugin also writes the post's own catalog keys, in document order with duplicates removed,
163
+ to `affiliateKeys` in the page's frontmatter - useful for a consumer that wants to know "which
164
+ catalog items did this post actually link to" without re-parsing markdown (e.g. to seed a
165
+ related-products widget from a post's own links before falling back to other sources). It's
166
+ `undefined`, not an empty array, on a post with no affiliate links - read it as
167
+ `affiliateKeys ?? []`. Access it via Astro's `remarkPluginFrontmatter`:
168
+
169
+ ```astro
170
+ ---
171
+ const { remarkPluginFrontmatter } = await render(entry);
172
+ const usedKeys = remarkPluginFrontmatter.affiliateKeys ?? [];
173
+ ---
174
+ ```
175
+
162
176
  ## `.astro` pages (`<AffiliateLink>`)
163
177
 
164
178
  For gear pages or other non-markdown content:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vdaluz/astro-affiliate",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "FTC-compliant affiliate-link catalog resolver and disclosure components - proven in production on vdaluz.com and imperfectsystems.com.",
5
5
  "keywords": [
6
6
  "astro",
package/src/lib/remark.ts CHANGED
@@ -15,6 +15,7 @@ interface VFileWithAstroFrontmatter {
15
15
  astro?: {
16
16
  frontmatter?: {
17
17
  affiliates?: string[];
18
+ affiliateKeys?: string[];
18
19
  };
19
20
  };
20
21
  };
@@ -36,6 +37,11 @@ function collectAffiliateLinkNodes(node: MdastNode, out: MdastNode[]) {
36
37
  * `affiliates:` frontmatter (so `<AffiliateDisclosure>` knows to render it).
37
38
  * An unknown key, or a used program missing from frontmatter, fails the build.
38
39
  *
40
+ * Also writes the post's own affiliate catalog keys, in document order with
41
+ * duplicates removed, to `affiliateKeys` in the page's frontmatter (via
42
+ * `remarkPluginFrontmatter`) - undefined, not an empty array, on a post with
43
+ * no affiliate links, so a consumer should read it as `affiliateKeys ?? []`.
44
+ *
39
45
  * import { remarkAffiliate } from '@vdaluz/astro-affiliate/remark';
40
46
  *
41
47
  * export default defineConfig({
@@ -50,12 +56,14 @@ export function remarkAffiliate(config: AffiliateConfig) {
50
56
 
51
57
  const declaredAffiliates = file.data?.astro?.frontmatter?.affiliates ?? [];
52
58
  const usedPrograms = new Set<string>();
59
+ const usedKeys: string[] = [];
53
60
 
54
61
  for (const node of linkNodes) {
55
62
  const key = node.url!.slice(AFFILIATE_PREFIX.length);
56
63
  const { url, program } = resolveAffiliate(config, key);
57
64
  node.url = url;
58
65
  usedPrograms.add(program);
66
+ if (!usedKeys.includes(key)) usedKeys.push(key);
59
67
  }
60
68
 
61
69
  for (const program of usedPrograms) {
@@ -65,5 +73,10 @@ export function remarkAffiliate(config: AffiliateConfig) {
65
73
  );
66
74
  }
67
75
  }
76
+
77
+ file.data ??= {};
78
+ file.data.astro ??= {};
79
+ file.data.astro.frontmatter ??= {};
80
+ file.data.astro.frontmatter.affiliateKeys = usedKeys;
68
81
  };
69
82
  }