From 3bebbf00e6f4d33bfacbf38eef73a9ad7f0d9d58 Mon Sep 17 00:00:00 2001 From: Tomas Bankauskas Date: Tue, 9 Apr 2024 12:40:31 +0300 Subject: Added Image CDN page (#4) * added image-cdn * updated image-cdn page, colors, etc * added Markdown.astro and updated styles --- src/components/Alert.astro | 16 +++++++ src/components/Markdown.astro | 35 ++++++++++++++ src/layouts/Layout.astro | 40 ++++++++-------- src/pages/_assets/corgi.jpg | Bin 0 -> 587671 bytes src/pages/image-cdn.astro | 105 ++++++++++++++++++++++++++++++++++++++++++ src/styles/globals.css | 43 +++++++++-------- src/utils.js | 4 ++ 7 files changed, 203 insertions(+), 40 deletions(-) create mode 100644 src/components/Alert.astro create mode 100644 src/components/Markdown.astro create mode 100644 src/pages/_assets/corgi.jpg create mode 100644 src/pages/image-cdn.astro create mode 100644 src/utils.js (limited to 'src') diff --git a/src/components/Alert.astro b/src/components/Alert.astro new file mode 100644 index 0000000..1a468fb --- /dev/null +++ b/src/components/Alert.astro @@ -0,0 +1,16 @@ +--- +interface Props { + class?: string; +} + +const { class: className } = Astro.props; +--- + +
+ + + + +
diff --git a/src/components/Markdown.astro b/src/components/Markdown.astro new file mode 100644 index 0000000..d9881a8 --- /dev/null +++ b/src/components/Markdown.astro @@ -0,0 +1,35 @@ +--- +import { Marked } from 'marked'; +import markedShiki from 'marked-shiki'; +import { getHighlighter } from 'shiki'; + +interface Props { + content: string; + class?: string; +} + +const { content, class: className } = Astro.props; + +// `getHighlighter` is async, it initializes the internal and +// loads the languages and themes specified. +// Then later you can use `highlighter.codeToHtml` synchronously +// with the loaded themes and languages. +const highlighter = await getHighlighter({ + langs: ['jsx', 'js'], + themes: ['poimandres'] +}); +const html = await new Marked() + .use( + markedShiki({ + highlight(code, lang, props) { + return highlighter.codeToHtml(code, { + lang, + theme: 'poimandres' + }); + } + }) + ) + .parse(content); +--- + +
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 4ecbd8b..1d5bea1 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,10 +1,10 @@ --- import '../../src/styles/globals.css'; -import Header from "../components/Header.astro"; -import Footer from "../components/Footer.astro"; +import Header from '../components/Header.astro'; +import Footer from '../components/Footer.astro'; interface Props { - title: string; + title: string; } const { title } = Astro.props; @@ -12,20 +12,20 @@ const { title } = Astro.props; - - - {title} - - - - - -
-
-
-
-
-
-
- - \ No newline at end of file + + + {title} + + + + + +
+
+
+
+
+
+
+ + diff --git a/src/pages/_assets/corgi.jpg b/src/pages/_assets/corgi.jpg new file mode 100644 index 0000000..402232f Binary files /dev/null and b/src/pages/_assets/corgi.jpg differ diff --git a/src/pages/image-cdn.astro b/src/pages/image-cdn.astro new file mode 100644 index 0000000..aa1b4e6 --- /dev/null +++ b/src/pages/image-cdn.astro @@ -0,0 +1,105 @@ +--- +import { Image } from 'astro:assets'; +import Layout from '../layouts/Layout.astro'; +import Markdown from '../components/Markdown.astro'; +import corgi from './_assets/corgi.jpg'; + +const sampleImageSrc = '/images/corgi.jpg'; + +const astroImageSnippet = ` +When running on Netlify, \`next/image\` is automatically set-up to use Netlify Image CDN for optimized images. + +~~~jsx +import Image from 'next/image'; + +// In your component +Corgi +~~~ +`; + +const originalVsCdnSnippet = ` +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/). + +~~~jsx +// <== On the left, the original image +Corgi + +// ==> On the right, explicitly using Netlify Image CDN endpoint for a responsive image +Corgi +~~~ +`; +--- + + +
+
+

Image CDN

+
+
+

Using built-in Astro <Image /> component

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

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

+ +
+
+
+
+ + Corgi +
+
+
+
+
+
+ + Corgi +
+
+
+
+
+
+
+
+ + diff --git a/src/styles/globals.css b/src/styles/globals.css index 8846f57..b36e856 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -5,33 +5,36 @@ @tailwind utilities; @layer base { - + h1 { + @apply mb-6 text-4xl font-bold tracking-tight sm:text-5xl; + } + + a { + @apply underline; + } + + pre { + @apply overflow-x-auto p-6 rounded-lg; + } + :not(pre) > code { @apply px-1 py-0.5 font-mono rounded bg-neutral-900 text-yellow-200; font-size: 0.9em; } - h1 { - @apply mb-6 text-4xl font-bold tracking-tight sm:text-5xl; + .markdown > * { + @apply my-6; } -} - -a { - @apply underline -} -.markdown { - @apply mb-1; -} + .markdown > :first-child { + @apply mt-0; + } -.alert .markdown { - @apply mb-0; -} + .markdown > :last-child { + @apply mb-0; + } -.markdown p { - @apply mb-3; + .btn:disabled { + @apply text-neutral-400 bg-neutral-700; + } } - -.btn:disabled { - @apply text-neutral-400 bg-neutral-700; -} \ No newline at end of file diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..d2cc47b --- /dev/null +++ b/src/utils.js @@ -0,0 +1,4 @@ +// Note: this only works on the server side +export function getNetlifyContext() { + return process.env.CONTEXT; +} \ No newline at end of file -- cgit v1.2.3