create-bearminion 1.20.0 → 1.21.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/template/AGENTS.md +1 -1
  5. package/template/README.md +5 -5
  6. package/template/astro.config.ts +16 -4
  7. package/template/bearminion.lock.json +80 -132
  8. package/template/content/pages/about.json +2 -2
  9. package/template/content/pages/index.json +23 -237
  10. package/template/content/site.json +2 -10
  11. package/template/package.json +1 -1
  12. package/template/src/components/organisms/EntryList.astro +83 -0
  13. package/template/src/components/organisms/Pagination.astro +56 -0
  14. package/template/src/components/sections/components.gen.ts +0 -10
  15. package/template/src/components/sections/definitions.gen.ts +0 -10
  16. package/template/src/components/sections/faq/definition.ts +2 -2
  17. package/template/src/components/sections/media/Media.astro +2 -2
  18. package/template/src/components/sections/media/MediaPlayer.astro +2 -2
  19. package/template/src/components/sections/shared.ts +3 -0
  20. package/template/src/components/sections/text-image/definition.ts +1 -1
  21. package/template/src/content.config.ts +4 -2
  22. package/template/src/dev/section-preview.astro +53 -0
  23. package/template/src/env.d.ts +2 -0
  24. package/template/src/layouts/Base.astro +19 -12
  25. package/template/src/lib/content.ts +57 -2
  26. package/template/src/lib/editing.ts +6 -0
  27. package/template/src/lib/sitemap.ts +14 -2
  28. package/template/src/pages/[...slug].astro +30 -16
  29. package/template/src/components/sections/contact/Contact.astro +0 -231
  30. package/template/src/components/sections/contact/Contact.stories.ts +0 -16
  31. package/template/src/components/sections/contact/definition.ts +0 -52
  32. package/template/src/components/sections/contact/form.ts +0 -313
  33. package/template/src/components/sections/contact/wireframe.ts +0 -15
  34. package/template/src/components/sections/logo-strip/LogoStrip.astro +0 -110
  35. package/template/src/components/sections/logo-strip/LogoStrip.stories.ts +0 -20
  36. package/template/src/components/sections/logo-strip/definition.ts +0 -30
  37. package/template/src/components/sections/logo-strip/wireframe.ts +0 -11
  38. package/template/src/components/sections/pricing/Pricing.astro +0 -210
  39. package/template/src/components/sections/pricing/Pricing.stories.ts +0 -16
  40. package/template/src/components/sections/pricing/definition.ts +0 -62
  41. package/template/src/components/sections/pricing/wireframe.ts +0 -18
  42. package/template/src/components/sections/stats/Stats.astro +0 -110
  43. package/template/src/components/sections/stats/Stats.stories.ts +0 -16
  44. package/template/src/components/sections/stats/definition.ts +0 -41
  45. package/template/src/components/sections/stats/wireframe.ts +0 -15
  46. package/template/src/components/sections/testimonials/Testimonials.astro +0 -172
  47. package/template/src/components/sections/testimonials/Testimonials.stories.ts +0 -19
  48. package/template/src/components/sections/testimonials/definition.ts +0 -42
  49. package/template/src/components/sections/testimonials/wireframe.ts +0 -21
  50. package/template/src/lib/contact-form.ts +0 -97
  51. package/template/src/lib/hidden-text.ts +0 -32
