From be4de751ad432f8230d83e1d6cbb3e56d608cd58 Mon Sep 17 00:00:00 2001 From: TomasBankauskas Date: Tue, 9 Apr 2024 13:44:24 +0300 Subject: updates --- 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 ++++++++++++------------ 5 files changed, 87 insertions(+), 43 deletions(-) create mode 100644 src/components/ContextAlert.astro create mode 100644 src/components/EdgeFunctionExplainer.astro (limited to 'src/components') 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 && ( + + ) + } + + -- cgit v1.2.3