bearminion 1.20.0 → 1.22.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 +35 -0
- package/README.md +3 -3
- package/dist/astro.d.ts +16 -7
- package/dist/astro.js +212 -93
- package/dist/cli.js +903 -4
- package/dist/content-types-46XqPaW4.js +505 -0
- package/dist/content.d.ts +24 -3
- package/dist/content.js +83 -6
- package/dist/{editor-context-DzRwKENi.d.ts → editor-context-D1yfPp21.d.ts} +95 -8
- package/dist/{github-store-Dt_YuOPD.js → github-store-B2folBeq.js} +551 -206
- package/dist/{github-store-DsLCe5MR.d.ts → github-store-CuhvbFCh.d.ts} +1 -1
- package/dist/hosted-astro.js +1 -1
- package/dist/{hosted-middleware-CsROahka.js → hosted-middleware-DHLIedeV.js} +1 -1
- package/dist/hosted-overlay.js +1 -1
- package/dist/hosted.d.ts +10 -4
- package/dist/hosted.js +68 -9
- package/dist/index.d.ts +4 -4
- package/dist/index.js +11 -6
- package/dist/{migrate-b408EaLp.js → migrate-Cm30puW8.js} +2 -2
- package/dist/{page-wlcQJAA-.js → page-C7zE_HD1.js} +5 -1
- package/dist/{page-BGSTL63-.d.ts → page-CpVElMPH.d.ts} +193 -37
- package/dist/{request-guards-BcSUj8Gc.js → request-guards-DtNVdqQ7.js} +1 -1
- package/dist/{collections-Bm3RWg2K.js → routing-jKeq4LwO.js} +213 -57
- package/dist/routing-yPy8hEfZ.d.ts +137 -0
- package/dist/{theme-BvqJ8UnS.js → theme-DTVVNMlr.js} +1 -1
- package/dist/ui/mount.js +3294 -1259
- package/package.json +2 -2
- package/registry/default/files/src/components/organisms/EntryList.astro +83 -0
- package/registry/default/files/src/components/organisms/Pagination.astro +56 -0
- package/registry/default/files/src/components/sections/contact/definition.ts +6 -2
- package/registry/default/files/src/components/sections/faq/definition.ts +2 -2
- package/registry/default/files/src/components/sections/media/Media.astro +2 -2
- package/registry/default/files/src/components/sections/media/MediaPlayer.astro +2 -2
- package/registry/default/files/src/components/sections/pricing/definition.ts +16 -1
- package/registry/default/files/src/components/sections/shared.ts +3 -0
- package/registry/default/files/src/components/sections/stats/definition.ts +6 -1
- package/registry/default/files/src/components/sections/testimonials/definition.ts +13 -1
- package/registry/default/files/src/components/sections/text-image/definition.ts +1 -1
- package/registry/default/files/src/components/seo/Seo.astro +3 -1
- package/registry/default/files/src/content.config.ts +21 -0
- package/registry/default/files/src/env.d.ts +2 -0
- package/registry/default/files/src/lib/content.ts +81 -0
- package/registry/default/files/src/lib/editing.ts +6 -0
- package/registry/default/files/src/lib/sitemap.ts +48 -0
- package/registry/default/files/src/pages/[...slug].astro +30 -16
- package/registry/default/registry.json +77 -21
- package/dist/preview-DFLna-Be.d.ts +0 -42
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bearminion",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.22.0",
|
|
4
|
+
"description": "Git-based CMS for Astro. Click to edit on the page, save JSON to your repo. Start with npm create bearminion.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakub Lange",
|
|
7
7
|
"homepage": "https://bearminion.com",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ListedEntry } from 'bearminion'
|
|
3
|
+
import Typography from '../atoms/Typography.astro'
|
|
4
|
+
import MediaFrame from '../molecules/MediaFrame.astro'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The entries of a content type on its listing page, one card each. It shows what an entry has: `date`, `excerpt`
|
|
8
|
+
* and `cover` when the type declares fields by those names, and the entry's SEO description when there is no excerpt.
|
|
9
|
+
* A type with other fields: change this file, it is yours.
|
|
10
|
+
*/
|
|
11
|
+
interface Props {
|
|
12
|
+
entries: ListedEntry[]
|
|
13
|
+
/** Shown above the list when the listing page has no sections of its own to introduce it. */
|
|
14
|
+
heading?: string
|
|
15
|
+
/** The site's language, for the date. */
|
|
16
|
+
lang: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { entries, heading, lang } = Astro.props
|
|
20
|
+
|
|
21
|
+
const text = (value: unknown): string | undefined => (typeof value === 'string' && value !== '' ? value : undefined)
|
|
22
|
+
|
|
23
|
+
/** A cover is an image field (`{ src, alt }`) or a plain path. */
|
|
24
|
+
function coverOf(value: unknown): { src: string; alt: string } | undefined {
|
|
25
|
+
if (typeof value === 'string' && value !== '') return { src: value, alt: '' }
|
|
26
|
+
if (typeof value !== 'object' || value === null || !('src' in value) || typeof value.src !== 'string') return undefined
|
|
27
|
+
if ('hidden' in value && value.hidden === true) return undefined
|
|
28
|
+
return { src: value.src, alt: 'alt' in value && typeof value.alt === 'string' ? value.alt : '' }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `2026-01-05` as the site's language writes a date. Anything that is not a date is shown as it is. */
|
|
32
|
+
function dateOf(value: unknown): { iso: string; label: string } | undefined {
|
|
33
|
+
const raw = value instanceof Date ? value.toISOString() : text(value)
|
|
34
|
+
if (!raw) return undefined
|
|
35
|
+
const date = new Date(raw)
|
|
36
|
+
if (Number.isNaN(date.getTime())) return { iso: raw, label: raw }
|
|
37
|
+
return { iso: raw, label: new Intl.DateTimeFormat(lang, { dateStyle: 'long', timeZone: 'UTC' }).format(date) }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const cards = entries.map((entry) => ({
|
|
41
|
+
entry,
|
|
42
|
+
cover: coverOf(entry.fields.cover),
|
|
43
|
+
date: dateOf(entry.fields.date),
|
|
44
|
+
excerpt: text(entry.fields.excerpt) ?? text(entry.description),
|
|
45
|
+
}))
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
<section data-entry-list class="relative overflow-clip">
|
|
49
|
+
<div class="section-container">
|
|
50
|
+
{heading && <Typography as="h1" size="h2">{heading}</Typography>}
|
|
51
|
+
{
|
|
52
|
+
cards.length === 0 ? (
|
|
53
|
+
<Typography as="p" size="lead" color="muted" class={heading ? 'mt-6' : undefined}>
|
|
54
|
+
Nothing here yet.
|
|
55
|
+
</Typography>
|
|
56
|
+
) : (
|
|
57
|
+
<ul class:list={['grid grid-cols-[repeat(auto-fit,minmax(min(100%,18rem),1fr))] gap-4', heading && 'mt-12']}>
|
|
58
|
+
{cards.map(({ entry, cover, date, excerpt }) => (
|
|
59
|
+
<li class="relative flex flex-col gap-4 rounded-card-lg bg-surface p-6 ring-line transition duration-200 hover:-translate-y-1 hover:shadow-[0_24px_40px_-28px_oklch(0.2_0.02_255/0.4)]">
|
|
60
|
+
{cover && <MediaFrame src={cover.src} alt={cover.alt} aspectClass="aspect-[16/9]" />}
|
|
61
|
+
{date && (
|
|
62
|
+
<p class="font-mono text-[0.6875rem] tracking-[0.08em] text-muted">
|
|
63
|
+
<time datetime={date.iso}>{date.label}</time>
|
|
64
|
+
</p>
|
|
65
|
+
)}
|
|
66
|
+
<Typography as="h2" size="h3">
|
|
67
|
+
{/* The link covers the whole card, so the title is the one thing a screen reader announces as the link. */}
|
|
68
|
+
<a href={entry.path} class="after:absolute after:inset-0 after:rounded-card-lg focus-visible:outline-none focus-visible:after:ring-2 focus-visible:after:ring-accent">
|
|
69
|
+
{entry.title}
|
|
70
|
+
</a>
|
|
71
|
+
</Typography>
|
|
72
|
+
{excerpt && (
|
|
73
|
+
<Typography as="p" size="body" color="muted">
|
|
74
|
+
{excerpt}
|
|
75
|
+
</Typography>
|
|
76
|
+
)}
|
|
77
|
+
</li>
|
|
78
|
+
))}
|
|
79
|
+
</ul>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
</div>
|
|
83
|
+
</section>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { Pagination } from 'bearminion'
|
|
3
|
+
|
|
4
|
+
/** The page numbers under a listing. Nothing is drawn while the listing fits on one page. */
|
|
5
|
+
interface Props {
|
|
6
|
+
pagination: Pagination
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { pagination } = Astro.props
|
|
10
|
+
const step = 'inline-flex h-10 min-w-10 items-center justify-center rounded-full px-3 font-mono text-sm ring-line transition-colors'
|
|
11
|
+
const link = `${step} bg-surface hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
{
|
|
15
|
+
pagination.pages > 1 && (
|
|
16
|
+
<nav aria-label="Pages" data-pagination class="mx-auto max-w-[80rem] px-[clamp(1.25rem,4cqi,3rem)] pb-16">
|
|
17
|
+
<ul class="flex flex-wrap items-center justify-center gap-2">
|
|
18
|
+
<li>
|
|
19
|
+
{pagination.previous ? (
|
|
20
|
+
<a href={pagination.previous} rel="prev" class={link}>
|
|
21
|
+
Previous
|
|
22
|
+
</a>
|
|
23
|
+
) : (
|
|
24
|
+
<span aria-disabled="true" class={`${step} text-muted opacity-50`}>
|
|
25
|
+
Previous
|
|
26
|
+
</span>
|
|
27
|
+
)}
|
|
28
|
+
</li>
|
|
29
|
+
{pagination.links.map((item) => (
|
|
30
|
+
<li>
|
|
31
|
+
{item.current ? (
|
|
32
|
+
<span aria-current="page" class={`${step} bg-fg text-bg`}>
|
|
33
|
+
{item.page}
|
|
34
|
+
</span>
|
|
35
|
+
) : (
|
|
36
|
+
<a href={item.path} aria-label={`Page ${item.page}`} class={link}>
|
|
37
|
+
{item.page}
|
|
38
|
+
</a>
|
|
39
|
+
)}
|
|
40
|
+
</li>
|
|
41
|
+
))}
|
|
42
|
+
<li>
|
|
43
|
+
{pagination.next ? (
|
|
44
|
+
<a href={pagination.next} rel="next" class={link}>
|
|
45
|
+
Next
|
|
46
|
+
</a>
|
|
47
|
+
) : (
|
|
48
|
+
<span aria-disabled="true" class={`${step} text-muted opacity-50`}>
|
|
49
|
+
Next
|
|
50
|
+
</span>
|
|
51
|
+
)}
|
|
52
|
+
</li>
|
|
53
|
+
</ul>
|
|
54
|
+
</nav>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
@@ -37,8 +37,12 @@ export const contact = defineSection({
|
|
|
37
37
|
heading: 'Get in touch.',
|
|
38
38
|
marks: accent('Get in touch.', 'in touch.'),
|
|
39
39
|
body: 'Tell people what they can contact you about and when they will hear back.',
|
|
40
|
-
details: [
|
|
41
|
-
|
|
40
|
+
details: [
|
|
41
|
+
{ label: 'Email', value: 'hello@example.com', hideFromCrawlers: false },
|
|
42
|
+
{ label: 'Phone', value: '+1 555 010 0100', hideFromCrawlers: false },
|
|
43
|
+
{ label: 'Hours', value: 'Monday to Friday, 9:00 to 17:00', hideFromCrawlers: false },
|
|
44
|
+
],
|
|
45
|
+
topics: ['General', 'Sales', 'Support'],
|
|
42
46
|
note: 'We only use your details to reply to you.',
|
|
43
47
|
thanks: 'Thanks, your message is on its way.',
|
|
44
48
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import { defineSection, linkSchema, richTextSchema, textSchema, withEmphasis, type CountRule } from 'bearminion'
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_CONTACT_HREF, accent, eyebrow, heading } from '../shared'
|
|
4
4
|
import { faqWireframe } from './wireframe'
|
|
5
5
|
|
|
6
6
|
export const faqVariants = ['accordion', 'split', 'grid'] as const
|
|
@@ -38,7 +38,7 @@ export const faq = defineSection({
|
|
|
38
38
|
eyebrow: 'FAQ',
|
|
39
39
|
heading: 'Questions, answered plainly.',
|
|
40
40
|
marks: accent('Questions, answered plainly.', 'plainly.'),
|
|
41
|
-
link: { label: 'Contact us', href:
|
|
41
|
+
link: { label: 'Contact us', href: DEFAULT_CONTACT_HREF },
|
|
42
42
|
items: [
|
|
43
43
|
{ q: 'What is included?', a: 'Answer the question people ask most before they buy, in two or three sentences.' },
|
|
44
44
|
{ q: 'How long does it take to get started?', a: 'Give a realistic time frame and say what the reader needs to have ready.' },
|
|
@@ -4,7 +4,7 @@ import Typography from '../../atoms/Typography.astro'
|
|
|
4
4
|
import SectionHeader from '../../molecules/SectionHeader.astro'
|
|
5
5
|
import SectionShell from '../../molecules/SectionShell.astro'
|
|
6
6
|
import MediaPlayer from './MediaPlayer.astro'
|
|
7
|
-
import {
|
|
7
|
+
import { placeholders } from '../../../lib/editing'
|
|
8
8
|
import { parseMediaSource } from './source'
|
|
9
9
|
|
|
10
10
|
interface Props {
|
|
@@ -20,7 +20,7 @@ const reveal = section.motion ?? motion
|
|
|
20
20
|
const intro = props.intro && Boolean(props.eyebrow || props.heading || props.body)
|
|
21
21
|
const filled = props.kind === 'video' ? Boolean(props.video && parseMediaSource(props.video)) : Boolean(props.image?.src && props.image.src !== 'placeholder' && !props.image.hidden)
|
|
22
22
|
// A built site leaves out an empty frame, and with no heading either, the whole section.
|
|
23
|
-
const showFrame = filled ||
|
|
23
|
+
const showFrame = filled || placeholders
|
|
24
24
|
const rendered = showFrame || intro
|
|
25
25
|
const player = {
|
|
26
26
|
kind: props.kind,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { Image } from 'bearminion'
|
|
3
3
|
import { imageSrcset, imageUrl } from '../../../lib/image-url'
|
|
4
4
|
import { cn } from '../../../lib/cn'
|
|
5
|
-
import {
|
|
5
|
+
import { placeholders } from '../../../lib/editing'
|
|
6
6
|
import MediaFrame from '../../molecules/MediaFrame.astro'
|
|
7
7
|
import type { MediaProps } from './definition'
|
|
8
8
|
import { parseMediaSource } from './source'
|
|
@@ -45,7 +45,7 @@ const looping = source?.kind === 'file' && playback === 'loop'
|
|
|
45
45
|
{
|
|
46
46
|
empty ? (
|
|
47
47
|
// The empty frame is an editor hint, so a built site leaves it out.
|
|
48
|
-
|
|
48
|
+
placeholders && (
|
|
49
49
|
<div class={cn(frame, 'placeholder-stripes flex flex-col items-center justify-center gap-4 p-6 text-center')} data-field={kind === 'image' ? imageField : undefined}>
|
|
50
50
|
{kind === 'video' && (
|
|
51
51
|
<span class="flex size-14 items-center justify-center rounded-full bg-fg text-bg" aria-hidden="true">
|
|
@@ -49,7 +49,22 @@ export const pricing = defineSection({
|
|
|
49
49
|
blurb: 'For trying things out.',
|
|
50
50
|
monthly: 0,
|
|
51
51
|
cta: { label: 'Start free', href: `#${DEFAULT_CONTACT_ANCHOR}` },
|
|
52
|
-
features: ['Core features'],
|
|
52
|
+
features: ['Core features', 'One project', 'Community support'],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'Pro',
|
|
56
|
+
blurb: 'For growing teams.',
|
|
57
|
+
monthly: 19,
|
|
58
|
+
featured: true,
|
|
59
|
+
cta: { label: 'Choose Pro', href: `#${DEFAULT_CONTACT_ANCHOR}` },
|
|
60
|
+
features: ['Everything in Starter', 'Unlimited projects', 'Priority email support', 'Team members'],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'Business',
|
|
64
|
+
blurb: 'For larger organisations.',
|
|
65
|
+
monthly: 49,
|
|
66
|
+
cta: { label: 'Contact sales', href: `#${DEFAULT_CONTACT_ANCHOR}` },
|
|
67
|
+
features: ['Everything in Pro', 'Custom onboarding', 'Dedicated contact'],
|
|
53
68
|
},
|
|
54
69
|
],
|
|
55
70
|
},
|
|
@@ -11,3 +11,6 @@ export function accent(heading: string, em: string) {
|
|
|
11
11
|
|
|
12
12
|
/** Default in-page target for contact CTAs. Sample pages set this anchor on the contact section. */
|
|
13
13
|
export const DEFAULT_CONTACT_ANCHOR = 'contact'
|
|
14
|
+
|
|
15
|
+
/** Where a "Contact us" link points by default on a site that may have no Contact section: an address to replace. */
|
|
16
|
+
export const DEFAULT_CONTACT_HREF = 'mailto:hello@example.com'
|
|
@@ -31,7 +31,12 @@ export const stats = defineSection({
|
|
|
31
31
|
eyebrow: 'By the numbers',
|
|
32
32
|
heading: 'Figures that build trust.',
|
|
33
33
|
marks: accent('Figures that build trust.', 'build trust.'),
|
|
34
|
-
items: [
|
|
34
|
+
items: [
|
|
35
|
+
{ value: '120+', label: 'customers since launch' },
|
|
36
|
+
{ value: '98%', label: 'would recommend us' },
|
|
37
|
+
{ value: '24 h', label: 'average reply time' },
|
|
38
|
+
{ value: '10 yrs', label: 'in business' },
|
|
39
|
+
],
|
|
35
40
|
},
|
|
36
41
|
variants: statsVariants,
|
|
37
42
|
defaultVariant: 'row',
|
|
@@ -32,7 +32,19 @@ export const testimonials = defineSection({
|
|
|
32
32
|
eyebrow: 'Testimonials',
|
|
33
33
|
heading: 'What people say',
|
|
34
34
|
marks: accent('What people say', 'people say'),
|
|
35
|
-
items: [
|
|
35
|
+
items: [
|
|
36
|
+
{
|
|
37
|
+
quote: 'A short quote from a happy customer. One or two sentences that sound like a real person.',
|
|
38
|
+
name: 'Alex Morgan',
|
|
39
|
+
role: 'Role, Company',
|
|
40
|
+
},
|
|
41
|
+
{ quote: 'Quotes work best when they name a specific result, not just a compliment.', name: 'Sam Rivera', role: 'Role, Company' },
|
|
42
|
+
{
|
|
43
|
+
quote: 'Ask for permission before you publish a name, and add a photo if you have one.',
|
|
44
|
+
name: 'Jordan Lee',
|
|
45
|
+
role: 'Role, Company',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
36
48
|
},
|
|
37
49
|
variants: testimonialsVariants,
|
|
38
50
|
defaultVariant: 'grid',
|
|
@@ -27,7 +27,7 @@ export const textImage = defineSection({
|
|
|
27
27
|
heading: 'Explain it in three steps.',
|
|
28
28
|
marks: accent('Explain it in three steps.', 'three steps.'),
|
|
29
29
|
body: 'A paragraph that walks through how it works, from the first contact to the result.',
|
|
30
|
-
points: ['Step one: what happens first'],
|
|
30
|
+
points: ['Step one: what happens first', 'Step two: what you do for them', 'Step three: what they end up with'],
|
|
31
31
|
link: { label: 'Learn more', href: '#' },
|
|
32
32
|
image: { src: 'placeholder', alt: '' },
|
|
33
33
|
},
|
|
@@ -30,7 +30,9 @@ const title = site.seo.titleTemplate ? site.seo.titleTemplate.replaceAll('%s', p
|
|
|
30
30
|
const description = page.seo.description || site.seo.description || ''
|
|
31
31
|
const path = pathname.startsWith('/') ? pathname : `/${pathname}`
|
|
32
32
|
const canonical = page.seo.canonical ? resolveAgainstSite(page.seo.canonical) : new URL(path, site.url).href
|
|
33
|
-
|
|
33
|
+
// SEO › Indexing: with "Allow search engines" off (site.seo.robots false), every page asks not to be indexed.
|
|
34
|
+
const noindex = page.seo.noindex || site.seo.robots === false
|
|
35
|
+
const robots = [noindex ? 'noindex' : 'index', page.seo.nofollow ? 'nofollow' : 'follow'].join(', ')
|
|
34
36
|
const ogImageSrc = page.seo.ogImage ?? site.seo.ogImage
|
|
35
37
|
const ogImage = ogImageSrc ? absoluteImage(ogImageSrc) : undefined
|
|
36
38
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineCollection } from 'astro:content'
|
|
2
|
+
import { contentCollections } from 'bearminion/content'
|
|
3
|
+
import { contentDirectory } from './lib/content-dir'
|
|
4
|
+
import { contentModel } from './lib/content-model'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `pages` (id = slug) and `site` (id `site`) read from `content/`. The editor writes the same
|
|
8
|
+
* files, and Astro refreshes these collections when they change. `types` holds one more collection for each content
|
|
9
|
+
* type declared in `content-model.ts`, and is empty when there are none.
|
|
10
|
+
*/
|
|
11
|
+
const { pages, site, types } = contentCollections(contentModel, {
|
|
12
|
+
contentDir: contentDirectory(),
|
|
13
|
+
// Dev only: a page holding a section type the site dropped still loads, so the editor can remove it.
|
|
14
|
+
tolerateOrphans: import.meta.env.DEV,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const collections = {
|
|
18
|
+
pages: defineCollection(pages),
|
|
19
|
+
site: defineCollection(site),
|
|
20
|
+
...Object.fromEntries(Object.entries(types).map(([name, collection]) => [name, defineCollection(collection)])),
|
|
21
|
+
}
|
|
@@ -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 {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { getCollection, getEntry } from 'astro:content'
|
|
2
|
+
import type { Site } from '../components/organisms/site-definition'
|
|
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'
|
|
16
|
+
import type { Page } from '../components/sections/definitions'
|
|
17
|
+
import { contentModel } from './content-model'
|
|
18
|
+
|
|
19
|
+
/** In dev the collection can hold sections the site no longer defines. They are not drawn. */
|
|
20
|
+
const drawable = <TDocument extends { sections: readonly unknown[] }>(document: TDocument): TDocument =>
|
|
21
|
+
withoutOrphanSections(document, contentModel.sections)
|
|
22
|
+
|
|
23
|
+
/** `content/site.json`, validated by the `site` collection. */
|
|
24
|
+
export async function getSite(): Promise<Site> {
|
|
25
|
+
const entry = await getEntry('site', 'site')
|
|
26
|
+
if (!entry) throw new Error('content/site.json is missing')
|
|
27
|
+
return entry.data
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One page by slug (the home page is `index`), or undefined. */
|
|
31
|
+
export async function getPage(slug: string): Promise<Page | undefined> {
|
|
32
|
+
const entry = await getEntry('pages', slug)
|
|
33
|
+
return entry && drawable(entry.data)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Every page except the slugs in `exclude`. */
|
|
37
|
+
export async function getPages(exclude: readonly string[] = []): Promise<Page[]> {
|
|
38
|
+
return (await getCollection('pages', ({ id }) => !exclude.includes(id))).map((entry) => drawable(entry.data))
|
|
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)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface SitemapPage {
|
|
2
|
+
slug: string
|
|
3
|
+
seo: {
|
|
4
|
+
noindex?: boolean
|
|
5
|
+
}
|
|
6
|
+
}
|
|
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
|
+
|
|
14
|
+
/** Public path for a content slug. The home page is stored as `index`. */
|
|
15
|
+
export function pagePath(slug: string): string {
|
|
16
|
+
return slug === 'index' ? '/' : `/${slug}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Compare sitemap URLs and content paths with or without a trailing slash. */
|
|
20
|
+
export function normalizePathname(pathname: string): string {
|
|
21
|
+
if (pathname.length > 1 && pathname.endsWith('/')) return pathname.slice(0, -1)
|
|
22
|
+
return pathname || '/'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sitemap `filter` for `@astrojs/sitemap`.
|
|
27
|
+
* Keeps only content-loader pages whose `seo.noindex` is not true.
|
|
28
|
+
* Static routes that are not in the content directory (the style guide, for example) are left out.
|
|
29
|
+
*/
|
|
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
|
+
)
|
|
38
|
+
|
|
39
|
+
return (pageUrl: string) => {
|
|
40
|
+
let pathname = pageUrl
|
|
41
|
+
try {
|
|
42
|
+
pathname = new URL(pageUrl).pathname
|
|
43
|
+
} catch {
|
|
44
|
+
pathname = pageUrl
|
|
45
|
+
}
|
|
46
|
+
return indexable.has(normalizePathname(pathname))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -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>
|