@@ -1,19 +0,0 @@
1
- import { sectionArgTypes } from '../../../stories/options'
2
- import { sectionEntry } from '../../../stories/sample'
3
- import Testimonials from './Testimonials.astro'
4
-
5
- const entry = sectionEntry('testimonials')
6
-
7
- export default {
8
- title: 'Sections/Testimonials',
9
- component: Testimonials,
10
- parameters: { layout: 'fullscreen' },
11
- argTypes: sectionArgTypes('testimonials'),
12
- }
13
-
14
- export const Home = {
15
- args: {
16
- section: entry.section,
17
- index: entry.index,
18
- },
19
- }
@@ -1,42 +0,0 @@
1
- import { z } from 'zod'
2
- import { defineSection, imageSchema, richTextSchema, textSchema, withEmphasis } from 'bearminion'
3
- import { accent, eyebrow, heading } from '../shared'
4
- import { testimonialsWireframe } from './wireframe'
5
-
6
- export const testimonialsVariants = ['grid', 'featured', 'carousel'] as const
7
-
8
- export const testimonialItemSchema = z
9
- .object({
10
- quote: richTextSchema,
11
- name: textSchema,
12
- role: textSchema.optional(),
13
- image: imageSchema.optional(),
14
- })
15
- .strict()
16
-
17
- export const testimonialsSchema = withEmphasis({
18
- eyebrow,
19
- heading,
20
- items: z.array(testimonialItemSchema).min(1),
21
- })
22
-
23
- export type TestimonialItem = z.infer<typeof testimonialItemSchema>
24
- export type TestimonialsProps = z.infer<typeof testimonialsSchema>
25
-
26
- export const testimonials = defineSection({
27
- type: 'testimonials',
28
- label: 'Testimonials',
29
- description: 'Quotes with a name and avatar.',
30
- schema: testimonialsSchema,
31
- defaults: {
32
- eyebrow: 'Testimonials',
33
- heading: 'What people say',
34
- marks: accent('What people say', 'people say'),
35
- items: [{ quote: 'A short quote from a happy customer, in their own words.', name: 'Alex Morgan', role: 'Role, Company' }],
36
- },
37
- variants: testimonialsVariants,
38
- defaultVariant: 'grid',
39
- optional: { props: ['eyebrow', 'heading'], items: { items: ['role', 'image'] } },
40
- counts: { items: { recommended: 3 } },
41
- wireframe: testimonialsWireframe,
42
- })
@@ -1,21 +0,0 @@
1
- import { defineWireframe } from 'bearminion'
2
-
3
- /** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
4
- export const testimonialsWireframe = defineWireframe([
5
- [8, 12, 36, 8, 'title'],
6
- [8, 32, 26, 56, 'card'],
7
- [37, 32, 26, 56, 'card'],
8
- [66, 32, 26, 56, 'card'],
9
- [11, 40, 20, 4, 'text'],
10
- [40, 40, 20, 4, 'text'],
11
- [69, 40, 20, 4, 'text'],
12
- [11, 48, 16, 4, 'text'],
13
- [40, 48, 16, 4, 'text'],
14
- [69, 48, 16, 4, 'text'],
15
- [11, 70, 7, 12, 'avatar'],
16
- [40, 70, 7, 12, 'avatar'],
17
- [69, 70, 7, 12, 'avatar'],
18
- [20, 74, 9, 4, 'title'],
19
- [49, 74, 9, 4, 'title'],
20
- [78, 74, 9, 4, 'title'],
21
- ])
@@ -1,97 +0,0 @@
1
- import type { FormResult, FormSubmission } from 'bearminion'
2
-
3
- /**
4
- * The Contact form's rules, apart from the page: what is sent, how an answer is read, and which submissions a
5
- * person could not have made. `components/sections/contact/form.ts` wires them to the DOM.
6
- */
7
-
8
- /** The spam-trap field. People never see it; many bots fill every field they find. Formspree uses the same name. */
9
- export const HONEYPOT_FIELD = '_gotcha'
10
-
11
- /** The field Cloudflare Turnstile's token is sent in, which `defineForm` from `bearminion/forms` checks on the server. */
12
- export const TURNSTILE_FIELD = 'cf-turnstile-response'
13
-
14
- /** A person needs longer than this to type a message. A submit sooner than this after the form appeared is a script. */
15
- export const MIN_FILL_MS = 1500
16
-
17
- /** Why a submission is dropped without being sent, or `null` when it should go out. */
18
- export function botVerdict(trap: string, openedAt: number, now: number): 'honeypot' | 'too-fast' | null {
19
- if (trap.trim() !== '') return 'honeypot'
20
- if (now - openedAt < MIN_FILL_MS) return 'too-fast'
21
- return null
22
- }
23
-
24
- /** The fields of a form as strings, plus where they came from. The trap field and any file input are left out. */
25
- export function collectSubmission(entries: Iterable<[string, unknown]>, formId: string, page: string): FormSubmission {
26
- const submission: FormSubmission = { formId, page }
27
- for (const [name, value] of entries) {
28
- if (name === HONEYPOT_FIELD || name === 'formId' || name === 'page' || typeof value !== 'string') continue
29
- submission[name] = value
30
- }
31
- return submission
32
- }
33
-
34
- /** Where every Contact form posts. The site's own handler, `src/forms/contact.ts`, answers here. */
35
- export const FORM_ENDPOINT = '/api/contact'
36
-
37
- export interface FormRequest {
38
- url: string
39
- init: RequestInit
40
- }
41
-
42
- /** The request: the submission as JSON. The handler (`defineForm`) reads it and answers with JSON. */
43
- export function buildRequest(submission: FormSubmission): FormRequest {
44
- return {
45
- url: FORM_ENDPOINT,
46
- init: {
47
- method: 'POST',
48
- headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
49
- body: JSON.stringify(submission),
50
- },
51
- }
52
- }
53
-
54
- const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value)
55
- const text = (value: unknown): string | undefined => (typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined)
56
-
57
- /** Field errors from `fieldErrors: { email: '…' }`. */
58
- function readFieldErrors(body: Record<string, unknown>): Record<string, string> | undefined {
59
- if (!isRecord(body.fieldErrors)) return undefined
60
- const found: Record<string, string> = {}
61
- for (const [name, message] of Object.entries(body.fieldErrors)) {
62
- const line = text(message)
63
- if (line) found[name] = line
64
- }
65
- return Object.keys(found).length > 0 ? found : undefined
66
- }
67
-
68
- /** What to tell a visitor when the endpoint gave no message of its own. */
69
- function fallbackError(status: number): string {
70
- if (status === 429) return 'Too many messages in a short time. Wait a minute and try again.'
71
- if (status >= 500) return 'The server had a problem. Try again in a moment.'
72
- return 'The message was not accepted. Check the form and try again.'
73
- }
74
-
75
- /**
76
- * Reads the handler's answer. The HTTP status decides: a 2xx is a success unless the body says `ok: false`. `body` is
77
- * the parsed JSON, or `undefined` when there was none, which a 2xx treats as success.
78
- */
79
- export function readResponse(status: number, body: unknown): FormResult {
80
- const record = isRecord(body) ? body : {}
81
- if (status >= 200 && status < 300 && record.ok !== false) {
82
- const note = record.ok === true ? text(record.message) : undefined
83
- return note ? { ok: true, message: note } : { ok: true }
84
- }
85
- const fieldErrors = readFieldErrors(record)
86
- const error = text(record.error) ?? text(record.message) ?? fallbackError(status >= 200 && status < 300 ? 400 : status)
87
- return fieldErrors ? { ok: false, error, fieldErrors } : { ok: false, error }
88
- }
89
-
90
- /** Shown when the request never got an answer: offline or blocked. */
91
- export const NETWORK_ERROR = 'The message could not be sent. Check your connection and try again.'
92
-
93
- /** Shown when the visitor sends before Turnstile has given its token. */
94
- export const TURNSTILE_PENDING = 'The spam check is still running. Try again in a moment.'
95
-
96
- /** Shown when Turnstile could not run: its script is blocked, or it reported an error. */
97
- export const TURNSTILE_FAILED = 'The spam check could not run. Reload the page, turn off any blocker for this site, and try again.'
@@ -1,32 +0,0 @@
1
- /**
2
- * Keeps a contact detail (an email address, a phone number) out of the page's HTML, so a crawler that only reads markup
3
- * does not harvest it. `hide` runs at build time and `reveal` in the browser.
4
- *
5
- * This is obfuscation, not encryption: the page has to show the value, so a browser, and any crawler that runs the
6
- * page's script, can recover it. It stops the scrapers that match `@` and digits in the HTML, which is most of them.
7
- */
8
-
9
- const KEY = 'bearminion'
10
-
11
- function scramble(bytes: Uint8Array): Uint8Array {
12
- return bytes.map((byte, index) => byte ^ (KEY.charCodeAt(index % KEY.length) & 0xff))
13
- }
14
-
15
- /** `value` as a short ASCII string that contains none of its characters. */
16
- export function hide(value: string): string {
17
- const scrambled = scramble(new TextEncoder().encode(value))
18
- let binary = ''
19
- for (const byte of scrambled) binary += String.fromCharCode(byte)
20
- return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
21
- }
22
-
23
- /** The value `hide` was given. */
24
- export function reveal(hidden: string): string {
25
- const base64 = hidden.replace(/-/g, '+').replace(/_/g, '/')
26
- const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4))
27
- const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0))
28
- return new TextDecoder().decode(scramble(bytes))
29
- }
30
-
31
- /** What a visitor without JavaScript reads where the value would be. */
32
- export const HIDDEN_FALLBACK = 'Turn on JavaScript to see this, or use the form.'