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 --- .gitignore | 3 ++ .prettierrc | 14 ++++++ astro.config.mjs | 11 +++-- package-lock.json | 22 +++++++++ package.json | 2 + 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 ++ tailwind.config.mjs | 6 +-- 13 files changed, 254 insertions(+), 47 deletions(-) create mode 100644 .prettierrc 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 diff --git a/.gitignore b/.gitignore index 6d4c0aa..0077615 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ pnpm-debug.log* # macOS-specific files .DS_Store + +# Local Netlify folder +.netlify diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ae04475 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,14 @@ +{ + "printWidth": 160, + "singleQuote": true, + "trailingComma": "none", + "tabWidth": 4, + "overrides": [ + { + "files": ["*.md", "*.mdx", "*.yaml"], + "options": { + "tabWidth": 2 + } + } + ] +} \ No newline at end of file diff --git a/astro.config.mjs b/astro.config.mjs index 461bd30..0798920 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,8 +1,11 @@ import { defineConfig } from 'astro/config'; - -import tailwind from "@astrojs/tailwind"; +import tailwind from '@astrojs/tailwind'; // https://astro.build/config export default defineConfig({ - integrations: [tailwind()] -}); \ No newline at end of file + integrations: [ + tailwind({ + applyBaseStyles: false + }) + ] +}); diff --git a/package-lock.json b/package-lock.json index 2b65a28..00d3e2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,8 @@ "dependencies": { "@astrojs/tailwind": "^5.1.0", "astro": "^4.5.14", + "marked": "^12.0.1", + "marked-shiki": "^1.0.1", "tailwindcss": "^3.4.3" }, "devDependencies": { @@ -3190,6 +3192,26 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/marked": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.1.tgz", + "integrity": "sha512-Y1/V2yafOcOdWQCX0XpAKXzDakPOpn6U0YLxTJs3cww6VxOzZV1BTOOYWLvH3gX38cq+iLwljHHTnMtlDfg01Q==", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/marked-shiki": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/marked-shiki/-/marked-shiki-1.0.1.tgz", + "integrity": "sha512-fVz5Gq4ZBEptQH4kZTpNfILLxnBONxrXdpjko7rfXm68psltGaZL5VcR1xNNbF/ZN7W4u7ba5fxM+bzzEZoPlQ==", + "peerDependencies": { + "marked": ">=7.0.0", + "shiki": ">=1.0.0" + } + }, "node_modules/mdast-util-definitions": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/mdast-util-definitions/-/mdast-util-definitions-6.0.0.tgz", diff --git a/package.json b/package.json index 6db7e80..a089f6e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ "dependencies": { "@astrojs/tailwind": "^5.1.0", "astro": "^4.5.14", + "marked": "^12.0.1", + "marked-shiki": "^1.0.1", "tailwindcss": "^3.4.3" }, "devDependencies": { 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 diff --git a/tailwind.config.mjs b/tailwind.config.mjs index 507c93e..87a222b 100644 --- a/tailwind.config.mjs +++ b/tailwind.config.mjs @@ -22,10 +22,10 @@ export default { { lofi: { ...require('daisyui/src/theming/themes')['lofi'], - primary: '#2bdcd2', + primary: '#fbb13d', 'primary-content': '#171717', - secondary: '#016968', - info: '#2bdcd2', + secondary: '#0f766e', + info: '#fbb13d', 'info-content': '#171717', } } -- cgit v1.2.3