diff options
| author | TomasBankauskas <tbdizainas@gmail.com> | 2024-04-09 13:44:24 +0300 |
|---|---|---|
| committer | TomasBankauskas <tbdizainas@gmail.com> | 2024-04-09 13:44:24 +0300 |
| commit | be4de751ad432f8230d83e1d6cbb3e56d608cd58 (patch) | |
| tree | 7922668f00823e21ab7ab799fa4cf5c811bf0613 /src | |
| parent | 3bebbf00e6f4d33bfacbf38eef73a9ad7f0d9d58 (diff) | |
updates
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets/corgi.jpg (renamed from src/pages/_assets/corgi.jpg) | bin | 587671 -> 587671 bytes | |||
| -rw-r--r-- | src/components/Card.astro | 37 | ||||
| -rw-r--r-- | src/components/ContextAlert.astro | 28 | ||||
| -rw-r--r-- | src/components/EdgeFunctionExplainer.astro | 24 | ||||
| -rw-r--r-- | src/components/Footer.astro | 11 | ||||
| -rw-r--r-- | src/components/Header.astro | 30 | ||||
| -rw-r--r-- | src/pages/blobs.astro | 6 | ||||
| -rw-r--r-- | src/pages/edge/australia/index.astro | 9 | ||||
| -rw-r--r-- | src/pages/edge/index.astro | 21 | ||||
| -rw-r--r-- | src/pages/edge/not-australia/index.astro | 9 | ||||
| -rw-r--r-- | src/pages/image-cdn.astro | 44 | ||||
| -rw-r--r-- | src/pages/index.astro | 23 | ||||
| -rw-r--r-- | src/styles/globals.css | 18 |
13 files changed, 178 insertions, 82 deletions
diff --git a/src/pages/_assets/corgi.jpg b/src/assets/corgi.jpg Binary files differindex 402232f..402232f 100644 --- a/src/pages/_assets/corgi.jpg +++ b/src/assets/corgi.jpg 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; --- <div class="bg-white text-neutral-600 card"> - <div class="card-body"> - {title && <h3 class="text-neutral-900 card-title">{title}</h3>} - {text && <p>{text}</p>} - { - linkText && href && ( - <div class="card-actions"> - <a - href={href} - class="transition link text-neutral-900 hover:opacity-80" - > - {linkText} - </a> - </div> - ) - } - </div> + <div class="card-body"> + {title && <h3 class="text-neutral-900 card-title">{title}</h3>} + {text && <p>{text}</p>} + { + linkText && href && ( + <div class="card-actions"> + <a href={href} class="link text-neutral-900"> + {linkText} + </a> + </div> + ) + } + </div> </div> 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 && ( + <Alert class={className}> + <Markdown content={markdownText} /> + </Alert> + ) +} 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) +`; +--- + +<Markdown content={explainer} /> 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 @@ --- <footer class="pt-16 pb-12 sm:pt-24 sm:pb-16"> - <p class="text-sm"> - <a - href="https://docs.netlify.com/frameworks/astro/" - class="underline transition decoration-dashed text-primary underline-offset-8 hover:opacity-80" - > - Astro.js on Netlify - </a> - </p> + <p class="text-sm"> + <a href="https://docs.netlify.com/frameworks/astro/" class="decoration-dashed text-primary underline-offset-8"> Astro.js on Netlify </a> + </p> </footer> 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 = [ <a href="/"> <img src="/netlify-logo.svg" alt="Netlify logo" /> </a> - {!!navItems?.length && ( - <ul class="flex flex-wrap gap-x-4 gap-y-1"> - {navItems.map((item) => ( - <li> - <a - href={item.href} - class="inline-block px-1.5 py-1 transition hover:opacity-80 sm:px-3 sm:py-2" - > - {item.linkText} - </a> - </li> - ))} - </ul> - )} -</nav>
\ No newline at end of file + { + !!navItems?.length && ( + <ul class="flex flex-wrap gap-x-4 gap-y-1"> + {navItems.map((item) => ( + <li> + <a href={item.href} class="inline-block px-1.5 py-1 sm:px-3 sm:py-2"> + {item.linkText} + </a> + </li> + ))} + </ul> + ) + } +</nav> + 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"; --- <Layout title="Blobs"> - <main class="flex flex-col gap-8 sm:gap-16"> - <section class="flex flex-col items-start gap-3 sm:gap-4"> - <h1>Blobs x Blobs</h1> + <h1 class="mb-8">Blobs x Blobs</h1> <p class="text-lg">Get started with Astro.js and Netlify in seconds.</p> - </section> - </main> </Layout> 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"; +--- + +<Layout title="In Australia"> + <h1 class="mb-8">You are in Australia!</h1> + <EdgeFunctionExplainer /> +</Layout> 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) +`; +--- + +<Layout title="Fallback"> + <Markdown content={explainer} /> +</Layout> 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'; +--- + +<Layout title="Not Autralia"> + <h1 class="mb-8">You're not in Australia!</h1> + <EdgeFunctionExplainer /> +</Layout> 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 \`<img>\` tag is used in both cases for a framework-agnostic example. Other than using \`next/image\` or rolling your own \`<img>\` 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 \`<img>\` tags, you can also /> ~~~ `; + +const devModeWarning = ` +In local development, optimization is performed locally without automatic format +detection, so format is set to WebP. +`; --- <Layout title="Image CDN"> - <div class="flex flex-col gap-8 sm:gap-16"> - <section> - <h1 class="mb-0">Image CDN</h1> + <div class="flex flex-col gap-12 sm:gap-16"> + <section class="space-y-8"> + <ContextAlert addedChecksFunction={ + (ctx) => { + return ctx === "dev" ? devModeWarning : null; + } + } /> + <h1>Image CDN</h1> </section> <section> - <h2 class="mb-6 text-2xl font-bold sm:text-3xl">Using built-in Astro <Image /> component</h2> <Markdown content={astroImageSnippet} class="mb-8" /> <figure> <Image src={corgi} alt="Corgi" class="border-2 border-white rounded-lg" /> <figcaption class="mt-2 text-sm italic"> - Credit: photo by <a href="https://unsplash.com/@alvannee?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Alvan Nee</a> on - <a - href="https://unsplash.com/photos/long-coated-white-and-brown-dog-lvFlpqEvuRM?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash" - > - Unsplash - </a> + Credit: photo by <a href="https://unsplash.com/@alvannee">Alvan Nee</a> on + <a href="https://unsplash.com/photos/long-coated-white-and-brown-dog-lvFlpqEvuRM"> Unsplash </a> </figcaption> </figure> </section> <section> - <h2 class="mb-6 text-2xl font-bold sm:text-3xl">Original vs. optimized image: can you tell the difference?</h2> <Markdown content={originalVsCdnSnippet} class="mb-8" /> <div class="diff aspect-[3/2] rounded-lg border-2 border-white"> <div class="diff-item-1"> <div> <div class="relative"> <span class="hidden absolute py-1.5 px-2.5 text-sm rounded-lg bg-neutral-900/70 top-2.5 right-2.5"></span> - <img src={`/.netlify/images?url=${sampleImageSrc}`} alt="Corgi" /> + <img src={sampleImageNetlify} alt="Corgi" /> </div> </div> </div> @@ -71,7 +85,7 @@ Other than using \`next/image\` or rolling your own \`<img>\` tags, you can also <div> <div class="relative"> <span class="hidden absolute py-1.5 px-2.5 text-sm rounded-lg bg-neutral-900/70 top-2.5 left-2.5"></span> - <img src={sampleImageSrc} alt="Corgi" /> + <img src={sampleImage} alt="Corgi" /> </div> </div> </div> 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'; --- <Layout title="Welcome to Astro."> - <main class="flex flex-col gap-8 sm:gap-16"> - <section class="flex flex-col items-start gap-3 sm:gap-4"> - <h1 class="mb-0">Netlify Platform Starter - Astro.js</h1> - <p class="text-lg">Get started with Astro.js and Netlify in seconds.</p> - <a - href="https://docs.netlify.com/frameworks/astro/" - class="btn btn-lg btn-primary sm:btn-wide" - > - Read the Docs - </a> - <Card title="Random Title" text="Long random text about Astro.js. Get started with Astro.js and Netlify in seconds." /> - </section> - </main> + <h1 class="mb-8">Netlify Platform Starter - Astro.js</h1> + <p class="mb-6 text-lg">Get started with Astro.js and Netlify in seconds.</p> + <p class="mb-8"> + <a href="https://docs.netlify.com/frameworks/astro/" class="btn btn-lg btn-primary sm:btn-wide">Read the Docs</a> + </p> + <Card title="Random Title" text="Long random text about Astro.js. Get started with Astro.js and Netlify in seconds." /> </Layout> 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; } |
