Skip to content

Commit c0c5946

Browse files
committed
docs
1 parent 1155035 commit c0c5946

5 files changed

Lines changed: 58 additions & 16 deletions

File tree

‎packages/docs/src/components/Navbar.svelte‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import ChangelogMenu from "$components/ChangelogMenu.svelte"
1111
import DiscountCountdown from "$components/DiscountCountdown.svelte"
1212
import { track } from "$lib/analytics.svelte.js"
13-
import { fetchActiveDiscount } from "$lib/storeDiscount.js"
13+
import { fetchActiveDiscount, getDiscountNavbarTarget } from "$lib/storeDiscount.js"
1414
1515
import { t } from "$lib/i18n.svelte.js"
1616
@@ -90,8 +90,11 @@
9090
9191
const hasText = (value) => typeof value === "string" && value.length > 0
9292
const activeDiscountExpiresAt = $derived(activeDiscount?.data?.attributes?.expires_at)
93+
const activeDiscountNavbarTarget = $derived(getDiscountNavbarTarget(activeDiscount))
9394
const shouldShowCountdownTooltip = (item) =>
94-
item.countdown && activeDiscountExpiresAt && !$page.url.pathname.startsWith("/store/")
95+
item.countdown === activeDiscountNavbarTarget &&
96+
activeDiscountExpiresAt &&
97+
!matchesActivePath(item)
9598
const githubStarsLabel = $derived.by(() => {
9699
if (!Number.isFinite(stargazersCount)) return null
97100

‎packages/docs/src/lib/data/navigation.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ navbar:
77
icon: '<svg class="size-4" width="18" height="18" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 29H6V43H20V29Z" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="butt" stroke-linejoin="bevel"/><path d="M24 4L34 21H14L24 4Z" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="butt" stroke-linejoin="bevel"/><path d="M36 44C40.4183 44 44 40.4183 44 36C44 31.5817 40.4183 28 36 28C31.5817 28 28 31.5817 28 36C28 40.4183 31.5817 44 36 44Z" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="butt" stroke-linejoin="bevel"/></svg>'
88
- name: "Templates"
99
href: "/store/"
10-
countdown: true
10+
countdown: "templates"
1111
icon: '<svg class="size-4" width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><g stroke="currentColor" fill="none" stroke-linejoin="miter" stroke-linecap="butt"><line x1="3" y1="11" x2="29" y2="11" fill="none" stroke-miterlimit="10" stroke-width="2.5"></line><line x1="12" y1="11" x2="12" y2="29" fill="none" stroke-miterlimit="10" stroke-width="2.5"></line><path d="m26,29H6c-1.657,0-3-1.343-3-3V6c0-1.657,1.343-3,3-3h20c1.657,0,3,1.343,3,3v20c0,1.657-1.343,3-3,3Z" fill="none" stroke-linecap="square" stroke-miterlimit="10" stroke-width="2.5"></path></g></svg>'
1212
- name: "MCP"
1313
href: "/blueprint/"
14+
countdown: "blueprint"
1415
icon: '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" class="size-4" viewBox="0 0 195 195" fill="none"><path d="M25 97.8528L92.8822 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="currentColor" stroke-width="15"></path><path d="M76.2652 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="currentColor" stroke-width="15"></path><path d="M109.853 46.9411L59.6482 97.1457C50.2756 106.518 50.2756 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2167 140.459 93.5893 131.087L143.794 80.8822" stroke="currentColor" stroke-width="15"></path></svg>'
1516
- {}
1617
- name: "More"

‎packages/docs/src/lib/storeDiscount.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export const discountDateFormat = {
77
second: "2-digit",
88
}
99

10+
const blueprintProductIds = [
11+
"prod_5E7U1fS3URoEtdjqJr3R9d",
12+
"prod_7bSjj3UImBhfsYHclXQHt4",
13+
"prod_4GWzcIFPubIXjTBvzo9pKA",
14+
"prod_4EC2CMwyCoPAeJ6GhKabZd",
15+
]
16+
1017
export function isDiscountValid(discount) {
1118
if (discount?.data?.attributes?.expires_at) {
1219
const expiresAt = new Date(discount.data.attributes.expires_at).toISOString()
@@ -61,3 +68,12 @@ export function isDiscountApplicableToProduct(discount, productIds) {
6168
if (!appliesTo?.length) return true
6269
return appliesTo.some((id) => productIds.includes(id))
6370
}
71+
72+
export function isDiscountApplicableToBlueprint(discount) {
73+
return isDiscountApplicableToProduct(discount, blueprintProductIds)
74+
}
75+
76+
export function getDiscountNavbarTarget(discount) {
77+
if (!discount) return null
78+
return isDiscountApplicableToBlueprint(discount) ? "blueprint" : "templates"
79+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { getDiscountNavbarTarget, isDiscountApplicableToBlueprint } from "./storeDiscount.js"
3+
4+
const discountFor = (productIds) => ({
5+
data: {
6+
attributes: {
7+
applies_to_products: productIds,
8+
},
9+
},
10+
})
11+
12+
describe("discount navbar target", () => {
13+
test("targets Blueprint when the discount applies to a Blueprint product", () => {
14+
const discount = discountFor(["prod_store", "prod_4EC2CMwyCoPAeJ6GhKabZd"])
15+
16+
expect(isDiscountApplicableToBlueprint(discount)).toBe(true)
17+
expect(getDiscountNavbarTarget(discount)).toBe("blueprint")
18+
})
19+
20+
test("targets Templates when the discount does not apply to Blueprint", () => {
21+
const discount = discountFor(["prod_store"])
22+
23+
expect(isDiscountApplicableToBlueprint(discount)).toBe(false)
24+
expect(getDiscountNavbarTarget(discount)).toBe("templates")
25+
})
26+
27+
test("treats a discount without product restrictions as applicable to Blueprint", () => {
28+
expect(getDiscountNavbarTarget(discountFor([]))).toBe("blueprint")
29+
})
30+
31+
test("has no navbar target when there is no discount", () => {
32+
expect(getDiscountNavbarTarget(null)).toBeNull()
33+
})
34+
})

‎packages/docs/src/routes/(routes)/blueprint/+page.svelte‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66
import { onMount, tick } from "svelte"
77
import { fade, fly } from "svelte/transition"
88
import { t } from "$lib/i18n.svelte.js"
9+
import { isDiscountApplicableToBlueprint } from "$lib/storeDiscount.js"
910
1011
// Dynamic card copy also appears in an excluded blog route; keep it registered here.
1112
// $t("Installing daisyUI")
1213
1314
const checkoutUrl = "/blueprint/checkout/"
1415
15-
const blueprintProductIds = [
16-
"prod_5E7U1fS3URoEtdjqJr3R9d",
17-
"prod_7bSjj3UImBhfsYHclXQHt4",
18-
"prod_4GWzcIFPubIXjTBvzo9pKA",
19-
"prod_4EC2CMwyCoPAeJ6GhKabZd",
20-
]
21-
2216
const pricingPlans = [
2317
{
2418
slug: "monthly",
@@ -995,12 +989,6 @@
995989
return Boolean(expiresAt && new Date(expiresAt).toISOString() > currentDate)
996990
}
997991
998-
const isDiscountApplicableToBlueprint = (discount) => {
999-
const appliesTo = discount?.data?.attributes?.applies_to_products
1000-
if (!appliesTo?.length) return true
1001-
return appliesTo.some((id) => blueprintProductIds.includes(id))
1002-
}
1003-
1004992
const fetchDiscount = (async () => {
1005993
try {
1006994
const [shorttimeDiscountResponse, specialDiscountResponse] = await Promise.all([

0 commit comments

Comments
 (0)