From be4de751ad432f8230d83e1d6cbb3e56d608cd58 Mon Sep 17 00:00:00 2001 From: TomasBankauskas Date: Tue, 9 Apr 2024 13:44:24 +0300 Subject: updates --- src/assets/corgi.jpg | Bin 0 -> 587671 bytes src/components/Card.astro | 37 +++++++++++------------- src/components/ContextAlert.astro | 28 ++++++++++++++++++ src/components/EdgeFunctionExplainer.astro | 24 ++++++++++++++++ src/components/Footer.astro | 11 ++------ src/components/Header.astro | 30 ++++++++++---------- src/pages/_assets/corgi.jpg | Bin 587671 -> 0 bytes src/pages/blobs.astro | 6 +--- src/pages/edge/australia/index.astro | 9 ++++++ src/pages/edge/index.astro | 21 ++++++++++++++ src/pages/edge/not-australia/index.astro | 9 ++++++ src/pages/image-cdn.astro | 44 +++++++++++++++++++---------- src/pages/index.astro | 23 ++++++--------- src/styles/globals.css | 18 +++++++++--- 14 files changed, 178 insertions(+), 82 deletions(-) create mode 100644 src/assets/corgi.jpg create mode 100644 src/components/ContextAlert.astro create mode 100644 src/components/EdgeFunctionExplainer.astro delete mode 100644 src/pages/_assets/corgi.jpg create mode 100644 src/pages/edge/australia/index.astro create mode 100644 src/pages/edge/index.astro create mode 100644 src/pages/edge/not-australia/index.astro (limited to 'src') diff --git a/src/assets/corgi.jpg b/src/assets/corgi.jpg new file mode 100644 index 0000000..402232f Binary files /dev/null and b/src/assets/corgi.jpg differ diff --git a/src/components/Card.astro b/src/components/Card.astro index cbe0b0a..da68297 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -1,29 +1,26 @@ --- interface Props { - title?: string; - text?: string; - linkText?: string; - href?: string; + title?: string; + text?: string; + linkText?: string; + href?: string; } const { title, text, linkText, href } = Astro.props; ---
-
- {title &&

{title}

} - {text &&

{text}

} - { - linkText && href && ( - - ) - } -
+
+ {title &&

{title}

} + {text &&

{text}

} + { + linkText && href && ( + + ) + } +
diff --git a/src/components/ContextAlert.astro b/src/components/ContextAlert.astro new file mode 100644 index 0000000..ed54565 --- /dev/null +++ b/src/components/ContextAlert.astro @@ -0,0 +1,28 @@ +--- +import Alert from './Alert.astro'; +import Markdown from './Markdown.astro'; +import { getNetlifyContext } from '../utils'; + +const noNetlifyContextAlert = ` +For full functionality, either run this site locally via \`netlify dev\` +([see docs](https://docs.netlify.com/cli/local-development/")) or deploy it to Netlify. +`; + +const { addedChecksFunction, class: className } = Astro.props; +const ctx = getNetlifyContext(); + +let markdownText = null; +if (!ctx) { + markdownText = noNetlifyContextAlert; +} else if (addedChecksFunction) { + markdownText = addedChecksFunction(ctx); +} +--- + +{ + markdownText && ( + + + + ) +} diff --git a/src/components/EdgeFunctionExplainer.astro b/src/components/EdgeFunctionExplainer.astro new file mode 100644 index 0000000..fb6e6ae --- /dev/null +++ b/src/components/EdgeFunctionExplainer.astro @@ -0,0 +1,24 @@ +--- +import Markdown from './Markdown.astro'; + +const explainer = ` +This page is using a Netlify Edge Function (\`netlify/edge-functions/rewrite.js\`) to rewrite the URL based on visitor geography. + +~~~js +const rewrite = async (request, context) => { + const path = context.geo?.country?.code === 'AU' ? '/edge/australia' : '/edge/not-australia'; + return new URL(path, request.url); +}; + +export const config = { + path: '/edge' +}; + +export default rewrite; +~~~ + +[See more examples](https://edge-functions-examples.netlify.app) +`; +--- + + diff --git a/src/components/Footer.astro b/src/components/Footer.astro index dd98602..9eb5917 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -3,12 +3,7 @@ --- diff --git a/src/components/Header.astro b/src/components/Header.astro index 724150e..e06ea28 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -12,18 +12,18 @@ const navItems = [ Netlify logo - {!!navItems?.length && ( - - )} - \ No newline at end of file + { + !!navItems?.length && ( + + ) + } + + diff --git a/src/pages/_assets/corgi.jpg b/src/pages/_assets/corgi.jpg deleted file mode 100644 index 402232f..0000000 Binary files a/src/pages/_assets/corgi.jpg and /dev/null differ diff --git a/src/pages/blobs.astro b/src/pages/blobs.astro index 61da040..2884c4a 100644 --- a/src/pages/blobs.astro +++ b/src/pages/blobs.astro @@ -3,10 +3,6 @@ import Layout from "../layouts/Layout.astro"; --- -
-
-

Blobs x Blobs

+

Blobs x Blobs

Get started with Astro.js and Netlify in seconds.

-
-
diff --git a/src/pages/edge/australia/index.astro b/src/pages/edge/australia/index.astro new file mode 100644 index 0000000..59965dd --- /dev/null +++ b/src/pages/edge/australia/index.astro @@ -0,0 +1,9 @@ +--- +import Layout from "../../../layouts/Layout.astro"; +import EdgeFunctionExplainer from "../../../components/EdgeFunctionExplainer.astro"; +--- + + +

You are in Australia!

+ +
diff --git a/src/pages/edge/index.astro b/src/pages/edge/index.astro new file mode 100644 index 0000000..f49f3a9 --- /dev/null +++ b/src/pages/edge/index.astro @@ -0,0 +1,21 @@ +--- +import Layout from '../../layouts/Layout.astro'; +import Markdown from '../../components/Markdown.astro'; + +const explainer = ` +# You've reached the fallback page. + +This page is using a [Netlify Edge Function](https://docs.netlify.com/edge-functions/overview/) to rewrite the URL based on visitor geography. + +For it to be invoked, please either run this site locally with \`netlify dev\` or deploy it to Netlify. + +Edge Functions are framework-agnostic, but are also used behind the scenes to run Next.js Middleware on Netlify. +There are advatanges to using Edge Functions directly, such as the ability to access & transform the response body. + +[See more examples](https://edge-functions-examples.netlify.app) +`; +--- + + + + diff --git a/src/pages/edge/not-australia/index.astro b/src/pages/edge/not-australia/index.astro new file mode 100644 index 0000000..74c2577 --- /dev/null +++ b/src/pages/edge/not-australia/index.astro @@ -0,0 +1,9 @@ +--- +import Layout from '../../../layouts/Layout.astro'; +import EdgeFunctionExplainer from '../../../components/EdgeFunctionExplainer.astro'; +--- + + +

You're not in Australia!

+ +
diff --git a/src/pages/image-cdn.astro b/src/pages/image-cdn.astro index aa1b4e6..8847536 100644 --- a/src/pages/image-cdn.astro +++ b/src/pages/image-cdn.astro @@ -1,12 +1,20 @@ --- import { Image } from 'astro:assets'; +import ContextAlert from '../components/ContextAlert.astro'; import Layout from '../layouts/Layout.astro'; import Markdown from '../components/Markdown.astro'; -import corgi from './_assets/corgi.jpg'; +import corgi from '../assets/corgi.jpg'; +import { getNetlifyContext } from '../utils'; -const sampleImageSrc = '/images/corgi.jpg'; +const sampleImage = '/images/corgi.jpg'; + +const ctx = getNetlifyContext(); +const forceWebP = ctx === 'dev'; +const sampleImageNetlify = `/.netlify/images?url=${sampleImage}${forceWebP ? '&fm=webp' : ''}`; const astroImageSnippet = ` +## Using built-in Astro <Image /> component + When running on Netlify, \`next/image\` is automatically set-up to use Netlify Image CDN for optimized images. ~~~jsx @@ -18,6 +26,8 @@ import Image from 'next/image'; `; const originalVsCdnSnippet = ` +## Original vs. optimized image: can you tell the difference? + In the code below, a regular \`\` tag is used in both cases for a framework-agnostic example. Other than using \`next/image\` or rolling your own \`\` tags, you can also use the excellent [unpic-img](https://unpic.pics/). @@ -33,37 +43,41 @@ Other than using \`next/image\` or rolling your own \`\` tags, you can also /> ~~~ `; + +const devModeWarning = ` +In local development, optimization is performed locally without automatic format +detection, so format is set to WebP. +`; --- -
-
-

Image CDN

+
+
+ { + return ctx === "dev" ? devModeWarning : null; + } + } /> +

