Astro Blanding is the template with which I begin for my clients' websites.
Handle contact form in src/pages/api/contact.ts
.
import queryStringToJSON from "@utils/QueryStringtoJSON"; // This should be built in to JavaScript, but it is not.
import { url } from "@utils/GetURL";
export async function post({request}: {request: Request}) {
const body = queryStringToJSON(await request.text())
await fetch(import.meta.env.SLACK_NOTIFICATION_URL, {
method: "POST",
body: JSON.stringify({
text: ${body.email} just requested a consultation for a website.\n${body.message.replace("+", " ")}
})
})
return Response.redirect(${url}/success
, 307) // Note that this requires that you create a form success /success
route.
}
src/config.ts
astro.config.mjs
npx astro add netlify
Example:
---
import { Icon } from 'astro-icon'
---
<!-- Automatically fetches and inlines Material Design Icon's "account" SVG -->
<Icon viewBox="2 2 20 20" width="18" height="18" pack="fe" name="github" />
<!-- Should be this, but I think there are still some bugs in the provider -->
<Icon pack="mdi" name="account" />
Figuring out a contact form is annoying, so I have one preconfigured. You only need to handle what happens once the form is submitted. This is done in src/pages/api/contact.ts
.
Preconfigured API routes in the src/pages/api/ab
directory (ab
as an abbreviation for astro-blanding
). Edit the HTML code in src/pages/api/ab/og.ts
to generate custom OG images for your social links. Use the Image
component from @ab/Image.svelte
to have lazy-loaded images using blurhash.
You can change default cache times for images and image previews in src/config
in the imageOptimization
property.
The <Image />
Svelte component is inspired by NextJS's image component.
---
import Image from "@ab/Image.svelte";
---
<Image src="https://github.com/christopher-kapic/astro-blanding/raw/master/github/lighthouse.png" width="300" height="200" alt="lighthouse scores" client:only="svelte" />
<Image />
props
src
- required, string
- a full or relative URL
https://github.com/an/image.png
, /github/lighthouse.png
width
- number
- width of the image in pixels, required unless fill
prop is usedheight
- number
- height of the image in pixels, required unless fill
prop is usedalt
- required, string
- used to describe the image for screen readers and search engines, if the image is purely decorative or not intended for the user, the alt property should be an empty string (eg: alt=""
)fill
- default: false
- a boolean that causes the image to fill the parent element
position: "relative"
, position: "fixed"
, or position: "absolute"
stylestyle
- string
- pass styles as a string, you may want to use this to set the object-fit CSS property.className
- string
- pass HTML class
via stringpreview
- string
- Blurhash preview (will speed up image preview, eg: if you save the preview in your database)