@coywolf/emdash 0.0.0-stage → 0.35.13
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/LICENSE +21 -0
- package/README.md +201 -2
- package/package.json +70 -5
- package/src/admin/admin-css.ts +57 -0
- package/src/admin/ai.tsx +915 -0
- package/src/admin/backups.tsx +613 -0
- package/src/admin/breadcrumbs.tsx +542 -0
- package/src/admin/codeBlocks.tsx +204 -0
- package/src/admin/customBlocks.tsx +321 -0
- package/src/admin/dirty.ts +20 -0
- package/src/admin/discovery.tsx +463 -0
- package/src/admin/download.ts +28 -0
- package/src/admin/feature-switches.tsx +124 -0
- package/src/admin/features.tsx +142 -0
- package/src/admin/files.tsx +791 -0
- package/src/admin/formUploads.tsx +445 -0
- package/src/admin/guides.tsx +18 -0
- package/src/admin/headings.tsx +262 -0
- package/src/admin/images.tsx +825 -0
- package/src/admin/index.tsx +62 -0
- package/src/admin/links.tsx +980 -0
- package/src/admin/performance.tsx +330 -0
- package/src/admin/preview.tsx +63 -0
- package/src/admin/redirects-removed.tsx +266 -0
- package/src/admin/redirects.tsx +470 -0
- package/src/admin/reviews.tsx +232 -0
- package/src/admin/robots-bots.tsx +647 -0
- package/src/admin/robots-shared.tsx +109 -0
- package/src/admin/robots-wizard.tsx +748 -0
- package/src/admin/robots.tsx +911 -0
- package/src/admin/save-bar.tsx +134 -0
- package/src/admin/schema.tsx +1187 -0
- package/src/admin/search.tsx +355 -0
- package/src/admin/settings-ui.tsx +87 -0
- package/src/admin/trash-prompt-core.ts +135 -0
- package/src/admin/trash-prompt.tsx +156 -0
- package/src/admin/usage.tsx +301 -0
- package/src/admin/videos-display.tsx +248 -0
- package/src/admin/videos.tsx +1202 -0
- package/src/admin/wpImport.tsx +1516 -0
- package/src/ai/entities.ts +59 -0
- package/src/ai/export.ts +61 -0
- package/src/ai/logic.test.ts +187 -0
- package/src/ai/logic.ts +606 -0
- package/src/ai/pack.ts +121 -0
- package/src/ai/prompts.ts +87 -0
- package/src/ai/providers.ts +276 -0
- package/src/ai/queue.test.ts +97 -0
- package/src/ai/routes.ts +359 -0
- package/src/ai/store.ts +301 -0
- package/src/ai/wikidata.test.ts +184 -0
- package/src/ai/wikidata.ts +87 -0
- package/src/ai/worker.ts +530 -0
- package/src/astro/astro-modules.d.ts +6 -0
- package/src/astro/breadcrumbs/Breadcrumbs.astro +129 -0
- package/src/astro/breadcrumbs/BreadcrumbsBlock.astro +12 -0
- package/src/astro/codeBlocks/CodeBlock.astro +62 -0
- package/src/astro/codeBlocks/EmDashCode.astro +61 -0
- package/src/astro/customBlocks/CustomBlock.astro +64 -0
- package/src/astro/customBlocks/Details.astro +8 -0
- package/src/astro/customBlocks/Disclosure.astro +8 -0
- package/src/astro/customBlocks/Note.astro +8 -0
- package/src/astro/customBlocks/Podcast.astro +8 -0
- package/src/astro/customBlocks/Quote.astro +8 -0
- package/src/astro/customBlocks/Testimonial.astro +8 -0
- package/src/astro/files/FileCard.astro +103 -0
- package/src/astro/headings/HeadingBlock.astro +129 -0
- package/src/astro/headings/TableOfContents.astro +45 -0
- package/src/astro/headings/request.ts +19 -0
- package/src/astro/images/ResponsiveImage.astro +60 -0
- package/src/astro/index.ts +84 -0
- package/src/astro/reviews/CoywolfReview.astro +27 -0
- package/src/astro/reviews/Review.astro +49 -0
- package/src/astro/search/SearchBox.astro +61 -0
- package/src/astro/search/SearchBoxForm.astro +509 -0
- package/src/astro/tables/CaptionedTable.astro +72 -0
- package/src/astro/videos/CoywolfVideo.astro +448 -0
- package/src/backups/download.ts +112 -0
- package/src/backups/dump.test.mjs +287 -0
- package/src/backups/dump.ts +288 -0
- package/src/backups/module.ts +276 -0
- package/src/backups/pack.ts +33 -0
- package/src/backups/restore.test.mjs +103 -0
- package/src/backups/restore.ts +209 -0
- package/src/backups/store.ts +409 -0
- package/src/breadcrumbs/pack.ts +113 -0
- package/src/breadcrumbs/settings.ts +102 -0
- package/src/breadcrumbs/stamp.ts +40 -0
- package/src/breadcrumbs/trail.ts +123 -0
- package/src/codeBlocks/contrast.ts +179 -0
- package/src/codeBlocks/hljs.d.ts +5 -0
- package/src/codeBlocks/pack.ts +110 -0
- package/src/codeBlocks/render.test.ts +152 -0
- package/src/codeBlocks/render.ts +304 -0
- package/src/codeBlocks/settings.ts +18 -0
- package/src/codeBlocks/themes.generated.ts +304 -0
- package/src/codeBlocks/themes.ts +114 -0
- package/src/core/compose.ts +244 -0
- package/src/core/content-url.ts +888 -0
- package/src/core/csv.ts +119 -0
- package/src/core/d1-batch.ts +65 -0
- package/src/core/entry-docs.ts +175 -0
- package/src/core/features-module.ts +48 -0
- package/src/core/features.ts +392 -0
- package/src/core/generation.ts +88 -0
- package/src/core/guide-content.ts +166 -0
- package/src/core/module.ts +104 -0
- package/src/core/read-failures.ts +57 -0
- package/src/core/request-memo.ts +71 -0
- package/src/core/secrets.ts +83 -0
- package/src/core/settings-enhance.ts +74 -0
- package/src/core/site.ts +36 -0
- package/src/core/storage.ts +27 -0
- package/src/customBlocks/pack.ts +260 -0
- package/src/customBlocks/render.ts +424 -0
- package/src/customBlocks/rich.ts +313 -0
- package/src/customBlocks/settings.ts +46 -0
- package/src/discovery/build.ts +252 -0
- package/src/discovery/feed-build.ts +217 -0
- package/src/discovery/feed.ts +172 -0
- package/src/discovery/indexnow.ts +114 -0
- package/src/discovery/llms.ts +79 -0
- package/src/discovery/markdown.ts +294 -0
- package/src/discovery/memory-cache.ts +97 -0
- package/src/discovery/middleware.ts +186 -0
- package/src/discovery/module.ts +353 -0
- package/src/discovery/news.ts +99 -0
- package/src/discovery/pack.ts +58 -0
- package/src/discovery/settings.ts +91 -0
- package/src/discovery/urls.ts +35 -0
- package/src/env.d.ts +10 -0
- package/src/files/card.ts +231 -0
- package/src/files/counts.test.ts +114 -0
- package/src/files/counts.ts +60 -0
- package/src/files/export.ts +44 -0
- package/src/files/format.test.ts +93 -0
- package/src/files/format.ts +163 -0
- package/src/files/module.ts +596 -0
- package/src/files/pack.ts +92 -0
- package/src/files/r2-rules.test.ts +30 -0
- package/src/files/r2-rules.ts +41 -0
- package/src/files/range.ts +50 -0
- package/src/files/s3.ts +114 -0
- package/src/files/serve.ts +141 -0
- package/src/files/sigv4.test.ts +64 -0
- package/src/files/sigv4.ts +160 -0
- package/src/files/site.ts +137 -0
- package/src/files/walker.ts +58 -0
- package/src/formUploads/lib.ts +266 -0
- package/src/formUploads/pack.ts +55 -0
- package/src/formUploads/wrap.ts +592 -0
- package/src/forms.ts +16 -0
- package/src/headings/headings.test.ts +159 -0
- package/src/headings/pack.ts +154 -0
- package/src/headings/render.ts +139 -0
- package/src/headings/settings.ts +117 -0
- package/src/headings/slug.ts +68 -0
- package/src/headings/stamp.ts +142 -0
- package/src/headings/test-hooks.mjs +14 -0
- package/src/headings/toc.ts +48 -0
- package/src/images/cloudflare.ts +329 -0
- package/src/images/lib.ts +221 -0
- package/src/images/module.ts +372 -0
- package/src/images/pack.ts +804 -0
- package/src/images/pending.ts +37 -0
- package/src/images/settings.ts +48 -0
- package/src/images/setup.ts +192 -0
- package/src/images/variants-estimate.ts +162 -0
- package/src/images/variants-store.ts +475 -0
- package/src/images/variants.ts +311 -0
- package/src/index.ts +143 -0
- package/src/links/check.ts +101 -0
- package/src/links/classify.ts +270 -0
- package/src/links/export.ts +59 -0
- package/src/links/module.ts +652 -0
- package/src/links/pack.ts +43 -0
- package/src/links/pt.ts +325 -0
- package/src/links/store.ts +704 -0
- package/src/middleware.ts +287 -0
- package/src/modules.ts +53 -0
- package/src/options.ts +66 -0
- package/src/pageCache/lib.test.mjs +224 -0
- package/src/pageCache/lib.ts +274 -0
- package/src/pageCache/pack.ts +240 -0
- package/src/pageCache/usage-core.ts +152 -0
- package/src/pageCache/usage.ts +262 -0
- package/src/pageCache/warm.test.mjs +670 -0
- package/src/pageCache/warm.ts +722 -0
- package/src/redirects/middleware.ts +169 -0
- package/src/redirects/module.ts +124 -0
- package/src/redirects/pack.ts +89 -0
- package/src/redirects/removed-core.ts +151 -0
- package/src/redirects/removed.ts +293 -0
- package/src/redirects/rules.ts +355 -0
- package/src/redirects/slug-changes.ts +207 -0
- package/src/redirects/slug-core.test.ts +50 -0
- package/src/redirects/slug-core.ts +49 -0
- package/src/redirects/transfer.ts +92 -0
- package/src/reviews/lib.ts +624 -0
- package/src/reviews/pack.ts +135 -0
- package/src/reviews/schema.ts +128 -0
- package/src/reviews/settings.ts +26 -0
- package/src/robots/bots.ts +321 -0
- package/src/robots/data/bots.json +696 -0
- package/src/robots/data/verified.json +582 -0
- package/src/robots/directory.ts +26 -0
- package/src/robots/explain.ts +191 -0
- package/src/robots/guided.ts +300 -0
- package/src/robots/importer.ts +263 -0
- package/src/robots/middleware.ts +151 -0
- package/src/robots/module.ts +446 -0
- package/src/robots/pack.ts +69 -0
- package/src/robots/radar.ts +129 -0
- package/src/robots/rep.test.ts +335 -0
- package/src/robots/rep.ts +362 -0
- package/src/robots/rules.test.ts +251 -0
- package/src/robots/rules.ts +883 -0
- package/src/robots/transfer.ts +45 -0
- package/src/robots/validate.ts +524 -0
- package/src/schema/catalog.ts +146 -0
- package/src/schema/graph.test.mjs +522 -0
- package/src/schema/graph.ts +791 -0
- package/src/schema/module.ts +1138 -0
- package/src/schema/og-image.ts +100 -0
- package/src/schema/pack.ts +58 -0
- package/src/search/engine.ts +578 -0
- package/src/search/fallback.ts +80 -0
- package/src/search/live-cache.ts +116 -0
- package/src/search/live-client.ts +770 -0
- package/src/search/live-serve.ts +282 -0
- package/src/search/module.ts +261 -0
- package/src/search/pack.ts +57 -0
- package/src/search/query.ts +132 -0
- package/src/search/ratelimit-core.ts +118 -0
- package/src/search/ratelimit.ts +79 -0
- package/src/search/snippet.ts +135 -0
- package/src/search/title-index.ts +139 -0
- package/src/search/title-match.ts +192 -0
- package/src/shared.ts +71 -0
- package/src/version.ts +2 -0
- package/src/videos/date.ts +40 -0
- package/src/videos/engagement.ts +75 -0
- package/src/videos/lib.ts +679 -0
- package/src/videos/module.ts +1160 -0
- package/src/videos/pack.ts +187 -0
- package/src/videos/pause.ts +42 -0
- package/src/videos/poster.ts +324 -0
- package/src/videos/render.ts +336 -0
- package/src/videos/store.ts +551 -0
- package/src/videos/stream.ts +134 -0
- package/src/wpImport/convert.ts +702 -0
- package/src/wpImport/guests.ts +329 -0
- package/src/wpImport/gutenberg.ts +157 -0
- package/src/wpImport/markers.ts +66 -0
- package/src/wpImport/pack.ts +451 -0
- package/src/wpImport/parents.ts +202 -0
- package/src/wpImport/prepare.ts +592 -0
- package/src/wpImport/redirects.ts +358 -0
- package/src/wpImport/sources.ts +67 -0
- package/src/wpImport/stream.ts +160 -0
- package/src/wpImport/urls.ts +354 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Astro components for the pack's Portable Text blocks, auto-merged into
|
|
3
|
+
* EmDash's <PortableText> (componentsEntry). Keys are block types. Each
|
|
4
|
+
* component checks its feature switch and renders nothing (or EmDash's own
|
|
5
|
+
* renderer) when it's off.
|
|
6
|
+
*/
|
|
7
|
+
import CodeBlock from "./codeBlocks/CodeBlock.astro";
|
|
8
|
+
import FileCard from "./files/FileCard.astro";
|
|
9
|
+
import BreadcrumbsComponent from "./breadcrumbs/Breadcrumbs.astro";
|
|
10
|
+
import BreadcrumbsBlock from "./breadcrumbs/BreadcrumbsBlock.astro";
|
|
11
|
+
import HeadingBlock from "./headings/HeadingBlock.astro";
|
|
12
|
+
import TableOfContents from "./headings/TableOfContents.astro";
|
|
13
|
+
import CoywolfVideo from "./videos/CoywolfVideo.astro";
|
|
14
|
+
import CoywolfReview from "./reviews/CoywolfReview.astro";
|
|
15
|
+
import Review from "./reviews/Review.astro";
|
|
16
|
+
import Note from "./customBlocks/Note.astro";
|
|
17
|
+
import Details from "./customBlocks/Details.astro";
|
|
18
|
+
import Disclosure from "./customBlocks/Disclosure.astro";
|
|
19
|
+
import Quote from "./customBlocks/Quote.astro";
|
|
20
|
+
import Testimonial from "./customBlocks/Testimonial.astro";
|
|
21
|
+
import Podcast from "./customBlocks/Podcast.astro";
|
|
22
|
+
import CaptionedTable from "./tables/CaptionedTable.astro";
|
|
23
|
+
|
|
24
|
+
export const blockComponents = {
|
|
25
|
+
"coywolf-toc": TableOfContents,
|
|
26
|
+
"coywolf-breadcrumbs": BreadcrumbsBlock,
|
|
27
|
+
code: CodeBlock,
|
|
28
|
+
"coywolf-file": FileCard,
|
|
29
|
+
"coywolf-video": CoywolfVideo,
|
|
30
|
+
"coywolf-review": CoywolfReview,
|
|
31
|
+
"coywolf-note": Note,
|
|
32
|
+
"coywolf-details": Details,
|
|
33
|
+
"coywolf-disclosure": Disclosure,
|
|
34
|
+
"coywolf-quote": Quote,
|
|
35
|
+
"coywolf-testimonial": Testimonial,
|
|
36
|
+
"coywolf-podcast": Podcast,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** EmDash's table, keyboard-scrollable, with its `caption` (tables imported from WordPress). In `portableTextComponents`. */
|
|
40
|
+
export { CaptionedTable };
|
|
41
|
+
|
|
42
|
+
/** Videos module: the Stream player, for theme code. */
|
|
43
|
+
export { CoywolfVideo };
|
|
44
|
+
export { hostedPosterImage } from "../videos/poster.js";
|
|
45
|
+
|
|
46
|
+
/** Breadcrumb trail for theme layouts (Breadcrumb Nav module). */
|
|
47
|
+
export { BreadcrumbsComponent as Breadcrumbs };
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Pass to <PortableText components={...}> so headings get their anchor ids
|
|
51
|
+
* (Headings & TOC module) and tables are keyboard-scrollable, with their
|
|
52
|
+
* caption. Plugins can't override EmDash's `block` renderer.
|
|
53
|
+
*/
|
|
54
|
+
export const portableTextComponents = { block: HeadingBlock, type: { table: CaptionedTable } };
|
|
55
|
+
/** Search module: the SearchBox component and OR-fallback search for site search pages. */
|
|
56
|
+
export { default as SearchBox } from "./search/SearchBox.astro";
|
|
57
|
+
export { searchWithFallback } from "../search/query.js";
|
|
58
|
+
export type { PackSearchOptions, PackSearchResponse, PackSearchResult } from "../search/query.js";
|
|
59
|
+
export { entryUrl, entryUrls, matchEntryPath } from "../core/content-url.js";
|
|
60
|
+
export type { EntryRef, MatchedEntry } from "../core/content-url.js";
|
|
61
|
+
/** Reviews module: the review box for theme code, and legacy WordPress review marker attrs → review fields. */
|
|
62
|
+
export { Review };
|
|
63
|
+
export { reviewFromAttrs } from "../reviews/lib.js";
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Clean Image URLs module: cleanImageUrl builds resized-image URLs for theme
|
|
67
|
+
* images (on the media host when one is set, else /media/<id>-<w>x<h>.<format>;
|
|
68
|
+
* null when off); originalImageUrl (alias mediaUrl) gives the original file
|
|
69
|
+
* on the media host (falls back to the source).
|
|
70
|
+
*/
|
|
71
|
+
export { cleanImageUrl, imageDimensions, mediaUrl, originalImageUrl } from "../images/pack.js";
|
|
72
|
+
export type { ImageDimensions } from "../images/pack.js";
|
|
73
|
+
/**
|
|
74
|
+
* Stored image sizes: imageInfo reads every image of a page in one query
|
|
75
|
+
* (call it once with all of them); responsiveImage (widths) and croppedImage
|
|
76
|
+
* (the site's crops) then give AVIF and WebP srcsets for a <picture>, or null
|
|
77
|
+
* until they exist (fall back to cleanImageUrl). markPendingMedia marks a
|
|
78
|
+
* page that showed a stopgap so it's cached briefly.
|
|
79
|
+
*/
|
|
80
|
+
export { croppedImage, imageInfo, responsiveImage } from "../images/pack.js";
|
|
81
|
+
export type { ImageInfo, ResponsiveImage as ResponsiveImageSources } from "../images/pack.js";
|
|
82
|
+
export { markPendingMedia } from "../images/pending.js";
|
|
83
|
+
export { default as ResponsiveImage } from "./images/ResponsiveImage.astro";
|
|
84
|
+
export { cleanImagePath, mediaFile } from "../images/lib.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Portable Text `coywolf-review` block (Reviews module). Renders nothing when
|
|
4
|
+
* the Reviews feature is off. Schema comes from the page:metadata hook /
|
|
5
|
+
* Schema & Social's graph, not from here.
|
|
6
|
+
*/
|
|
7
|
+
import { siteFeatureOn } from "../../core/features.js";
|
|
8
|
+
import Review from "./Review.astro";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
node: Record<string, unknown>;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { node } = Astro.props;
|
|
16
|
+
|
|
17
|
+
// Claim the per-page CSS synchronously, before any await, so the first block
|
|
18
|
+
// in document order carries it even when siblings render in parallel.
|
|
19
|
+
const locals = (Astro.locals ?? {}) as Record<string, unknown>;
|
|
20
|
+
const first = !locals.__cwReviewAssets;
|
|
21
|
+
locals.__cwReviewAssets = true;
|
|
22
|
+
|
|
23
|
+
const on = Boolean(node) && (await siteFeatureOn("reviews"));
|
|
24
|
+
if (!on && first) locals.__cwReviewAssets = false;
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
{on && <Review review={node} styles={first} />}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The review box (Reviews module), for themes: renders a review in the same
|
|
4
|
+
* markup and style as the Coywolf Review block, including the accent color
|
|
5
|
+
* and custom CSS from the Reviews page. Not gated by the feature switch: a
|
|
6
|
+
* theme that uses it has opted in.
|
|
7
|
+
*
|
|
8
|
+
* <Review review={{ itemName, rating: 4.5, pros: ["…"], cons: ["…"] }} />
|
|
9
|
+
* <Review attrs={markerAttrs} /> (legacy WordPress review marker:
|
|
10
|
+
* { name, brand, rating, strengths, shortcomings })
|
|
11
|
+
* <Review {...markerAttrs} /> (same, spread)
|
|
12
|
+
*
|
|
13
|
+
* Schema isn't printed here; pass the same reviews as page.coywolf.reviews
|
|
14
|
+
* (see reviewFromAttrs) and Review schema adds them to the page's JSON-LD.
|
|
15
|
+
* The CSS is inlined once per page, before the first box, so no layout shift.
|
|
16
|
+
*/
|
|
17
|
+
import { normalizeReview, pageCss, renderReviewHtml, reviewFromAttrs } from "../../reviews/lib.js";
|
|
18
|
+
import { siteReviewStyle } from "../../reviews/settings.js";
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
/** Block-shaped fields (itemName, itemType, brand, itemUrl, image, rating, pros, cons, …). */
|
|
22
|
+
review?: Record<string, unknown>;
|
|
23
|
+
/** Legacy WordPress review marker attributes. */
|
|
24
|
+
attrs?: Record<string, unknown>;
|
|
25
|
+
/** Set by the block renderer, which claims the page's CSS before its own await. */
|
|
26
|
+
styles?: boolean;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const props = Astro.props as Props;
|
|
31
|
+
const source =
|
|
32
|
+
props.review ??
|
|
33
|
+
(props.attrs ? reviewFromAttrs(props.attrs) : "strengths" in props || "shortcomings" in props ? reviewFromAttrs(props) : props);
|
|
34
|
+
const review = normalizeReview(source);
|
|
35
|
+
|
|
36
|
+
const locals = (Astro.locals ?? {}) as Record<string, unknown>;
|
|
37
|
+
let first: boolean;
|
|
38
|
+
if (typeof props.styles === "boolean") first = props.styles;
|
|
39
|
+
else {
|
|
40
|
+
first = Boolean(review) && !locals.__cwReviewAssets;
|
|
41
|
+
if (review) locals.__cwReviewAssets = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const html = review ? renderReviewHtml(review) : "";
|
|
45
|
+
const css = first ? pageCss(await siteReviewStyle()) : "";
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
{css && <style is:inline set:html={css} />}
|
|
49
|
+
{html && <Fragment set:html={html} />}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* SearchBox: a search form (feature "search.box") with live results as you
|
|
4
|
+
* type while "search.live" is on.
|
|
5
|
+
*
|
|
6
|
+
* ```astro
|
|
7
|
+
* ---
|
|
8
|
+
* import { SearchBox } from "@coywolf/emdash/astro";
|
|
9
|
+
* ---
|
|
10
|
+
* <SearchBox action="/search" collections={["posts", "pages"]} />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Without JavaScript it's a plain GET form to `action` (?q=…), so the site's
|
|
14
|
+
* search page handles it. With JavaScript, suggestions come from the pack's
|
|
15
|
+
* live results route: titles first, then full text (with excerpts), then
|
|
16
|
+
* results for any of the words when nothing matches all of them. Renders
|
|
17
|
+
* nothing while "search.box" is off, and a plain form while "search.live"
|
|
18
|
+
* is off. Colors are CSS custom properties (--cw-search-*).
|
|
19
|
+
*/
|
|
20
|
+
import { isOn, siteFeatures } from "../../core/features.js";
|
|
21
|
+
import SearchBoxForm from "./SearchBoxForm.astro";
|
|
22
|
+
|
|
23
|
+
export interface Props {
|
|
24
|
+
/** The site's search results page. Default "/search". */
|
|
25
|
+
action?: string;
|
|
26
|
+
/** Query parameter name. Default "q". */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Field label (visually hidden unless showLabel). Default "Search". */
|
|
29
|
+
label?: string;
|
|
30
|
+
showLabel?: boolean;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
/** Collections to suggest from (default: every searchable collection). */
|
|
33
|
+
collections?: string[];
|
|
34
|
+
/** Locale to search (default: the page's locale; null for all). */
|
|
35
|
+
locale?: string | null;
|
|
36
|
+
/** Characters before suggesting. Default 2. */
|
|
37
|
+
minChars?: number;
|
|
38
|
+
/** Milliseconds to wait after typing. Default 200. */
|
|
39
|
+
debounce?: number;
|
|
40
|
+
/** Suggestions to show. Default 8. */
|
|
41
|
+
limit?: number;
|
|
42
|
+
/** Show the content type (e.g. "Post") beside each suggestion. Default true. */
|
|
43
|
+
showType?: boolean;
|
|
44
|
+
/** Show a matching excerpt under each suggestion. Default true. */
|
|
45
|
+
showSnippets?: boolean;
|
|
46
|
+
/** Show a submit button. Default true. */
|
|
47
|
+
submitButton?: boolean;
|
|
48
|
+
/** Value to start with, e.g. the current query on the results page. */
|
|
49
|
+
value?: string;
|
|
50
|
+
class?: string;
|
|
51
|
+
/** Base for element ids (needed when a page has more than one box). Default "cw-search". */
|
|
52
|
+
id?: string;
|
|
53
|
+
/** D1 binding of the site database, for the feature switch. Default "DB". */
|
|
54
|
+
database?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { database, ...props } = Astro.props;
|
|
58
|
+
const features = await siteFeatures(database);
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
{isOn(features, "search.box") && <SearchBoxForm {...props} live={isOn(features, "search.live")} />}
|