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.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/template/AGENTS.md +1 -1
- package/template/README.md +5 -5
- package/template/astro.config.ts +16 -4
- package/template/bearminion.lock.json +80 -132
- package/template/content/pages/about.json +2 -2
- package/template/content/pages/index.json +23 -237
- package/template/content/site.json +2 -10
- package/template/package.json +1 -1
- package/template/src/components/organisms/EntryList.astro +83 -0
- package/template/src/components/organisms/Pagination.astro +56 -0
- package/template/src/components/sections/components.gen.ts +0 -10
- package/template/src/components/sections/definitions.gen.ts +0 -10
- package/template/src/components/sections/faq/definition.ts +2 -2
- package/template/src/components/sections/media/Media.astro +2 -2
- package/template/src/components/sections/media/MediaPlayer.astro +2 -2
- package/template/src/components/sections/shared.ts +3 -0
- package/template/src/components/sections/text-image/definition.ts +1 -1
- package/template/src/content.config.ts +4 -2
- package/template/src/dev/section-preview.astro +53 -0
- package/template/src/env.d.ts +2 -0
- package/template/src/layouts/Base.astro +19 -12
- package/template/src/lib/content.ts +57 -2
- package/template/src/lib/editing.ts +6 -0
- package/template/src/lib/sitemap.ts +14 -2
- package/template/src/pages/[...slug].astro +30 -16
- package/template/src/components/sections/contact/Contact.astro +0 -231
- package/template/src/components/sections/contact/Contact.stories.ts +0 -16
- package/template/src/components/sections/contact/definition.ts +0 -52
- package/template/src/components/sections/contact/form.ts +0 -313
- package/template/src/components/sections/contact/wireframe.ts +0 -15
- package/template/src/components/sections/logo-strip/LogoStrip.astro +0 -110
- package/template/src/components/sections/logo-strip/LogoStrip.stories.ts +0 -20
- package/template/src/components/sections/logo-strip/definition.ts +0 -30
- package/template/src/components/sections/logo-strip/wireframe.ts +0 -11
- package/template/src/components/sections/pricing/Pricing.astro +0 -210
- package/template/src/components/sections/pricing/Pricing.stories.ts +0 -16
- package/template/src/components/sections/pricing/definition.ts +0 -62
- package/template/src/components/sections/pricing/wireframe.ts +0 -18
- package/template/src/components/sections/stats/Stats.astro +0 -110
- package/template/src/components/sections/stats/Stats.stories.ts +0 -16
- package/template/src/components/sections/stats/definition.ts +0 -41
- package/template/src/components/sections/stats/wireframe.ts +0 -15
- package/template/src/components/sections/testimonials/Testimonials.astro +0 -172
- package/template/src/components/sections/testimonials/Testimonials.stories.ts +0 -19
- package/template/src/components/sections/testimonials/definition.ts +0 -42
- package/template/src/components/sections/testimonials/wireframe.ts +0 -21
- package/template/src/lib/contact-form.ts +0 -97
- package/template/src/lib/hidden-text.ts +0 -32
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { GetStaticPaths } from 'astro'
|
|
3
|
+
import { sectionDefinitions, sectionOptions, sectionSchema, sectionTypes, type Page, type SectionType } from '../components/sections/definitions'
|
|
4
|
+
import SectionList from '../components/sections/SectionList.astro'
|
|
5
|
+
import Base from '../layouts/Base.astro'
|
|
6
|
+
import { getSite } from '../lib/content'
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* One section in one layout, with its default content and nothing around it: the live previews in the docs load this
|
|
10
|
+
* page in a frame. `astro dev` serves it at /section-preview/<section>/<variant>, like the variants gallery. The docs build adds
|
|
11
|
+
* the route to a build of this template (apps/docs/scripts/build-previews.mjs); a site's own build leaves it out.
|
|
12
|
+
*
|
|
13
|
+
* The frame's page changes the tone (`data-tone` on the section) and the light or dark theme (`data-theme` on <html>)
|
|
14
|
+
* in place, so one page per layout serves every combination.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Astro runs getStaticPaths on its own, before the rest of this script: everything it uses is inside it or imported.
|
|
18
|
+
export const getStaticPaths = (() =>
|
|
19
|
+
sectionTypes.flatMap((type) => {
|
|
20
|
+
const option = sectionOptions[type].find((candidate) => candidate.name === 'variant')
|
|
21
|
+
const variants = option?.type === 'enum' ? option.choices : []
|
|
22
|
+
// The address uses the section's directory name (`text-image`), as `npx bearminion add` and the docs do.
|
|
23
|
+
const section = type.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
|
|
24
|
+
return variants.map((variant) => ({ params: { section, variant }, props: { type } }))
|
|
25
|
+
})) satisfies GetStaticPaths
|
|
26
|
+
|
|
27
|
+
const { variant } = Astro.params as { section: string; variant: string }
|
|
28
|
+
const { type } = Astro.props as { type: SectionType }
|
|
29
|
+
const definition = sectionDefinitions[type]
|
|
30
|
+
const parsed = sectionSchema.safeParse({ id: type, type, variant, tone: 'base', motion: false, props: definition.defaults })
|
|
31
|
+
if (!parsed.success) throw new Error(`The preview of ${type}/${variant} has content its schema rejects: ${parsed.error.message}`)
|
|
32
|
+
const section = parsed.data
|
|
33
|
+
const site = await getSite()
|
|
34
|
+
const page = {
|
|
35
|
+
slug: `preview-${type}-${variant}`,
|
|
36
|
+
title: `${definition.label} · ${variant}`,
|
|
37
|
+
seo: { title: `${definition.label} · ${variant}`, description: `${definition.label}, ${variant} layout, with its default content.`, noindex: true, nofollow: true },
|
|
38
|
+
sections: [section],
|
|
39
|
+
} satisfies Page
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
<Base site={site} page={page} chrome={false}>
|
|
43
|
+
{/* In the docs, take the docs' light or dark theme before the first paint; the docs keep it in step from then on. */}
|
|
44
|
+
<script is:inline>
|
|
45
|
+
try {
|
|
46
|
+
const theme = window.parent !== window ? window.parent.document.documentElement.dataset.theme : undefined
|
|
47
|
+
if (theme) document.documentElement.dataset.theme = theme === 'light' ? 'light' : 'dark'
|
|
48
|
+
} catch {}
|
|
49
|
+
</script>
|
|
50
|
+
<SectionList sections={[section]} motion={false} />
|
|
51
|
+
{/* What the docs show in the Content tab: the section as it sits in a page file. */}
|
|
52
|
+
<script type="application/json" data-section-json set:html={JSON.stringify(section, null, 2)} />
|
|
53
|
+
</Base>
|
package/template/src/env.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
interface ImportMetaEnv {
|
|
4
4
|
/** Set by the hosted editor's build (`bearminionHostedEditor`). Not set in a public site's build. */
|
|
5
5
|
readonly BEARMINION_HOSTED?: boolean
|
|
6
|
+
/** Set by the docs' build of the section previews. Not set in a site's own build. */
|
|
7
|
+
readonly BEARMINION_PREVIEWS?: boolean
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
declare namespace App {
|
|
@@ -13,9 +13,11 @@ import '../styles/global.css'
|
|
|
13
13
|
interface Props {
|
|
14
14
|
site: Site
|
|
15
15
|
page: Page
|
|
16
|
+
/** False for a page that is only its sections, such as a section preview: no header, footer or consent banner. */
|
|
17
|
+
chrome?: boolean
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
const { site, page } = Astro.props
|
|
20
|
+
const { site, page, chrome = true } = Astro.props
|
|
19
21
|
const icon = site.favicon ? resolveLocalAsset(site.favicon.src) : undefined
|
|
20
22
|
const ICON_TYPES: Record<string, string> = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif', avif: 'image/avif' }
|
|
21
23
|
const iconType = icon ? ICON_TYPES[icon.format] : undefined
|
|
@@ -23,11 +25,12 @@ const paletteCss = themeCss(site.theme.colors)
|
|
|
23
25
|
const themeColor = site.theme.mode === 'dark' ? '#1c1e24' : '#f7f8f8'
|
|
24
26
|
// Snippets ship in the live site's build only: not in `astro dev`, not in host previews. See lib/analytics.ts.
|
|
25
27
|
const analyticsOn = analyticsEnabled(process.env, import.meta.env.PROD)
|
|
26
|
-
|
|
28
|
+
// A page without chrome (a section preview) never loads them.
|
|
29
|
+
const analytics = analyticsOn && chrome ? site.analytics : undefined
|
|
27
30
|
// With a banner, the snippets wait inside <template> until the visitor accepts. The banner itself shows in dev
|
|
28
31
|
// and previews too, so the owner sees it; only the live build has snippets to hold back. See lib/consent.ts.
|
|
29
32
|
const asks = consentRequired(site)
|
|
30
|
-
const gated = asks && analyticsOn
|
|
33
|
+
const gated = asks && analyticsOn && chrome
|
|
31
34
|
---
|
|
32
35
|
|
|
33
36
|
<!doctype html>
|
|
@@ -62,20 +65,24 @@ const gated = asks && analyticsOn
|
|
|
62
65
|
{icon && <link rel="icon" type={iconType} href={icon.src} />}
|
|
63
66
|
</head>
|
|
64
67
|
<body class="min-h-screen font-sans antialiased">
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
{
|
|
69
|
+
chrome && (
|
|
70
|
+
<a
|
|
71
|
+
href="#content"
|
|
72
|
+
class="sr-only focus:not-sr-only focus:fixed focus:top-4 focus:left-4 focus:z-50 focus:rounded-full focus:bg-fg focus:px-4 focus:py-2 focus:text-bg"
|
|
73
|
+
>
|
|
74
|
+
Skip to content
|
|
75
|
+
</a>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
{chrome && <Header site={site} pathname={Astro.url.pathname} />}
|
|
72
79
|
<main id="content">
|
|
73
80
|
<slot />
|
|
74
81
|
</main>
|
|
75
|
-
<Footer site={site} consentLabel={asks && site.consent?.reopen !== 'icon' ? consentCopy(site.consent).settings : undefined} />
|
|
82
|
+
{chrome && <Footer site={site} consentLabel={asks && site.consent?.reopen !== 'icon' ? consentCopy(site.consent).settings : undefined} />}
|
|
76
83
|
{analytics?.bodyEnd && !asks && <Fragment set:html={analytics.bodyEnd} />}
|
|
77
84
|
{gated && analytics?.bodyEnd && <template data-consent-snippet="body" set:html={analytics.bodyEnd} />}
|
|
78
|
-
{asks && <ConsentBanner consent={site.consent} />}
|
|
85
|
+
{chrome && asks && <ConsentBanner consent={site.consent} />}
|
|
79
86
|
<script>
|
|
80
87
|
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
81
88
|
const observer =
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { getCollection, getEntry } from 'astro:content'
|
|
2
2
|
import type { Site } from '../components/organisms/site-definition'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
LISTINGS_COLLECTION,
|
|
5
|
+
SINGLES_COLLECTION,
|
|
6
|
+
findRoute,
|
|
7
|
+
resolveTypes,
|
|
8
|
+
siteRoutes,
|
|
9
|
+
withoutOrphanSections,
|
|
10
|
+
type Entry,
|
|
11
|
+
type ListingDocument,
|
|
12
|
+
type Route,
|
|
13
|
+
type RouteOptions,
|
|
14
|
+
type SiteContent,
|
|
15
|
+
} from 'bearminion'
|
|
4
16
|
import type { Page } from '../components/sections/definitions'
|
|
5
17
|
import { contentModel } from './content-model'
|
|
6
18
|
|
|
7
19
|
/** In dev the collection can hold sections the site no longer defines. They are not drawn. */
|
|
8
|
-
const drawable = (
|
|
20
|
+
const drawable = <TDocument extends { sections: readonly unknown[] }>(document: TDocument): TDocument =>
|
|
21
|
+
withoutOrphanSections(document, contentModel.sections)
|
|
9
22
|
|
|
10
23
|
/** `content/site.json`, validated by the `site` collection. */
|
|
11
24
|
export async function getSite(): Promise<Site> {
|
|
@@ -24,3 +37,45 @@ export async function getPage(slug: string): Promise<Page | undefined> {
|
|
|
24
37
|
export async function getPages(exclude: readonly string[] = []): Promise<Page[]> {
|
|
25
38
|
return (await getCollection('pages', ({ id }) => !exclude.includes(id))).map((entry) => drawable(entry.data))
|
|
26
39
|
}
|
|
40
|
+
|
|
41
|
+
/** The collections of the content types the model declares are named at run time, so Astro has no types for them. */
|
|
42
|
+
const collectionOf = getCollection as unknown as (name: string) => Promise<{ id: string; data: unknown }[]>
|
|
43
|
+
const entryOf = getEntry as unknown as (collection: string, id: string) => Promise<{ data: unknown } | undefined>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Everything the site publishes: the pages, plus the entries, listing pages and singles of the content types declared
|
|
47
|
+
* in `content-model.ts`. A model with no `types` has only pages.
|
|
48
|
+
*/
|
|
49
|
+
export async function getContent(): Promise<SiteContent> {
|
|
50
|
+
const types = resolveTypes(contentModel)
|
|
51
|
+
const entries: Record<string, Entry[]> = {}
|
|
52
|
+
const listings: Record<string, ListingDocument> = {}
|
|
53
|
+
const singles: Record<string, Entry> = {}
|
|
54
|
+
for (const type of types.multi) {
|
|
55
|
+
if (type === types.pages) continue
|
|
56
|
+
entries[type.id] = (await collectionOf(type.id)).map((entry) => drawable(entry.data as Entry))
|
|
57
|
+
// A listing page that was never saved has no file; the route then shows the type's label and the list.
|
|
58
|
+
const listing = type.listing ? await entryOf(LISTINGS_COLLECTION, type.id) : undefined
|
|
59
|
+
if (listing) listings[type.id] = drawable(listing.data as ListingDocument)
|
|
60
|
+
}
|
|
61
|
+
for (const type of types.singles) {
|
|
62
|
+
const single = type.builtIn ? undefined : await entryOf(SINGLES_COLLECTION, type.id)
|
|
63
|
+
if (single) singles[type.id] = drawable(single.data as Entry)
|
|
64
|
+
}
|
|
65
|
+
return { pages: await getPages(), entries, listings, singles }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Lists are ordered in the site's language. `astro dev` also shows entries marked as drafts; a build leaves them out. */
|
|
69
|
+
async function routeOptions(): Promise<RouteOptions> {
|
|
70
|
+
return { locale: (await getSite()).lang ?? 'en', drafts: import.meta.env.DEV }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Every address of the site with what it shows: pages, entries, singles and each page of a listing. */
|
|
74
|
+
export async function getRoutes(): Promise<Route[]> {
|
|
75
|
+
return siteRoutes(contentModel, await getContent(), await routeOptions())
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** What the address `pathname` shows, or undefined when nothing lives there. */
|
|
79
|
+
export async function getRoute(pathname: string): Promise<Route | undefined> {
|
|
80
|
+
return findRoute(contentModel, await getContent(), pathname, await routeOptions())
|
|
81
|
+
}
|
|
@@ -3,3 +3,9 @@
|
|
|
3
3
|
* BEARMINION_HOSTED). A built public site is neither, so editor hints and editor-only image routes stay out of it.
|
|
4
4
|
*/
|
|
5
5
|
export const editing = Boolean(import.meta.env.DEV || import.meta.env.BEARMINION_HOSTED)
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* True wherever an empty frame should still be drawn, so a layout shows its shape: while editing, and in the section
|
|
9
|
+
* previews the docs build (apps/docs/scripts/build-previews.mjs sets BEARMINION_PREVIEWS). A public site leaves them out.
|
|
10
|
+
*/
|
|
11
|
+
export const placeholders = editing || Boolean(import.meta.env.BEARMINION_PREVIEWS)
|
|
@@ -5,6 +5,12 @@ export interface SitemapPage {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/** One address of the site, as `siteRoutes()` lists them: a page, an entry, a single or one page of a listing. */
|
|
9
|
+
export interface SitemapRoute {
|
|
10
|
+
path: string
|
|
11
|
+
page: SitemapPage
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
/** Public path for a content slug. The home page is stored as `index`. */
|
|
9
15
|
export function pagePath(slug: string): string {
|
|
10
16
|
return slug === 'index' ? '/' : `/${slug}`
|
|
@@ -21,8 +27,14 @@ export function normalizePathname(pathname: string): string {
|
|
|
21
27
|
* Keeps only content-loader pages whose `seo.noindex` is not true.
|
|
22
28
|
* Static routes that are not in the content directory (the style guide, for example) are left out.
|
|
23
29
|
*/
|
|
24
|
-
export function createSitemapFilter(pages: readonly SitemapPage[]): (pageUrl: string) => boolean {
|
|
25
|
-
const indexable = new Set(
|
|
30
|
+
export function createSitemapFilter(pages: readonly (SitemapPage | SitemapRoute)[]): (pageUrl: string) => boolean {
|
|
31
|
+
const indexable = new Set(
|
|
32
|
+
pages
|
|
33
|
+
// A route carries its own address. A bare page is at `/<slug>`.
|
|
34
|
+
.map((item) => ('path' in item ? { path: item.path, seo: item.page.seo } : { path: pagePath(item.slug), seo: item.seo }))
|
|
35
|
+
.filter((item) => item.seo.noindex !== true)
|
|
36
|
+
.map((item) => item.path),
|
|
37
|
+
)
|
|
26
38
|
|
|
27
39
|
return (pageUrl: string) => {
|
|
28
40
|
let pathname = pageUrl
|
|
@@ -1,45 +1,59 @@
|
|
|
1
1
|
---
|
|
2
|
+
import type { Route } from 'bearminion'
|
|
3
|
+
import EntryList from '../components/organisms/EntryList.astro'
|
|
4
|
+
import Pagination from '../components/organisms/Pagination.astro'
|
|
2
5
|
import type { Site } from '../components/organisms/site-definition'
|
|
3
|
-
import type {
|
|
6
|
+
import type { Section } from '../components/sections/definitions'
|
|
4
7
|
import SectionList from '../components/sections/SectionList.astro'
|
|
5
8
|
import Base from '../layouts/Base.astro'
|
|
6
|
-
import {
|
|
9
|
+
import { getRoute, getRoutes, getSite } from '../lib/content'
|
|
7
10
|
|
|
8
11
|
export async function getStaticPaths() {
|
|
9
12
|
const site = await getSite()
|
|
13
|
+
// Pages, and the entries, singles and listing pages of the content types declared in content-model.ts.
|
|
10
14
|
// 404.json is rendered by src/pages/404.astro, so Astro emits /404.html instead of /404/index.html.
|
|
11
|
-
const
|
|
15
|
+
const routes = (await getRoutes()).filter((route) => route.path !== '/404')
|
|
12
16
|
|
|
13
|
-
return
|
|
17
|
+
return routes.map((route) => ({
|
|
14
18
|
params: {
|
|
15
|
-
// The home page is
|
|
16
|
-
slug:
|
|
19
|
+
// The home page is published at `/`. An entry's address has two segments, such as `blog/first-post`.
|
|
20
|
+
slug: route.path === '/' ? undefined : route.path.slice(1),
|
|
17
21
|
},
|
|
18
|
-
props: { site,
|
|
22
|
+
props: { site, route },
|
|
19
23
|
}))
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
interface Props {
|
|
23
27
|
site: Site
|
|
24
|
-
|
|
28
|
+
route: Route
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
const pathname = `/${Astro.params.slug ?? ''}`
|
|
27
32
|
// The hosted editor draws the repository's current content (`Astro.locals.bearminion`); a static build uses the props.
|
|
28
33
|
const live = Astro.locals.bearminion
|
|
29
|
-
let { site,
|
|
34
|
+
let { site, route } = Astro.props as Partial<Props>
|
|
30
35
|
if (live) {
|
|
31
36
|
site = (await live.content.getSite()) as Site
|
|
32
|
-
|
|
33
|
-
if (!
|
|
34
|
-
} else if (!
|
|
37
|
+
route = await live.content.getRoute(pathname)
|
|
38
|
+
if (!route || route.path === '/404') return Astro.rewrite('/404')
|
|
39
|
+
} else if (!route) {
|
|
35
40
|
// A server build has no props: a visitor to a hosted editor with `signIn: 'optional'` gets the build's content.
|
|
36
41
|
site = await getSite()
|
|
37
|
-
|
|
38
|
-
if (!
|
|
42
|
+
route = await getRoute(pathname)
|
|
43
|
+
if (!route || route.path === '/404') return Astro.rewrite('/404')
|
|
39
44
|
}
|
|
40
|
-
if (!site || !
|
|
45
|
+
if (!site || !route) throw new Error(`No content for ${Astro.url.pathname}.`)
|
|
46
|
+
const page = route.page
|
|
41
47
|
---
|
|
42
48
|
|
|
43
49
|
<Base site={site} page={page}>
|
|
44
|
-
<SectionList sections={page.sections} motion={site.theme.motion} />
|
|
50
|
+
<SectionList sections={page.sections as Section[]} motion={site.theme.motion} />
|
|
51
|
+
{
|
|
52
|
+
route.kind === 'listing' && (
|
|
53
|
+
<>
|
|
54
|
+
<EntryList entries={route.entries} heading={page.sections.length === 0 ? page.title : undefined} lang={site.lang ?? 'en'} />
|
|
55
|
+
<Pagination pagination={route.pagination} />
|
|
56
|
+
</>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
45
59
|
</Base>
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { Section } from '../definitions'
|
|
3
|
-
import Button from '../../atoms/Button.astro'
|
|
4
|
-
import Emphasis from '../../atoms/Emphasis.astro'
|
|
5
|
-
import Typography from '../../atoms/Typography.astro'
|
|
6
|
-
import SectionHeader from '../../molecules/SectionHeader.astro'
|
|
7
|
-
import SectionShell from '../../molecules/SectionShell.astro'
|
|
8
|
-
import { HIDDEN_FALLBACK, hide } from '../../../lib/hidden-text'
|
|
9
|
-
|
|
10
|
-
interface Props {
|
|
11
|
-
section: Extract<Section, { type: 'contact' }>
|
|
12
|
-
index: number
|
|
13
|
-
motion?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const { section, index, motion = true } = Astro.props
|
|
17
|
-
const props = section.props
|
|
18
|
-
const field = (path: string) => `sections.${index}.props.${path}`
|
|
19
|
-
const reveal = section.motion ?? motion
|
|
20
|
-
const formId = `contact-form-${section.id}`
|
|
21
|
-
// A detail marked "hide from crawlers" is written into the HTML scrambled, and form.ts puts the value back in the browser.
|
|
22
|
-
const hidden = (detail: { value: string; hideFromCrawlers?: boolean | undefined }) =>
|
|
23
|
-
detail.hideFromCrawlers ? { 'data-hidden-value': hide(detail.value) } : {}
|
|
24
|
-
const shown = (detail: { value: string; hideFromCrawlers?: boolean | undefined }) => (detail.hideFromCrawlers ? HIDDEN_FALLBACK : detail.value)
|
|
25
|
-
// The form always posts to /api/contact, where the site's own handler (src/forms/contact.ts) answers. The public
|
|
26
|
-
// Turnstile site key comes from the environment at build time, so it never lives in the content files.
|
|
27
|
-
const turnstileKey: string | undefined = import.meta.env.PUBLIC_TURNSTILE_SITE_KEY || undefined
|
|
28
|
-
const formAttrs = {
|
|
29
|
-
'data-form-id': section.id,
|
|
30
|
-
'data-turnstile-key': turnstileKey,
|
|
31
|
-
action: '/api/contact',
|
|
32
|
-
method: 'post',
|
|
33
|
-
}
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
<SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal}>
|
|
37
|
-
{
|
|
38
|
-
section.variant === 'split' && (
|
|
39
|
-
<div class="section-container grid items-start gap-12 @min-[880px]:grid-cols-[minmax(22rem,0.85fr)_minmax(0,1.15fr)]" data-contact>
|
|
40
|
-
<div>
|
|
41
|
-
<SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} field={field} />
|
|
42
|
-
{props.body && <Typography as="p" size="lead" color="muted" class="mt-5" data-field={field('body')} markdown={props.body} />}
|
|
43
|
-
{
|
|
44
|
-
props.details.length > 0 && (
|
|
45
|
-
<dl class="mt-8 flex flex-col">
|
|
46
|
-
{props.details.map((detail, detailIndex) => (
|
|
47
|
-
<div class="grid grid-cols-[7rem_1fr] gap-4 border-t border-[var(--line)] py-4">
|
|
48
|
-
<dt class="font-mono text-[0.75rem] tracking-[0.06em] text-muted uppercase" data-field={field(`details.${detailIndex}.label`)}>
|
|
49
|
-
{detail.label}
|
|
50
|
-
</dt>
|
|
51
|
-
<dd data-field={field(`details.${detailIndex}.value`)} {...hidden(detail)}>{shown(detail)}</dd>
|
|
52
|
-
</div>
|
|
53
|
-
))}
|
|
54
|
-
</dl>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
</div>
|
|
58
|
-
<div class="rounded-panel bg-surface p-6 ring-line @min-[700px]:p-8">
|
|
59
|
-
<form id={formId} class="grid gap-4 @min-[700px]:grid-cols-2" data-contact-form {...formAttrs} novalidate>
|
|
60
|
-
<input type="hidden" name="formId" value={section.id} />
|
|
61
|
-
<label class="flex flex-col gap-2 text-[0.8125rem]">
|
|
62
|
-
Name
|
|
63
|
-
<input class="bm-field" name="name" required autocomplete="name" />
|
|
64
|
-
</label>
|
|
65
|
-
<label class="flex flex-col gap-2 text-[0.8125rem]">
|
|
66
|
-
Email
|
|
67
|
-
<input class="bm-field" type="email" name="email" required autocomplete="email" />
|
|
68
|
-
</label>
|
|
69
|
-
{
|
|
70
|
-
props.topics.length > 0 && (
|
|
71
|
-
<label class="flex flex-col gap-2 text-[0.8125rem] @min-[700px]:col-span-2">
|
|
72
|
-
Topic
|
|
73
|
-
<select class="bm-field" name="topic" required>
|
|
74
|
-
{props.topics.map((topic) => (
|
|
75
|
-
<option value={topic}>{topic}</option>
|
|
76
|
-
))}
|
|
77
|
-
</select>
|
|
78
|
-
</label>
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
<label class="flex flex-col gap-2 text-[0.8125rem] @min-[700px]:col-span-2">
|
|
82
|
-
Message
|
|
83
|
-
<textarea class="bm-field h-32 py-3" name="message" required></textarea>
|
|
84
|
-
</label>
|
|
85
|
-
<div class="absolute -left-[9999px] size-px overflow-hidden" aria-hidden="true">
|
|
86
|
-
<label>
|
|
87
|
-
Leave this field empty
|
|
88
|
-
<input name="_gotcha" tabindex="-1" autocomplete="off" />
|
|
89
|
-
</label>
|
|
90
|
-
</div>
|
|
91
|
-
{turnstileKey && <div class="@min-[700px]:col-span-2" data-turnstile-widget></div>}
|
|
92
|
-
<div class="@min-[700px]:col-span-2">
|
|
93
|
-
<Button type="submit">Send message</Button>
|
|
94
|
-
{props.note && <Typography as="p" size="small" color="muted" class="mt-3" data-field={field('note')} markdown={props.note} />}
|
|
95
|
-
</div>
|
|
96
|
-
</form>
|
|
97
|
-
<div id={`${section.id}-sent`} data-contact-success tabindex="-1">
|
|
98
|
-
<p class="text-[1.5rem] font-semibold tracking-[-0.03em]">Message sent.</p>
|
|
99
|
-
{props.thanks && <Typography as="p" size="body" color="muted" class="mt-3" data-field={field('thanks')} markdown={props.thanks} />}
|
|
100
|
-
<Button type="button" variant="secondary" class="mt-6" data-contact-reset>
|
|
101
|
-
Send another
|
|
102
|
-
</Button>
|
|
103
|
-
</div>
|
|
104
|
-
<p id={`${section.id}-failed`} class="bm-form-error mt-4" data-contact-failed role="alert">The message was not sent. Try again, or reach us another way.</p>
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
{
|
|
110
|
-
section.variant === 'card' && (
|
|
111
|
-
<div class="section-container" data-contact>
|
|
112
|
-
<SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} intro={props.body} introField="body" align="center" field={field} class="mx-auto max-w-2xl" />
|
|
113
|
-
<div class="mx-auto mt-10 max-w-[42rem] rounded-panel bg-surface p-6 ring-line @min-[700px]:p-8">
|
|
114
|
-
<form id={formId} class="grid gap-4 @min-[700px]:grid-cols-2" data-contact-form {...formAttrs} novalidate>
|
|
115
|
-
<input type="hidden" name="formId" value={section.id} />
|
|
116
|
-
<label class="flex flex-col gap-2 text-[0.8125rem]">
|
|
117
|
-
Name
|
|
118
|
-
<input class="bm-field" name="name" required autocomplete="name" />
|
|
119
|
-
</label>
|
|
120
|
-
<label class="flex flex-col gap-2 text-[0.8125rem]">
|
|
121
|
-
Email
|
|
122
|
-
<input class="bm-field" type="email" name="email" required autocomplete="email" />
|
|
123
|
-
</label>
|
|
124
|
-
{
|
|
125
|
-
props.topics.length > 0 && (
|
|
126
|
-
<div class="@min-[700px]:col-span-2">
|
|
127
|
-
<p class="mb-2 text-[0.8125rem]">Topic</p>
|
|
128
|
-
<div class="flex flex-wrap gap-2" data-topics>
|
|
129
|
-
{props.topics.map((topic, topicIndex) => (
|
|
130
|
-
<button type="button" class="h-10 rounded-full px-4 text-[0.875rem] ring-line" data-topic aria-pressed={topicIndex === 0 ? 'true' : 'false'}>
|
|
131
|
-
{topic}
|
|
132
|
-
</button>
|
|
133
|
-
))}
|
|
134
|
-
</div>
|
|
135
|
-
<input type="hidden" name="topic" value={props.topics[0]} data-topic-input required />
|
|
136
|
-
</div>
|
|
137
|
-
)
|
|
138
|
-
}
|
|
139
|
-
<label class="flex flex-col gap-2 text-[0.8125rem] @min-[700px]:col-span-2">
|
|
140
|
-
Message
|
|
141
|
-
<textarea class="bm-field h-32 py-3" name="message" required></textarea>
|
|
142
|
-
</label>
|
|
143
|
-
<div class="absolute -left-[9999px] size-px overflow-hidden" aria-hidden="true">
|
|
144
|
-
<label>
|
|
145
|
-
Leave this field empty
|
|
146
|
-
<input name="_gotcha" tabindex="-1" autocomplete="off" />
|
|
147
|
-
</label>
|
|
148
|
-
</div>
|
|
149
|
-
{turnstileKey && <div class="@min-[700px]:col-span-2" data-turnstile-widget></div>}
|
|
150
|
-
<div class="@min-[700px]:col-span-2">
|
|
151
|
-
<Button type="submit" class="w-full">Send message</Button>
|
|
152
|
-
{props.note && <Typography as="p" size="small" color="muted" class="mt-3 text-center" data-field={field('note')} markdown={props.note} />}
|
|
153
|
-
</div>
|
|
154
|
-
</form>
|
|
155
|
-
<div id={`${section.id}-sent`} data-contact-success tabindex="-1">
|
|
156
|
-
<p class="text-[1.5rem] font-semibold tracking-[-0.03em]">Message sent.</p>
|
|
157
|
-
{props.thanks && <Typography as="p" size="body" color="muted" class="mt-3" data-field={field('thanks')} markdown={props.thanks} />}
|
|
158
|
-
<Button type="button" variant="secondary" class="mt-6" data-contact-reset>
|
|
159
|
-
Send another
|
|
160
|
-
</Button>
|
|
161
|
-
</div>
|
|
162
|
-
<p id={`${section.id}-failed`} class="bm-form-error mt-4" data-contact-failed role="alert">The message was not sent. Try again, or reach us another way.</p>
|
|
163
|
-
</div>
|
|
164
|
-
</div>
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
{
|
|
168
|
-
section.variant === 'minimal' && (
|
|
169
|
-
<div class="section-container" data-contact>
|
|
170
|
-
{
|
|
171
|
-
props.heading && (
|
|
172
|
-
<h2 class="max-w-[12ch] text-[clamp(2.75rem,1rem+6cqi,7rem)] leading-[0.92] font-semibold tracking-[-0.05em]">
|
|
173
|
-
<Emphasis heading={props.heading} marks={props.marks} data-field={field('heading')} />
|
|
174
|
-
</h2>
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
<form id={formId} class="mt-10 grid gap-8 @min-[760px]:grid-cols-2" data-contact-form {...formAttrs} novalidate>
|
|
178
|
-
<input type="hidden" name="formId" value={section.id} />
|
|
179
|
-
<label class="flex flex-col gap-2">
|
|
180
|
-
<span class="font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase">Name</span>
|
|
181
|
-
<input class="bm-underline" name="name" required autocomplete="name" />
|
|
182
|
-
</label>
|
|
183
|
-
<label class="flex flex-col gap-2">
|
|
184
|
-
<span class="font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase">Email</span>
|
|
185
|
-
<input class="bm-underline" type="email" name="email" required autocomplete="email" />
|
|
186
|
-
</label>
|
|
187
|
-
<label class="flex flex-col gap-2 @min-[760px]:col-span-2">
|
|
188
|
-
<span class="font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase">Message</span>
|
|
189
|
-
<textarea class="bm-underline" name="message" required rows="3"></textarea>
|
|
190
|
-
</label>
|
|
191
|
-
<div class="absolute -left-[9999px] size-px overflow-hidden" aria-hidden="true">
|
|
192
|
-
<label>
|
|
193
|
-
Leave this field empty
|
|
194
|
-
<input name="_gotcha" tabindex="-1" autocomplete="off" />
|
|
195
|
-
</label>
|
|
196
|
-
</div>
|
|
197
|
-
{turnstileKey && <div class="@min-[760px]:col-span-2" data-turnstile-widget></div>}
|
|
198
|
-
<div class="flex flex-wrap items-end justify-between gap-6 @min-[760px]:col-span-2">
|
|
199
|
-
{
|
|
200
|
-
props.details.length > 0 && (
|
|
201
|
-
<dl class="flex flex-wrap gap-x-8 gap-y-3">
|
|
202
|
-
{props.details.map((detail, detailIndex) => (
|
|
203
|
-
<div>
|
|
204
|
-
<dt class="font-mono text-[0.6875rem] tracking-[0.08em] text-muted uppercase" data-field={field(`details.${detailIndex}.label`)}>{detail.label}</dt>
|
|
205
|
-
<dd class="mt-1" data-field={field(`details.${detailIndex}.value`)} {...hidden(detail)}>{shown(detail)}</dd>
|
|
206
|
-
</div>
|
|
207
|
-
))}
|
|
208
|
-
</dl>
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
<Button type="submit">Send</Button>
|
|
212
|
-
</div>
|
|
213
|
-
</form>
|
|
214
|
-
<div id={`${section.id}-sent`} data-contact-success tabindex="-1">
|
|
215
|
-
<p class="text-[clamp(2rem,1rem+3cqi,3.5rem)] leading-[0.95] font-semibold tracking-[-0.04em]">Message sent.</p>
|
|
216
|
-
{props.thanks && <Typography as="p" size="body" color="muted" class="mt-4" data-field={field('thanks')} markdown={props.thanks} />}
|
|
217
|
-
<Button type="button" variant="secondary" class="mt-6" data-contact-reset>
|
|
218
|
-
Send another
|
|
219
|
-
</Button>
|
|
220
|
-
</div>
|
|
221
|
-
<p id={`${section.id}-failed`} class="bm-form-error mt-4" data-contact-failed role="alert">The message was not sent. Try again, or reach us another way.</p>
|
|
222
|
-
</div>
|
|
223
|
-
)
|
|
224
|
-
}
|
|
225
|
-
</SectionShell>
|
|
226
|
-
|
|
227
|
-
<script>
|
|
228
|
-
import { bindContacts } from './form'
|
|
229
|
-
bindContacts()
|
|
230
|
-
document.addEventListener('bearminion:preview', bindContacts)
|
|
231
|
-
</script>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { sectionArgTypes } from '../../../stories/options'
|
|
2
|
-
import { sectionEntry } from '../../../stories/sample'
|
|
3
|
-
import Contact from './Contact.astro'
|
|
4
|
-
|
|
5
|
-
const entry = sectionEntry('contact')
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: 'Sections/Contact',
|
|
9
|
-
component: Contact,
|
|
10
|
-
parameters: { layout: 'fullscreen' },
|
|
11
|
-
argTypes: sectionArgTypes('contact'),
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const Home = {
|
|
15
|
-
args: { section: entry.section, index: entry.index, motion: false },
|
|
16
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { defineSection, richTextSchema, textSchema, withEmphasis } from 'bearminion'
|
|
3
|
-
import { accent, eyebrow, heading } from '../shared'
|
|
4
|
-
import { contactWireframe } from './wireframe'
|
|
5
|
-
|
|
6
|
-
export const contactVariants = ['split', 'card', 'minimal'] as const
|
|
7
|
-
|
|
8
|
-
export const contactDetailSchema = z
|
|
9
|
-
.object({
|
|
10
|
-
label: textSchema,
|
|
11
|
-
value: textSchema,
|
|
12
|
-
// The built page carries the value scrambled and a few lines of script show it, so a crawler that only reads the HTML finds none.
|
|
13
|
-
hideFromCrawlers: z.boolean().optional(),
|
|
14
|
-
})
|
|
15
|
-
.strict()
|
|
16
|
-
|
|
17
|
-
export const contactSchema = withEmphasis({
|
|
18
|
-
eyebrow,
|
|
19
|
-
heading,
|
|
20
|
-
body: richTextSchema.optional(),
|
|
21
|
-
details: z.array(contactDetailSchema),
|
|
22
|
-
topics: z.array(textSchema),
|
|
23
|
-
note: richTextSchema.optional(),
|
|
24
|
-
thanks: richTextSchema.optional(),
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
export type ContactDetail = z.infer<typeof contactDetailSchema>
|
|
28
|
-
export type ContactProps = z.infer<typeof contactSchema>
|
|
29
|
-
|
|
30
|
-
export const contact = defineSection({
|
|
31
|
-
type: 'contact',
|
|
32
|
-
label: 'Contact',
|
|
33
|
-
description: 'Contact details beside a form.',
|
|
34
|
-
schema: contactSchema,
|
|
35
|
-
defaults: {
|
|
36
|
-
eyebrow: 'Contact',
|
|
37
|
-
heading: 'Get in touch.',
|
|
38
|
-
marks: accent('Get in touch.', 'in touch.'),
|
|
39
|
-
body: 'Tell people what they can contact you about and when they will hear back.',
|
|
40
|
-
details: [{ label: 'Email', value: 'hello@example.com', hideFromCrawlers: false }],
|
|
41
|
-
topics: ['General'],
|
|
42
|
-
note: 'We only use your details to reply to you.',
|
|
43
|
-
thanks: 'Thanks, your message is on its way.',
|
|
44
|
-
},
|
|
45
|
-
variants: contactVariants,
|
|
46
|
-
defaultVariant: 'split',
|
|
47
|
-
// The form posts to /api/contact: the handler is `src/forms/contact.ts`, written in code, never configured here.
|
|
48
|
-
form: 'contact',
|
|
49
|
-
optional: { props: ['eyebrow', 'heading', 'body', 'note', 'thanks'], items: { details: ['hideFromCrawlers'] } },
|
|
50
|
-
counts: { details: { recommended: 3 }, topics: { recommended: 3 } },
|
|
51
|
-
wireframe: contactWireframe,
|
|
52
|
-
})
|