@amulet-laboratories/rig-nuxt 0.3.0 → 0.4.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/package.json +2 -2
- package/src/module.ts +37 -1
- package/src/runtime/components/content/ArticleHeader.vue +16 -0
- package/src/runtime/components/content/CategoryIcon.vue +453 -0
- package/src/runtime/components/content/ContentBestForIndexPage.vue +80 -0
- package/src/runtime/components/content/ContentBestForPersonaPage.vue +120 -0
- package/src/runtime/components/content/ContentCompareIndexPage.vue +96 -0
- package/src/runtime/components/content/ContentComparePage.vue +207 -0
- package/src/runtime/components/content/ContentHomePage.vue +221 -0
- package/src/runtime/components/content/EditorialSidebar.vue +27 -0
- package/src/runtime/components/content/NetworkArticles.vue +1 -1
- package/src/runtime/components/content/NetworkLinks.vue +1 -1
- package/src/runtime/components/content/ProductCardWrapper.vue +58 -2
- package/src/runtime/components/layout/NetworkFooter.vue +6 -1
- package/src/runtime/composables/useArticleSeo.ts +5 -1
- package/src/runtime/composables/useStructuredData.ts +92 -17
- package/src/runtime/plugins/fathom.client.ts +2 -0
- package/src/runtime/plugins/sentry.client.ts +1 -0
- package/src/runtime/server/api/newsletter/subscribe.post.ts +1 -0
- package/src/runtime/server/routes/feed.xml.ts +2 -0
- package/src/runtime/server/routes/sitemap.xml.ts +3 -0
- package/src/runtime/server/utils/injectAffiliateTag.ts +35 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
2
3
|
import { useAsyncData } from '#imports'
|
|
3
4
|
import { useFathom } from '@amulet-laboratories/rig'
|
|
4
5
|
import { useProducts } from '../../composables/useProducts'
|
|
@@ -14,6 +15,50 @@ const { data: product, status } = await useAsyncData(`product-${props.slug}`, ()
|
|
|
14
15
|
|
|
15
16
|
const { trackAffiliateClick } = useFathom()
|
|
16
17
|
|
|
18
|
+
interface Retailer {
|
|
19
|
+
name: string
|
|
20
|
+
url: string
|
|
21
|
+
commission_rate: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const bestRetailer = computed<Retailer | null>(() => {
|
|
25
|
+
if (!product.value) return null
|
|
26
|
+
|
|
27
|
+
const candidates: Retailer[] = []
|
|
28
|
+
|
|
29
|
+
if (product.value.amazon?.url) {
|
|
30
|
+
candidates.push({
|
|
31
|
+
name: 'Amazon',
|
|
32
|
+
url: product.value.amazon.url,
|
|
33
|
+
commission_rate: product.value.amazon.commission_rate || '0%',
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (product.value.alt_retailers?.length) {
|
|
38
|
+
for (const retailer of product.value.alt_retailers) {
|
|
39
|
+
if (retailer.url) candidates.push(retailer as Retailer)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!candidates.length) return null
|
|
44
|
+
|
|
45
|
+
return candidates.sort((a, b) => {
|
|
46
|
+
const rateA = parseFloat(a.commission_rate) || 0
|
|
47
|
+
const rateB = parseFloat(b.commission_rate) || 0
|
|
48
|
+
return rateB - rateA
|
|
49
|
+
})[0]
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const amazonFallback = computed<Retailer | null>(() => {
|
|
53
|
+
if (!product.value?.amazon?.url) return null
|
|
54
|
+
if (bestRetailer.value?.name === 'Amazon') return null
|
|
55
|
+
return {
|
|
56
|
+
name: 'Amazon',
|
|
57
|
+
url: product.value.amazon.url,
|
|
58
|
+
commission_rate: product.value.amazon.commission_rate || '0%',
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
17
62
|
function onAffiliateClick() {
|
|
18
63
|
trackAffiliateClick(props.slug)
|
|
19
64
|
}
|
|
@@ -66,13 +111,24 @@ function onAffiliateClick() {
|
|
|
66
111
|
</div>
|
|
67
112
|
<div data-rig-product-card-footer>
|
|
68
113
|
<a
|
|
69
|
-
|
|
114
|
+
v-if="bestRetailer"
|
|
115
|
+
:href="bestRetailer.url"
|
|
70
116
|
target="_blank"
|
|
71
117
|
rel="nofollow noopener sponsored"
|
|
72
118
|
data-rig-product-card-link
|
|
73
119
|
@click="onAffiliateClick"
|
|
74
120
|
>
|
|
75
|
-
Check price on
|
|
121
|
+
Check price on {{ bestRetailer.name }}
|
|
122
|
+
</a>
|
|
123
|
+
<a
|
|
124
|
+
v-if="amazonFallback"
|
|
125
|
+
:href="amazonFallback.url"
|
|
126
|
+
target="_blank"
|
|
127
|
+
rel="nofollow noopener sponsored"
|
|
128
|
+
data-rig-product-card-link-secondary
|
|
129
|
+
@click="onAffiliateClick"
|
|
130
|
+
>
|
|
131
|
+
Also on Amazon
|
|
76
132
|
</a>
|
|
77
133
|
</div>
|
|
78
134
|
</div>
|
|
@@ -23,7 +23,12 @@ const otherSites = computed(() => props.sites.filter((s) => s.name !== currentSi
|
|
|
23
23
|
<p data-rig-network-footer-label>From our network</p>
|
|
24
24
|
<ul data-rig-network-footer-list>
|
|
25
25
|
<li v-for="site in otherSites" :key="site.name">
|
|
26
|
-
<a
|
|
26
|
+
<a
|
|
27
|
+
:href="site.url"
|
|
28
|
+
target="_blank"
|
|
29
|
+
rel="noopener noreferrer"
|
|
30
|
+
data-rig-network-footer-link
|
|
31
|
+
>
|
|
27
32
|
<span data-rig-network-footer-name>{{ site.name }}</span>
|
|
28
33
|
<span data-rig-network-footer-tagline>{{ site.tagline }}</span>
|
|
29
34
|
</a>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useRuntimeConfig, useRoute, useSeoMeta, useHead } from 'nuxt/app'
|
|
2
|
+
|
|
1
3
|
export interface SeoMetaOptions {
|
|
2
4
|
title: string
|
|
3
5
|
description?: string
|
|
@@ -7,7 +9,9 @@ export interface SeoMetaOptions {
|
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export const useArticleSeo = (options: SeoMetaOptions) => {
|
|
10
|
-
const
|
|
12
|
+
const config = useRuntimeConfig()
|
|
13
|
+
const siteUrl = (config.public?.siteUrl as string) || ''
|
|
14
|
+
const siteName = (config.public?.siteName as string) || ''
|
|
11
15
|
const route = useRoute()
|
|
12
16
|
const canonicalUrl = `${siteUrl}${route.path}`
|
|
13
17
|
const ogImage = options.ogImage || `${siteUrl}/og-default.svg`
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import { useRuntimeConfig, useRoute, useHead } from 'nuxt/app'
|
|
2
|
+
|
|
3
|
+
export interface StructuredDataProduct {
|
|
4
|
+
slug: string
|
|
5
|
+
name: string
|
|
6
|
+
brand?: string
|
|
7
|
+
image_url?: string
|
|
8
|
+
rating?: number
|
|
9
|
+
price_range?: string
|
|
10
|
+
amazon?: { url?: string }
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
export interface StructuredDataPage {
|
|
2
14
|
title: string
|
|
3
15
|
description: string
|
|
@@ -10,14 +22,59 @@ export interface StructuredDataPage {
|
|
|
10
22
|
width: number
|
|
11
23
|
height: number
|
|
12
24
|
}
|
|
25
|
+
/** One of: 'Article' | 'HowTo' | 'Review' | 'ItemList' (auto-picked if products present). */
|
|
13
26
|
schema?: string
|
|
14
27
|
rating?: number
|
|
15
28
|
price?: string
|
|
16
29
|
faq?: Array<{ question: string; answer: string }>
|
|
30
|
+
/**
|
|
31
|
+
* Affiliate products referenced by the article. When passed, emits real
|
|
32
|
+
* Product entities inside the appropriate parent schema (Review for a single
|
|
33
|
+
* primary product, ItemList for roundups). Single biggest organic-CTR
|
|
34
|
+
* multiplier for affiliate content — Google surfaces star ratings + prices
|
|
35
|
+
* in the SERP when these are present.
|
|
36
|
+
*/
|
|
37
|
+
products?: StructuredDataProduct[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function productSchema(p: StructuredDataProduct, siteUrl: string) {
|
|
41
|
+
const node: Record<string, unknown> = {
|
|
42
|
+
'@type': 'Product',
|
|
43
|
+
name: p.name,
|
|
44
|
+
}
|
|
45
|
+
if (p.brand) node.brand = { '@type': 'Brand', name: p.brand }
|
|
46
|
+
if (p.image_url)
|
|
47
|
+
node.image = p.image_url.startsWith('http') ? p.image_url : `${siteUrl}${p.image_url}`
|
|
48
|
+
if (p.rating) {
|
|
49
|
+
node.aggregateRating = {
|
|
50
|
+
'@type': 'AggregateRating',
|
|
51
|
+
ratingValue: p.rating,
|
|
52
|
+
bestRating: 5,
|
|
53
|
+
ratingCount: 1,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (p.amazon?.url) {
|
|
57
|
+
node.offers = {
|
|
58
|
+
'@type': 'Offer',
|
|
59
|
+
url: p.amazon.url,
|
|
60
|
+
priceCurrency: 'USD',
|
|
61
|
+
...(p.price_range ? { price: extractMinPrice(p.price_range) } : {}),
|
|
62
|
+
availability: 'https://schema.org/InStock',
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return node
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function extractMinPrice(range: string): string | undefined {
|
|
69
|
+
// "$169-$199" -> "169"
|
|
70
|
+
const m = range.match(/\$?(\d+(?:\.\d+)?)/)
|
|
71
|
+
return m ? m[1] : undefined
|
|
17
72
|
}
|
|
18
73
|
|
|
19
74
|
export const useStructuredData = (page: StructuredDataPage) => {
|
|
20
|
-
const
|
|
75
|
+
const config = useRuntimeConfig()
|
|
76
|
+
const siteUrl = (config.public?.siteUrl as string) || ''
|
|
77
|
+
const siteName = (config.public?.siteName as string) || ''
|
|
21
78
|
const route = useRoute()
|
|
22
79
|
const url = `${siteUrl}${route.path}`
|
|
23
80
|
|
|
@@ -54,33 +111,51 @@ export const useStructuredData = (page: StructuredDataPage) => {
|
|
|
54
111
|
baseData.dateModified = page.updatedAt
|
|
55
112
|
}
|
|
56
113
|
|
|
57
|
-
|
|
114
|
+
// Auto-pick schema: explicit > products-driven > Article default.
|
|
115
|
+
// ≥2 products on an article without explicit schema → ItemList (roundup).
|
|
116
|
+
// 1 product or explicit Review → Review.
|
|
117
|
+
let schemaType = page.schema ?? 'Article'
|
|
118
|
+
const productCount = page.products?.length ?? 0
|
|
119
|
+
if (!page.schema && productCount >= 2) schemaType = 'ItemList'
|
|
58
120
|
|
|
59
|
-
switch (
|
|
60
|
-
case 'Review':
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
121
|
+
switch (schemaType) {
|
|
122
|
+
case 'Review': {
|
|
123
|
+
baseData['@type'] = 'Review'
|
|
124
|
+
const primary = page.products?.[0]
|
|
125
|
+
baseData.itemReviewed = primary
|
|
126
|
+
? productSchema(primary, siteUrl)
|
|
127
|
+
: { '@type': 'Product', name: page.title }
|
|
128
|
+
const rating = page.rating ?? primary?.rating
|
|
129
|
+
if (rating) {
|
|
67
130
|
baseData.reviewRating = {
|
|
68
131
|
'@type': 'Rating',
|
|
69
|
-
ratingValue:
|
|
132
|
+
ratingValue: rating,
|
|
70
133
|
bestRating: 5,
|
|
71
134
|
}
|
|
72
135
|
}
|
|
73
136
|
break
|
|
74
|
-
|
|
75
|
-
|
|
137
|
+
}
|
|
138
|
+
case 'ItemList': {
|
|
139
|
+
baseData['@type'] = 'ItemList'
|
|
140
|
+
baseData.name = page.title
|
|
141
|
+
baseData.numberOfItems = productCount
|
|
142
|
+
baseData.itemListElement = (page.products ?? []).map((p, i) => ({
|
|
143
|
+
'@type': 'ListItem',
|
|
144
|
+
position: i + 1,
|
|
145
|
+
item: productSchema(p, siteUrl),
|
|
146
|
+
}))
|
|
147
|
+
break
|
|
148
|
+
}
|
|
149
|
+
case 'HowTo': {
|
|
150
|
+
baseData['@type'] = 'HowTo'
|
|
76
151
|
baseData.name = page.title
|
|
77
152
|
break
|
|
78
|
-
|
|
79
|
-
|
|
153
|
+
}
|
|
154
|
+
default: {
|
|
155
|
+
baseData['@type'] = 'Article'
|
|
156
|
+
}
|
|
80
157
|
}
|
|
81
158
|
|
|
82
|
-
baseData['@type'] = schemaType
|
|
83
|
-
|
|
84
159
|
const scripts: Array<{ type: string; innerHTML: string }> = [
|
|
85
160
|
{
|
|
86
161
|
type: 'application/ld+json',
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, existsSync } from 'node:fs'
|
|
2
2
|
import { join, resolve } from 'node:path'
|
|
3
3
|
import { parse } from 'yaml'
|
|
4
|
+
import { defineEventHandler } from 'h3'
|
|
5
|
+
import { useRuntimeConfig } from 'nitropack/runtime'
|
|
6
|
+
import { queryCollection } from '@nuxt/content/nitro'
|
|
4
7
|
|
|
5
8
|
export default defineEventHandler(async (event) => {
|
|
6
9
|
const config = useRuntimeConfig()
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
+
import { useRuntimeConfig } from 'nitropack/runtime'
|
|
2
|
+
|
|
3
|
+
const PLACEHOLDER_TAG = 'YOURTAG-20'
|
|
4
|
+
let warnedMissingTag = false
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
|
-
* Replaces placeholder affiliate
|
|
3
|
-
*
|
|
7
|
+
* Replaces the placeholder affiliate tag in a product's Amazon URL with the
|
|
8
|
+
* real per-site tag from runtime config (NUXT_AMAZON_AFFILIATE_TAG).
|
|
9
|
+
*
|
|
10
|
+
* When no tag is configured, the placeholder is STRIPPED rather than shipped:
|
|
11
|
+
* a live URL containing `tag=YOURTAG-20` earns no commission and reads as
|
|
12
|
+
* broken, so we emit a clean (un-attributed) Amazon link — and warn once in
|
|
13
|
+
* dev — instead of leaking the placeholder to readers.
|
|
4
14
|
*/
|
|
5
15
|
export function injectAffiliateTag(product) {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
16
|
+
const amazonTag = useRuntimeConfig().amazonAffiliateTag || ''
|
|
17
|
+
const url = product.amazon?.url
|
|
18
|
+
|
|
19
|
+
if (!url || !url.includes(PLACEHOLDER_TAG)) return product
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
const amazon = { ...product.amazon }
|
|
10
22
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
if (amazonTag) {
|
|
24
|
+
amazon.url = url.replace(PLACEHOLDER_TAG, amazonTag)
|
|
25
|
+
} else {
|
|
26
|
+
// No NUXT_AMAZON_AFFILIATE_TAG set — never expose the literal placeholder.
|
|
27
|
+
try {
|
|
28
|
+
const cleaned = new URL(url)
|
|
29
|
+
cleaned.searchParams.delete('tag')
|
|
30
|
+
amazon.url = cleaned.toString()
|
|
31
|
+
} catch {
|
|
32
|
+
amazon.url = url.replace(PLACEHOLDER_TAG, '')
|
|
33
|
+
}
|
|
34
|
+
if (!warnedMissingTag && process.env.NODE_ENV !== 'production') {
|
|
35
|
+
warnedMissingTag = true
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.warn(
|
|
38
|
+
'[injectAffiliateTag] NUXT_AMAZON_AFFILIATE_TAG is not set — Amazon links render un-attributed (no commission). Set a per-site tag before production.',
|
|
39
|
+
)
|
|
40
|
+
}
|
|
14
41
|
}
|
|
15
42
|
|
|
16
43
|
return { ...product, amazon }
|