Image CDN

-

Using built-in Astro <Image /> component

Corgi
- Credit: photo by Alvan Nee on - - Unsplash - + Credit: photo by Alvan Nee on + Unsplash
-

Original vs. optimized image: can you tell the difference?

- Corgi + Corgi
@@ -71,7 +85,7 @@ Other than using \`next/image\` or rolling your own \`\` tags, you can also
- Corgi + Corgi
diff --git a/src/pages/index.astro b/src/pages/index.astro index 2a3c105..8955471 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,20 +1,13 @@ --- -import Layout from "../layouts/Layout.astro"; -import Card from "../components/Card.astro"; +import Layout from '../layouts/Layout.astro'; +import Card from '../components/Card.astro'; --- -
-
-

Netlify Platform Starter - Astro.js

-

Get started with Astro.js and Netlify in seconds.

- - Read the Docs - - -
-
+

Netlify Platform Starter - Astro.js

+

Get started with Astro.js and Netlify in seconds.

+

+ Read the Docs +

+
diff --git a/src/styles/globals.css b/src/styles/globals.css index b36e856..dabf3e4 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -6,15 +6,19 @@ @layer base { h1 { - @apply mb-6 text-4xl font-bold tracking-tight sm:text-5xl; + @apply text-4xl font-bold tracking-tight sm:text-5xl; + } + + h2 { + @apply text-2xl font-bold sm:text-3xl } a { - @apply underline; + @apply underline transition hover:opacity-80; } pre { - @apply overflow-x-auto p-6 rounded-lg; + @apply p-6 overflow-x-auto rounded-lg; } :not(pre) > code { @@ -22,7 +26,13 @@ font-size: 0.9em; } - .markdown > * { + .markdown > h1, + .markdown > h2 { + @apply mt-12 mb-6; + } + + .markdown > p, + .markdown > pre { @apply my-6; } -- cgit v1.2.3