diff options
30 files changed, 812 insertions, 120 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ca4e8a8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,27 @@ +{ + "editor.tabSize": 4, + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[yaml]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.tabSize": 2 + }, + "[toml]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.tabSize": 2 + }, + "[markdown]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.tabSize": 2 + }, + "typescript.tsdk": "node_modules/typescript/lib", + "files.associations": { + "*.css": "tailwindcss", + } +} @@ -1,4 +1,4 @@ -# Astro Starter +# Astro on Netlify Platform Starter ## Commands @@ -11,4 +11,4 @@ All commands are run from the root of the project, from a terminal: | `npm run build` | Build your production site to `./dist/` | | `npm run preview` | Preview your build locally, before deploying | | `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | -| `npm run astro -- --help` | Get help using the Astro CLI |
\ No newline at end of file +| `npm run astro -- --help` | Get help using the Astro CLI | diff --git a/astro.config.mjs b/astro.config.mjs index 0798920..adb7e74 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,11 +1,16 @@ import { defineConfig } from 'astro/config'; +import netlify from '@astrojs/netlify'; +import react from '@astrojs/react'; import tailwind from '@astrojs/tailwind'; // https://astro.build/config export default defineConfig({ integrations: [ + react(), tailwind({ applyBaseStyles: false }) - ] + ], + output: 'hybrid', + adapter: netlify() }); diff --git a/package-lock.json b/package-lock.json index 00d3e2d..c78a494 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,14 +8,27 @@ "name": "astro-netlify-platform-starter", "version": "0.1.0", "dependencies": { + "@astrojs/netlify": "^5.2.0", + "@astrojs/react": "^3.3.0", "@astrojs/tailwind": "^5.1.0", - "astro": "^4.5.14", + "@fontsource/inter": "^5.0.18", + "@netlify/blobs": "^7.3.0", + "@netlify/functions": "^2.6.0", + "@types/react": "^18.2.79", + "@types/react-dom": "^18.2.25", + "astro": "^4.6.2", + "blobshape": "^1.0.0", "marked": "^12.0.1", - "marked-shiki": "^1.0.1", - "tailwindcss": "^3.4.3" + "marked-shiki": "^1.1.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "tailwindcss": "^3.4.3", + "unique-names-generator": "^4.7.1" }, "devDependencies": { - "daisyui": "^4.9.0" + "@types/blobshape": "^1.0.3", + "@types/node": "^20.12.7", + "daisyui": "^4.10.2" } }, "node_modules/@alloc/quick-lru": { @@ -52,11 +65,11 @@ "integrity": "sha512-6B13lz5n6BrbTqCTwhXjJXuR1sqiX/H6rTxzlXx+lN1NnV4jgnq/KJldCQaUWJzPL5SiWahQyinxAbxQtwgPHA==" }, "node_modules/@astrojs/markdown-remark": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@astrojs/markdown-remark/-/markdown-remark-5.0.0.tgz", - "integrity": "sha512-QBXbxXZamVRoqCNN2gjDXa7qYPUkJZq7KYFfg3DX7rze3QL6xiz4N+Wg202dNPRaIkQa16BV6D8+EHibQFubRg==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@astrojs/markdown-remark/-/markdown-remark-5.1.0.tgz", + "integrity": "sha512-S6Z3K2hOB7MfjeDoHsotnP/q2UsnEDB8NlNAaCjMDsGBZfTUbWxyLW3CaphEWw08f6KLZi2ibK9yC3BaMhh2NQ==", "dependencies": { - "@astrojs/prism": "^3.0.0", + "@astrojs/prism": "^3.1.0", "github-slugger": "^2.0.0", "hast-util-from-html": "^2.0.0", "hast-util-to-text": "^4.0.0", @@ -76,15 +89,46 @@ "vfile": "^6.0.1" } }, + "node_modules/@astrojs/netlify": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@astrojs/netlify/-/netlify-5.2.0.tgz", + "integrity": "sha512-NFg3AdUToV7kbY5w2yHZY5UskqfsmIo9i0zIzQ2GgUcTwjyZCekZ89DLtKCJ1jFVle+QXJGsJAS61EYyptBDBQ==", + "dependencies": { + "@astrojs/underscore-redirects": "^0.3.3", + "@netlify/functions": "^2.0.1", + "esbuild": "^0.19.5" + }, + "peerDependencies": { + "astro": "^4.2.0" + } + }, "node_modules/@astrojs/prism": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@astrojs/prism/-/prism-3.0.0.tgz", - "integrity": "sha512-g61lZupWq1bYbcBnYZqdjndShr/J3l/oFobBKPA3+qMat146zce3nz2kdO4giGbhYDt4gYdhmoBz0vZJ4sIurQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@astrojs/prism/-/prism-3.1.0.tgz", + "integrity": "sha512-Z9IYjuXSArkAUx3N6xj6+Bnvx8OdUSHA8YoOgyepp3+zJmtVYJIl/I18GozdJVW1p5u/CNpl3Km7/gwTJK85cw==", "dependencies": { "prismjs": "^1.29.0" }, "engines": { - "node": ">=18.14.1" + "node": "^18.17.1 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@astrojs/react": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@astrojs/react/-/react-3.3.0.tgz", + "integrity": "sha512-IKHizDgYPTl9TTKcEB+PwmqHqYgCwD3jqd9hGBRITYiMmeiHVMRr2zNNXSmOOv0uWL3/EwsISsrUnjwuxIVZUA==", + "dependencies": { + "@vitejs/plugin-react": "^4.2.0", + "ultrahtml": "^1.3.0" + }, + "engines": { + "node": "^18.17.1 || ^20.3.0 || >=21.0.0" + }, + "peerDependencies": { + "@types/react": "^17.0.50 || ^18.0.21", + "@types/react-dom": "^17.0.17 || ^18.0.6", + "react": "^17.0.2 || ^18.0.0", + "react-dom": "^17.0.2 || ^18.0.0" } }, "node_modules/@astrojs/tailwind": { @@ -102,35 +146,26 @@ } }, "node_modules/@astrojs/telemetry": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@astrojs/telemetry/-/telemetry-3.0.4.tgz", - "integrity": "sha512-A+0c7k/Xy293xx6odsYZuXiaHO0PL+bnDoXOc47sGDF5ffIKdKQGRPFl2NMlCF4L0NqN4Ynbgnaip+pPF0s7pQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@astrojs/telemetry/-/telemetry-3.1.0.tgz", + "integrity": "sha512-/ca/+D8MIKEC8/A9cSaPUqQNZm+Es/ZinRv0ZAzvu2ios7POQSsVD+VOj7/hypWNsNM3T7RpfgNq7H2TU1KEHA==", "dependencies": { - "ci-info": "^3.8.0", + "ci-info": "^4.0.0", "debug": "^4.3.4", "dlv": "^1.1.3", - "dset": "^3.1.2", + "dset": "^3.1.3", "is-docker": "^3.0.0", "is-wsl": "^3.0.0", "which-pm-runs": "^1.1.0" }, "engines": { - "node": ">=18.14.1" + "node": "^18.17.1 || ^20.3.0 || >=21.0.0" } }, - "node_modules/@astrojs/telemetry/node_modules/ci-info": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", - "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/sibiraj-s" - } - ], - "engines": { - "node": ">=8" - } + "node_modules/@astrojs/underscore-redirects": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@astrojs/underscore-redirects/-/underscore-redirects-0.3.3.tgz", + "integrity": "sha512-qDAKhFO4M1KzP7mxoJfiehf8oyf3EB158MxAa6z10NeD2pR3o4K3LlOQI8CfJgXE+BDBQcnaLvVCg/Mz/Gkg4Q==" }, "node_modules/@babel/code-frame": { "version": "7.24.2", @@ -421,6 +456,34 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-react-jsx-self": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.24.1.tgz", + "integrity": "sha512-kDJgnPujTmAZ/9q2CN4m2/lRsUUPDvsG3+tSHWUJIzMGTt5U/b/fwWd3RO3n+5mjLrsBrVa5eKFRVSQbi3dF1w==", + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-react-jsx-source": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.24.1.tgz", + "integrity": "sha512-1v202n7aUq4uXAieRTKcwPzNyphlCuqHHDcdSNc+vdhoTEZcFMh+L5yZuCmGaIO7bs1nJUNfHB89TZyoL48xNA==", + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/template": { "version": "7.24.0", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz", @@ -812,6 +875,11 @@ "node": ">=12" } }, + "node_modules/@fontsource/inter": { + "version": "5.0.18", + "resolved": "https://registry.npmjs.org/@fontsource/inter/-/inter-5.0.18.tgz", + "integrity": "sha512-YCsoYPTcs713sI7tLtxaPrIhXAXvEetGg5Ry02ivA8qUOb3fQHojbK/X9HLD5OOKvFUNR2Ynkwb1kR1hVKQHpw==" + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -892,6 +960,45 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@netlify/blobs": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/@netlify/blobs/-/blobs-7.3.0.tgz", + "integrity": "sha512-wN/kNTZo4xjlUM/C0WILOkJbe8p4AFquSGkZEIoIcgnsx5ikp2GyqGiq1WMLee7QdbnqeIV2g2hn/PjT324E5w==", + "engines": { + "node": "^14.16.0 || >=16.0.0" + } + }, + "node_modules/@netlify/functions": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-2.6.0.tgz", + "integrity": "sha512-vU20tij0fb4nRGACqb+5SQvKd50JYyTyEhQetCMHdakcJFzjLDivvRR16u1G2Oy4A7xNAtGJF1uz8reeOtTVcQ==", + "dependencies": { + "@netlify/serverless-functions-api": "1.14.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@netlify/node-cookies": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@netlify/node-cookies/-/node-cookies-0.1.0.tgz", + "integrity": "sha512-OAs1xG+FfLX0LoRASpqzVntVV/RpYkgpI0VrUnw2u0Q1qiZUzcPffxRK8HF3gc4GjuhG5ahOEMJ9bswBiZPq0g==", + "engines": { + "node": "^14.16.0 || >=16.0.0" + } + }, + "node_modules/@netlify/serverless-functions-api": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@netlify/serverless-functions-api/-/serverless-functions-api-1.14.0.tgz", + "integrity": "sha512-HUNETLNvNiC2J+SB/YuRwJA9+agPrc0azSoWVk8H85GC+YE114hcS5JW+dstpKwVerp2xILE3vNWN7IMXP5Q5Q==", + "dependencies": { + "@netlify/node-cookies": "^0.1.0", + "urlpattern-polyfill": "8.0.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1155,6 +1262,17 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/blobshape": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@types/blobshape/-/blobshape-1.0.3.tgz", + "integrity": "sha512-jbJZ9AIebK77LoeN8PjPyAs88GJCDKO+ZpWCJlLlV2FXkeYScQsvkZmlGHGvSRk/WFmUOdbGJ75umLATGX1lsw==", + "dev": true + }, + "node_modules/@types/cookie": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.5.4.tgz", + "integrity": "sha512-7z/eR6O859gyWIAjuvBWFzNURmf2oPBmJlfVWkwehU5nzIyjwBsTh7WMmEEV4JFnHuQ3ex4oyTvfKzcyJVDBNA==" + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -1202,6 +1320,37 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==" }, + "node_modules/@types/node": { + "version": "20.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", + "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "devOptional": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/prop-types": { + "version": "15.7.12", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", + "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==" + }, + "node_modules/@types/react": { + "version": "18.2.79", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.79.tgz", + "integrity": "sha512-RwGAGXPl9kSXwdNTafkOEuFrTBD5SA2B3iEB96xi8+xu5ddUa/cpvyVCSNn+asgLCTHkb5ZxN8gbuibYJi4s1w==", + "dependencies": { + "@types/prop-types": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@types/react-dom": { + "version": "18.2.25", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.25.tgz", + "integrity": "sha512-o/V48vf4MQh7juIKZU2QGDfli6p1+OOi5oXx36Hffpc9adsHeXjVp8rHuPkjd8VT8sOJ2Zp05HR7CdpGTIUFUA==", + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/unist": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", @@ -1212,6 +1361,24 @@ "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==" }, + "node_modules/@vitejs/plugin-react": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.2.1.tgz", + "integrity": "sha512-oojO9IDc4nCUUi8qIR11KoQm0XFFLIwsRBwHRR4d/88IWghn1y6ckz/bJ8GHDCsYEJee8mDzqtJxh15/cisJNQ==", + "dependencies": { + "@babel/core": "^7.23.5", + "@babel/plugin-transform-react-jsx-self": "^7.23.3", + "@babel/plugin-transform-react-jsx-source": "^7.23.3", + "@types/babel__core": "^7.20.5", + "react-refresh": "^0.14.0" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "peerDependencies": { + "vite": "^4.2.0 || ^5.0.0" + } + }, "node_modules/acorn": { "version": "8.11.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", @@ -1335,14 +1502,14 @@ } }, "node_modules/astro": { - "version": "4.5.14", - "resolved": "https://registry.npmjs.org/astro/-/astro-4.5.14.tgz", - "integrity": "sha512-OXQ9Wbcn5e2eEPrNKJjGXeCWnKamNGyvSwORL0B8BB1fp3OO/EYo/RfeQGTR9kxGNxEpokoPZL9JNgFHoVK+wA==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/astro/-/astro-4.6.2.tgz", + "integrity": "sha512-Kl+Wd7MJMQFnI3+V0JxF4HPbs8M67eltqQgtztReOwDLSl0VnOd39rM61W/3LEh10FZ0F13xrDgtdgfXzuLVbg==", "dependencies": { "@astrojs/compiler": "^2.7.1", "@astrojs/internal-helpers": "0.4.0", - "@astrojs/markdown-remark": "5.0.0", - "@astrojs/telemetry": "3.0.4", + "@astrojs/markdown-remark": "5.1.0", + "@astrojs/telemetry": "3.1.0", "@babel/core": "^7.24.3", "@babel/generator": "^7.23.3", "@babel/parser": "^7.23.3", @@ -1350,6 +1517,7 @@ "@babel/traverse": "^7.23.3", "@babel/types": "^7.23.3", "@types/babel__core": "^7.20.4", + "@types/cookie": "^0.5.4", "acorn": "^8.11.2", "aria-query": "^5.3.0", "axobject-query": "^4.0.0", @@ -1406,8 +1574,9 @@ "astro": "astro.js" }, "engines": { - "node": ">=18.14.1", - "npm": ">=6.14.0" + "node": "^18.17.1 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0" }, "optionalDependencies": { "sharp": "^0.32.6" @@ -1555,6 +1724,11 @@ "readable-stream": "^3.4.0" } }, + "node_modules/blobshape": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/blobshape/-/blobshape-1.0.0.tgz", + "integrity": "sha512-GUD6tUIvj7k8zLSMtfdM1RyusWDjFqYL9g6J6QIgwxbVjL3b6mbRz5peerDc+6kbZX/14BSr3ed9sizrJKdkQQ==" + }, "node_modules/boxen": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/boxen/-/boxen-7.1.1.tgz", @@ -1978,6 +2152,11 @@ "node": ">=4" } }, + "node_modules/csstype": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", + "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" + }, "node_modules/culori": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/culori/-/culori-3.3.0.tgz", @@ -1988,9 +2167,9 @@ } }, "node_modules/daisyui": { - "version": "4.9.0", - "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-4.9.0.tgz", - "integrity": "sha512-9JsDx4E+30kPxThE+6yEwQokqg1957uwTx/skP2RE98fG6Ten6U+S9YXeQg1a3CI958aF5aOb0oEA+KZFfrZUA==", + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-4.10.2.tgz", + "integrity": "sha512-eCWS1W/JPyxW9IvlgW5m0R6rp9ZhRsBTW37rvEUthckkjsV04u8XipV519OoccSA46ixhSJa3q7XLI1WUFtRCA==", "dev": true, "dependencies": { "css-selector-tokenizer": "^0.8", @@ -2691,9 +2870,9 @@ } }, "node_modules/hast-util-to-text": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/hast-util-to-text/-/hast-util-to-text-4.0.0.tgz", - "integrity": "sha512-EWiE1FSArNBPUo1cKWtzqgnuRQwEeQbQtnFJRYV1hb1BWDgrAlBU0ExptvZMM/KSA82cDpm2sFGf3Dmc5Mza3w==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/hast-util-to-text/-/hast-util-to-text-4.0.1.tgz", + "integrity": "sha512-RHL7Vo2n06ZocCFWqmbyhZ1pCYX/mSKdywt9YD5U6Hquu5syV+dImCXFKLFt02JoK5QxkQFS0PoVdFdPXuPffQ==", "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", @@ -3164,6 +3343,17 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -3204,9 +3394,9 @@ } }, "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==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/marked-shiki/-/marked-shiki-1.1.0.tgz", + "integrity": "sha512-PNiC0X4rYnzF63T6CDscwTxQB8l5Aur9XR7MRNBi/Y9nSxmPxasWT+V5OVam8Pj+NycWjzG6idO7fbc2bDD16w==", "peerDependencies": { "marked": ">=7.0.0", "shiki": ">=1.0.0" @@ -4851,6 +5041,37 @@ "rc": "cli.js" } }, + "node_modules/react": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.0" + }, + "peerDependencies": { + "react": "^18.2.0" + } + }, + "node_modules/react-refresh": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz", + "integrity": "sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -5514,6 +5735,14 @@ } ] }, + "node_modules/scheduler": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/section-matter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz", @@ -6096,6 +6325,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/ultrahtml": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/ultrahtml/-/ultrahtml-1.5.3.tgz", + "integrity": "sha512-GykOvZwgDWZlTQMtp5jrD4BVL+gNn2NVlVafjcFUJ7taY20tqYdwdoWBFy6GBJsNTZe1GkGPkSl5knQAjtgceg==" + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "devOptional": true + }, "node_modules/unherit": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/unherit/-/unherit-3.0.1.tgz", @@ -6123,6 +6363,14 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/unique-names-generator": { + "version": "4.7.1", + "resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-4.7.1.tgz", + "integrity": "sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow==", + "engines": { + "node": ">=8" + } + }, "node_modules/unist-util-find-after": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/unist-util-find-after/-/unist-util-find-after-5.0.0.tgz", @@ -6276,6 +6524,11 @@ "browserslist": ">= 4.21.0" } }, + "node_modules/urlpattern-polyfill": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/urlpattern-polyfill/-/urlpattern-polyfill-8.0.2.tgz", + "integrity": "sha512-Qp95D4TPJl1kC9SKigDcqgyM2VDVO4RiJc2d4qe5GrYm+zbIQCWWKAFaJNQ4BhdFeDGwBmAxqJBwWSJDb9T3BQ==" + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index a089f6e..eb7b56a 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,26 @@ "astro": "astro" }, "dependencies": { + "@astrojs/netlify": "^5.2.0", + "@astrojs/react": "^3.3.0", "@astrojs/tailwind": "^5.1.0", - "astro": "^4.5.14", + "@fontsource/inter": "^5.0.18", + "@netlify/blobs": "^7.3.0", + "@netlify/functions": "^2.6.0", + "@types/react": "^18.2.79", + "@types/react-dom": "^18.2.25", + "astro": "^4.6.2", + "blobshape": "^1.0.0", "marked": "^12.0.1", - "marked-shiki": "^1.0.1", - "tailwindcss": "^3.4.3" + "marked-shiki": "^1.1.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "tailwindcss": "^3.4.3", + "unique-names-generator": "^4.7.1" }, "devDependencies": { - "daisyui": "^4.9.0" + "@types/blobshape": "^1.0.3", + "@types/node": "^20.12.7", + "daisyui": "^4.10.2" } } diff --git a/public/images/noise.svg b/public/images/noise.svg deleted file mode 100644 index 17bddaf..0000000 --- a/public/images/noise.svg +++ /dev/null @@ -1,7 +0,0 @@ -<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs" viewBox="0 0 700 700" width="700" height="700"><defs><filter id="nnnoise-filter" x="-20%" y="-20%" width="140%" height="140%" filterUnits="objectBoundingBox" primitiveUnits="userSpaceOnUse" color-interpolation-filters="linearRGB"> - <feTurbulence type="fractalNoise" baseFrequency="0.102" numOctaves="4" seed="15" stitchTiles="stitch" x="0%" y="0%" width="100%" height="100%" result="turbulence"></feTurbulence> - <feSpecularLighting surfaceScale="15" specularConstant="0.75" specularExponent="20" lighting-color="#ffffff" x="0%" y="0%" width="100%" height="100%" in="turbulence" result="specularLighting"> - <feDistantLight azimuth="3" elevation="100"></feDistantLight> - </feSpecularLighting> - -</filter></defs><rect width="700" height="700" fill="transparent"></rect><rect width="700" height="700" fill="#ffffff" filter="url(#nnnoise-filter)" opacity="0.2"></rect></svg>
\ No newline at end of file diff --git a/public/netlify-logo.svg b/public/netlify-logo.svg index 9aa5a20..0183451 100644 --- a/public/netlify-logo.svg +++ b/public/netlify-logo.svg @@ -1,11 +1,11 @@ <svg width="122" height="50" viewBox="0 0 122 50" fill="none" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_175_3110)"> -<path d="M27.9828 49.0799V36.6502L28.2433 36.391H30.8459L31.1065 36.6502V49.0799L30.8459 49.3391H28.2433L27.9828 49.0799Z" fill="#32E6E2"/> -<path d="M27.9828 12.688V0.259198L28.2433 0H30.8459L31.1065 0.259198V12.688L30.8459 12.9472H28.2433L27.9828 12.688Z" fill="#32E6E2"/> -<path d="M16.6687 40.1195H16.3007L14.4605 38.2879V37.9217L18.7575 33.6477L20.7061 33.6486L20.9675 33.9069V35.8454L16.6687 40.1195Z" fill="#32E6E2"/> -<path d="M16.6669 9.21965H16.2988L14.4587 11.0513V11.4174L18.7557 15.6914L20.7042 15.6905L20.9657 15.4322V13.4937L16.6669 9.21965Z" fill="#32E6E2"/> -<path d="M0.260534 23.1157H17.9595L18.2201 23.3749V25.9642L17.9595 26.2234H0.260534L0 25.9642V23.3749L0.260534 23.1157Z" fill="#32E6E2"/> -<path d="M105.082 23.1157H121.74L122.001 23.3749V25.9642L121.74 26.2234H104.041L103.781 25.9642L104.821 23.3749L105.082 23.1157Z" fill="#32E6E2"/> +<path d="M27.9828 49.0799V36.6502L28.2433 36.391H30.8459L31.1065 36.6502V49.0799L30.8459 49.3391H28.2433L27.9828 49.0799Z" fill="#fff"/> +<path d="M27.9828 12.688V0.259198L28.2433 0H30.8459L31.1065 0.259198V12.688L30.8459 12.9472H28.2433L27.9828 12.688Z" fill="#fff"/> +<path d="M16.6687 40.1195H16.3007L14.4605 38.2879V37.9217L18.7575 33.6477L20.7061 33.6486L20.9675 33.9069V35.8454L16.6687 40.1195Z" fill="#fff"/> +<path d="M16.6669 9.21965H16.2988L14.4587 11.0513V11.4174L18.7557 15.6914L20.7042 15.6905L20.9657 15.4322V13.4937L16.6669 9.21965Z" fill="#fff"/> +<path d="M0.260534 23.1157H17.9595L18.2201 23.3749V25.9642L17.9595 26.2234H0.260534L0 25.9642V23.3749L0.260534 23.1157Z" fill="#fff"/> +<path d="M105.082 23.1157H121.74L122.001 23.3749V25.9642L121.74 26.2234H104.041L103.781 25.9642L104.821 23.3749L105.082 23.1157Z" fill="#fff"/> <path d="M50.529 25.7748L50.2685 26.034H42.1946L41.9341 26.2932C41.9341 26.8116 42.4552 28.3659 44.5385 28.3659C45.3201 28.3659 46.1008 28.1067 46.3614 27.5883L46.6219 27.3291H49.7474L50.0079 27.5883C49.7474 29.1425 48.4456 31.4753 44.5385 31.4753C40.1113 31.4753 38.027 28.3659 38.027 24.7389C38.027 21.1119 40.1104 18.0025 44.278 18.0025C48.4456 18.0025 50.529 21.1119 50.529 24.7389V25.7757V25.7748ZM46.6219 23.1837C46.6219 22.9245 46.3614 21.111 44.278 21.111C42.1946 21.111 41.9341 22.9245 41.9341 23.1837L42.1946 23.4429H46.3614L46.6219 23.1837Z" fill="white"/> <path d="M57.8212 27.3291C57.8212 27.8475 58.0818 28.1067 58.6028 28.1067H60.9467L61.2073 28.3659V30.9569L60.9467 31.2161H58.6028C56.2589 31.2161 54.1756 30.1793 54.1756 27.3291V21.6285L53.915 21.3693H52.0922L51.8317 21.1101V18.5191L52.0922 18.2599H53.915L54.1756 18.0007V15.6688L54.4361 15.4096H57.5616L57.8221 15.6688V18.0007L58.0827 18.2599H60.9476L61.2082 18.5191V21.1101L60.9476 21.3693H58.0827L57.8221 21.6285V27.3291H57.8212Z" fill="white"/> <path d="M67.4573 31.2161H64.3318L64.0713 30.9569V13.3378L64.3318 13.0786H67.4573L67.7178 13.3378V30.9569L67.4573 31.2161Z" fill="white"/> diff --git a/src/components/ContextAlert.astro b/src/components/ContextAlert.astro index ed54565..61273c3 100644 --- a/src/components/ContextAlert.astro +++ b/src/components/ContextAlert.astro @@ -5,7 +5,7 @@ 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. +([see docs](https://docs.netlify.com/cli/local-development/)) or deploy it to Netlify. `; const { addedChecksFunction, class: className } = Astro.props; diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 9eb5917..fbf1e8f 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -4,6 +4,6 @@ <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="decoration-dashed text-primary underline-offset-8"> Astro.js on Netlify </a> + <a href="https://docs.netlify.com/frameworks/astro/" class="decoration-dashed text-primary underline-offset-8"> Astro on Netlify </a> </p> </footer> diff --git a/src/components/Markdown.astro b/src/components/Markdown.astro index d9881a8..e8996c5 100644 --- a/src/components/Markdown.astro +++ b/src/components/Markdown.astro @@ -16,7 +16,7 @@ const { content, class: className } = Astro.props; // with the loaded themes and languages. const highlighter = await getHighlighter({ langs: ['jsx', 'js'], - themes: ['poimandres'] + themes: ['min-dark'] }); const html = await new Marked() .use( @@ -24,7 +24,7 @@ const html = await new Marked() highlight(code, lang, props) { return highlighter.codeToHtml(code, { lang, - theme: 'poimandres' + theme: 'min-dark' }); } }) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 1d5bea1..5b37dd5 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,5 +1,7 @@ --- import '../../src/styles/globals.css'; +import '@fontsource/inter/400.css'; +import '@fontsource/inter/800.css'; import Header from '../components/Header.astro'; import Footer from '../components/Footer.astro'; @@ -19,7 +21,7 @@ const { title } = Astro.props; <meta name="generator" content={Astro.generator} /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> </head> - <body class="antialiased text-white bg-teal-600"> + <body class="antialiased text-white bg-[#355C7D]"> <div class="flex flex-col min-h-screen px-6 bg-grid-pattern sm:px-12"> <div class="flex flex-col w-full max-w-5xl mx-auto grow"> <Header /> diff --git a/src/pages/api/blob.ts b/src/pages/api/blob.ts new file mode 100644 index 0000000..4ff37c4 --- /dev/null +++ b/src/pages/api/blob.ts @@ -0,0 +1,20 @@ +import type { APIRoute } from 'astro'; +import { getStore } from '@netlify/blobs'; + +export const prerender = false; + +export const GET: APIRoute = async (context) => { + const urlParams = new URL(context.url); + const key = urlParams.searchParams.get('key'); + if (!key) { + return new Response('Bad Request', { status: 400 }); + } + + const blobStore = getStore('shapes'); + const blob = await blobStore.get(key, { type: 'json' }); + return new Response( + JSON.stringify({ + blob + }) + ); +}; diff --git a/src/pages/api/blobs.ts b/src/pages/api/blobs.ts new file mode 100644 index 0000000..d11aa58 --- /dev/null +++ b/src/pages/api/blobs.ts @@ -0,0 +1,27 @@ +import type { APIRoute } from 'astro'; +import { getStore } from '@netlify/blobs'; + +export const prerender = false; + +export const POST: APIRoute = async ({ request }) => { + const parameters = await request.json(); + const blobStore = getStore('shapes'); + const key = parameters.name; + await blobStore.setJSON(key, parameters); + return new Response( + JSON.stringify({ + message: `Stored shape "${key}"` + }) + ); +}; + +export const GET: APIRoute = async ({ request }) => { + const blobStore = getStore({ name: 'shapes', consistency: 'strong' }); + const data = await blobStore.list(); + const keys = data.blobs.map(({ key }) => key); + return new Response( + JSON.stringify({ + keys + }) + ); +}; diff --git a/src/pages/api/revalidate.ts b/src/pages/api/revalidate.ts new file mode 100644 index 0000000..0d953a3 --- /dev/null +++ b/src/pages/api/revalidate.ts @@ -0,0 +1,19 @@ +import type { APIRoute } from 'astro'; +import { purgeCache } from '@netlify/functions'; + +export const prerender = false; + +export const POST: APIRoute = async ({ request }) => { + const { tags } = await request.json(); + + if (!Array.isArray(tags)) { + return new Response(`Bad Request: expected tags attribute with array of strings in the body, got ${typeof tags}`, { status: 400 }); + } + + await purgeCache({ tags }); + return new Response( + JSON.stringify({ + invalidated: tags + }) + ); +}; diff --git a/src/pages/blobs.astro b/src/pages/blobs.astro deleted file mode 100644 index 2884c4a..0000000 --- a/src/pages/blobs.astro +++ /dev/null @@ -1,8 +0,0 @@ ---- -import Layout from "../layouts/Layout.astro"; ---- - -<Layout title="Blobs"> - <h1 class="mb-8">Blobs x Blobs</h1> - <p class="text-lg">Get started with Astro.js and Netlify in seconds.</p> -</Layout> diff --git a/src/pages/blobs/_components/NewShape.tsx b/src/pages/blobs/_components/NewShape.tsx new file mode 100644 index 0000000..05f9e6f --- /dev/null +++ b/src/pages/blobs/_components/NewShape.tsx @@ -0,0 +1,60 @@ +import { useState, useEffect } from 'react'; +import type { Dispatch, SetStateAction } from 'react'; +import ShapePreview from './ShapePreview.tsx'; +import { generateBlob } from '../../../utils'; +import type { BlobProps } from '../../../types.ts'; + +interface Props { + setLastMutationTime?: Dispatch<SetStateAction<number>>; +} + +export default function NewShape(props: Props) { + const { setLastMutationTime } = props; + const [blobData, setBlobData] = useState<BlobProps>(); + const [wasUploaded, setWasUploaded] = useState<boolean>(false); + + const randomizeBlob = () => { + setBlobData(generateBlob()); + setWasUploaded(false); + }; + + const uploadBlob = async () => { + const response = await fetch('/api/blobs', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(blobData.parameters) + }); + const data = await response.json(); + if (data.message) { + console.log(data.message); + } + setWasUploaded(true); + setLastMutationTime(Date.now()); + }; + + useEffect(() => { + if (!blobData) { + randomizeBlob(); + } + }, [blobData]); + + return ( + <> + <h2 className="mb-4 text-xl text-center sm:text-xl">New Random Shape</h2> + <div className="w-full bg-white rounded-lg mb-6"> + <div className="min-h-14 p-4 border-b border-neutral-200 text-neutral-900 text-center"> + {blobData && <span>{blobData.parameters?.name}</span>} + </div> + <div className="p-4 aspect-square text-primary">{blobData && <ShapePreview {...blobData} />}</div> + </div> + <div className="flex flex-wrap justify-center gap-4"> + <button className="btn btn-primary" onClick={randomizeBlob}> + Randomize + </button> + <button className="btn btn-primary" onClick={uploadBlob} disabled={wasUploaded || !blobData}> + Upload + </button> + </div> + </> + ); +} diff --git a/src/pages/blobs/_components/ShapeEditor.tsx b/src/pages/blobs/_components/ShapeEditor.tsx new file mode 100644 index 0000000..9a339cc --- /dev/null +++ b/src/pages/blobs/_components/ShapeEditor.tsx @@ -0,0 +1,18 @@ +import { useState } from 'react'; +import NewShape from './NewShape.tsx'; +import StoredShapes from './StoredShapes.tsx'; + +export default function ShapeEditor() { + const [lastMutationTime, setLastMutationTime] = useState<number>(null); + + return ( + <div className="flex flex-col gap-8 md:flex-row"> + <div className="flex-1"> + <NewShape setLastMutationTime={setLastMutationTime} /> + </div> + <div className="flex-1"> + <StoredShapes lastMutationTime={lastMutationTime} /> + </div> + </div> + ); +} diff --git a/src/pages/blobs/_components/ShapePreview.tsx b/src/pages/blobs/_components/ShapePreview.tsx new file mode 100644 index 0000000..a00d2bc --- /dev/null +++ b/src/pages/blobs/_components/ShapePreview.tsx @@ -0,0 +1,19 @@ +import { randomInt } from '../../../utils.ts'; +import type { BlobProps } from '../../../types.ts'; + +export default function ShapePreview(props: BlobProps) { + const { svgPath, parameters } = props; + const gradientId = `gradient-${randomInt(10_000_000, 100_000_000)}`; + + return ( + <svg viewBox={`0 0 ${parameters.size} ${parameters.size}`} xmlns="http://www.w3.org/2000/svg" width="100%"> + <defs> + <linearGradient id={gradientId} x1="0%" y1="0%" x2="0%" y2="100%"> + <stop offset="0%" style={{ stopColor: parameters.colors[0] }} /> + <stop offset="100%" style={{ stopColor: parameters.colors[1] }} /> + </linearGradient> + </defs> + <path d={svgPath} fill={`url(#${gradientId})`}></path> + </svg> + ); +} diff --git a/src/pages/blobs/_components/StoredShapes.tsx b/src/pages/blobs/_components/StoredShapes.tsx new file mode 100644 index 0000000..e870ef5 --- /dev/null +++ b/src/pages/blobs/_components/StoredShapes.tsx @@ -0,0 +1,78 @@ +import { useState, useEffect } from 'react'; +import ShapePreview from './ShapePreview.tsx'; +import { generateBlob } from '../../../utils'; +import type { BlobProps } from '../../../types.ts'; + +interface Props { + lastMutationTime: number; +} + +export default function StoredShapes(props: Props) { + const { lastMutationTime } = props; + const [keys, setKeys] = useState<string[]>([]); + const [selectedKey, setSelectedKey] = useState<string>(null); + const [previewData, setPreviewData] = useState<BlobProps>(null); + + const getBlobKeyList = async () => { + console.log('Fetching keys...'); + const response = await fetch('/api/blobs', { + method: 'GET', + headers: { 'Content-Type': 'application/json' } + }); + const data = await response.json(); + if (data.keys) { + setKeys(data.keys); + } + }; + + const getBlobByKey = async (key: string) => { + setSelectedKey(key); + const params = new URLSearchParams({ key }); + const response = await fetch(`/api/blob/?${params}`, { + method: 'GET' + }); + const data = await response.json(); + if (data.blob) { + setPreviewData(generateBlob(data.blob)); + } + }; + + useEffect(() => { + getBlobKeyList(); + }, [lastMutationTime]); + + return ( + <> + <h2 className="mb-4 text-xl text-center sm:text-xl">Objects in Blob Store</h2> + <div className="w-full bg-white rounded-lg"> + <div className="min-h-14 p-4 text-center"> + {keys?.length ? ( + <div className="space-y-1"> + {keys.map((keyName) => ( + <button + key={keyName} + className={ + 'btn btn-ghost btn-sm btn-block text-neutral-900 font-normal' + + (selectedKey === keyName ? ' bg-base-content/20 pointer-events-none' : '') + } + onClick={() => { + getBlobByKey(keyName); + }} + > + {keyName} + </button> + ))} + </div> + ) : ( + <span className="text-neutral-900">Please upload some shapes!</span> + )} + </div> + {previewData && ( + <div className="p-4 aspect-square text-primary border-t border-neutral-200"> + <ShapePreview {...previewData} /> + </div> + )} + </div> + </> + ); +} diff --git a/src/pages/blobs/index.astro b/src/pages/blobs/index.astro new file mode 100644 index 0000000..5630d6b --- /dev/null +++ b/src/pages/blobs/index.astro @@ -0,0 +1,18 @@ +--- +import Layout from '../../layouts/Layout.astro'; +import Markdown from '../../components/Markdown.astro'; +import ShapeEditor from './_components/ShapeEditor.tsx'; + +const explainer = ` +[Netlify Blobs](https://docs.netlify.com/blobs/overview/) provides an object store for any kind of data, be it JSON, binary, +or [really](https://mk.gg/projects/chalkstream) anything else ([really!](https://mk.gg/projects/turbofan)). In this example, the blob store is used to **hold the data of user-generated random blobby shapes**. + +Below is an Astro island with a React component for editing, uploading and viewing blobs to the blob store 🙂. +`; +--- + +<Layout title="Blobs"> + <h1 class="mb-8">Blobs x Blobs</h1> + <Markdown content={explainer} class="mb-12" /> + <ShapeEditor client:load /> +</Layout> diff --git a/src/pages/edge/index.astro b/src/pages/edge/index.astro index f49f3a9..8bf4a85 100644 --- a/src/pages/edge/index.astro +++ b/src/pages/edge/index.astro @@ -9,7 +9,7 @@ This page is using a [Netlify Edge Function](https://docs.netlify.com/edge-funct 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. +Edge Functions are framework-agnostic, but are also used behind the scenes to run Astro 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/image-cdn.astro b/src/pages/image-cdn.astro index 8847536..dbb8822 100644 --- a/src/pages/image-cdn.astro +++ b/src/pages/image-cdn.astro @@ -10,18 +10,25 @@ const sampleImage = '/images/corgi.jpg'; const ctx = getNetlifyContext(); const forceWebP = ctx === 'dev'; -const sampleImageNetlify = `/.netlify/images?url=${sampleImage}${forceWebP ? '&fm=webp' : ''}`; +const sampleImageSrcSet = [640, 1280, 2048] + .map((size) => { + return `/.netlify/images?url=${sampleImage}&w=${size}${forceWebP ? '&fm=webp' : ''} ${size}w`; + }) + .join(', '); +const sizes = '(max-width: 1024px) 100vw, 1024px'; const astroImageSnippet = ` -## Using built-in Astro <Image /> component +## Using the built-in Astro <Image /> component -When running on Netlify, \`next/image\` is automatically set-up to use Netlify Image CDN for optimized images. +Astro's \`Image\` component will automatically use Netlify Image CDN to serve optimized images. ~~~jsx -import Image from 'next/image'; - -// In your component -<Image src="/images/corgi.jpg" alt="Corgi" /* ... additional props */ /> +--- +import { Image } from 'astro:assets'; +import corgi from '../assets/corgi.jpg'; +--- +// Later in your markup... +<Image src={corgi} alt="Corgi" /* ... additional props */ /> ~~~ `; @@ -29,7 +36,7 @@ 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/). +Note that aside from Astro's \`Image\` or rolling your own \`<img>\` tags, you can also use the excellent [unpic-img](https://unpic.pics/) package. ~~~jsx // <== On the left, the original image @@ -37,8 +44,8 @@ Other than using \`next/image\` or rolling your own \`<img>\` tags, you can also // ==> On the right, explicitly using Netlify Image CDN endpoint for a responsive image <img - srcSet="/.netlify/images?url=images/corgi.jpg&w=640 640w, /.netlify/images?url=images/corgi.jpg&w=1280 1280w, /.netlify/images?url=images/corgi.jpg&w=2048 2048w" - sizes="(max-width: 1024px) 100vw, 1024px" + srcSet="${sampleImageSrcSet}" + sizes="${sizes}" alt="Corgi" /> ~~~ @@ -53,11 +60,11 @@ detection, so format is set to WebP. <Layout title="Image CDN"> <div class="flex flex-col gap-12 sm:gap-16"> <section class="space-y-8"> - <ContextAlert addedChecksFunction={ - (ctx) => { - return ctx === "dev" ? devModeWarning : null; - } - } /> + <ContextAlert + addedChecksFunction={(ctx) => { + return ctx === 'dev' ? devModeWarning : null; + }} + /> <h1>Image CDN</h1> </section> <section> @@ -77,7 +84,7 @@ detection, so format is set to WebP. <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={sampleImageNetlify} alt="Corgi" /> + <img srcset={sampleImageSrcSet} alt="Corgi" /> </div> </div> </div> diff --git a/src/pages/index.astro b/src/pages/index.astro index 8955471..6e73e14 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,13 +1,21 @@ --- import Layout from '../layouts/Layout.astro'; -import Card from '../components/Card.astro'; +import ContextAlert from '../components/ContextAlert.astro'; +import Markdown from '../components/Markdown.astro'; + +const explainer = ` +An Astro website can go way beyond static pages - on the right platform. + +Netlify supports not only [Streaming SSR](https://docs.astro.build/en/guides/server-side-rendering/) and fast [Edge Middleware](https://docs.astro.build/en/guides/middleware/), but also [on-demand revalidation](https://www.netlify.com/blog/cache-tags-and-purge-api-on-netlify/) and [stale-while-revalidate](https://www.netlify.com/blog/swr-and-fine-grained-cache-control/). +Any page or data can be rebuilt only when needed, without site visitors ever getting a performance hit. +`; --- <Layout title="Welcome to Astro."> - <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> + <ContextAlert class="mb-4" /> + <h1 class="mb-10">Netlify Platform Starter for Astro</h1> + <Markdown content={explainer} class="text-lg mb-10" /> <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/pages/revalidation.astro b/src/pages/revalidation.astro new file mode 100644 index 0000000..f7d4f6e --- /dev/null +++ b/src/pages/revalidation.astro @@ -0,0 +1,61 @@ +--- +import Layout from '../layouts/Layout.astro'; +import ContextAlert from '../components/ContextAlert.astro'; +import Markdown from '../components/Markdown.astro'; +import { cacheHeaders, randomInt } from '../utils'; + +export const prerender = false; + +const tags = ['/revalidation', 'cats-related', 'all-pets-related']; +const headers = cacheHeaders(365, tags); + +Object.entries(headers).map(([k, v]) => { + Astro.response.headers.set(k, v); +}); + +const explainer = ` +This is a server-rendered page, last created at \`${new Date().toUTCString()}\` with a few extra response headers: + +~~~js +${JSON.stringify(headers, null, 2)} +~~~ + +Meaning: **for browsers,** this is a non-cacheable page. At the **CDN level,** it *is* cacheable for up to a year (and Netlify also automatically busts the cache on new deployments, by default). + +But there's something more: the \`Cache-Tag\` header, in tandem with the [purge API](https://docs.netlify.com/platform/caching/#on-demand-invalidation), allows a developer to invalidate at will any +pieces of content (pages, JSON responses, or whatnot) based on the tags associated with them. Tags are completely up to you to decide on, and allow for very powerful patterns. + +In real-world applications, you may want to use [stale-while-revalidate](https://docs.netlify.com/platform/caching/#stale-while-revalidate-directive) as well, so that end-users don't experience +a performance hit as pages are being rebuilt. + +Use the button below to invlidate a random tag out of this page's tags, then refresh the page. +`; + +const exampleTag = tags[randomInt(0, tags.length - 1)]; +--- + +<Layout title="Revalidation"> + <h1 class="mb-10">Revalidating Server Content</h1> + <Markdown content={explainer} class="mb-10" /> + <button class="revalidate-button btn btn-primary" data-tag={exampleTag}>Invalidate tag: {exampleTag}</button> + <button class="btn btn-primary" onclick="location.reload()">Reload page</button> +</Layout> + +<script> + function revalidate(tag: string) { + fetch('/api/revalidate', { + method: 'POST', + body: JSON.stringify({ tags: [tag] }), + headers: { + 'Content-Type': 'application/json' + } + }); + alert(`Invalidated tag: ${tag}`); + } + + const revalidateButton = document.querySelectorAll('button.revalidate-button')[0]; + revalidateButton.addEventListener('click', (e) => { + const tag = (e.target as HTMLButtonElement).getAttribute('data-tag'); + revalidate(tag); + }); +</script> diff --git a/src/styles/globals.css b/src/styles/globals.css index dabf3e4..2573355 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -1,5 +1,3 @@ -@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap'); - @tailwind base; @tailwind components; @tailwind utilities; @@ -10,7 +8,7 @@ } h2 { - @apply text-2xl font-bold sm:text-3xl + @apply text-2xl font-bold sm:text-3xl; } a { @@ -22,10 +20,12 @@ } :not(pre) > code { - @apply px-1 py-0.5 font-mono rounded bg-neutral-900 text-yellow-200; + @apply px-1 py-0.5 font-mono rounded bg-[#1f1f1f] text-[#F67280]; font-size: 0.9em; } +} +@layer components { .markdown > h1, .markdown > h2 { @apply mt-12 mb-6; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..8c8daa8 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,13 @@ +export type BlobParameterProps = { + seed: number; + size: number; + edges: number; + growth: number; + name: string; + colors: string[]; +}; + +export type BlobProps = { + svgPath: string; + parameters: BlobParameterProps; +}; diff --git a/src/utils.js b/src/utils.js deleted file mode 100644 index d2cc47b..0000000 --- a/src/utils.js +++ /dev/null @@ -1,4 +0,0 @@ -// Note: this only works on the server side -export function getNetlifyContext() { - return process.env.CONTEXT; -}
\ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..7a32b7d --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,55 @@ +import blobshape from 'blobshape'; +import { uniqueNamesGenerator, adjectives, animals } from 'unique-names-generator'; + +// Note: this only works on the server side +export function getNetlifyContext() { + return process.env.CONTEXT; +} + +export function randomInt(min: number, max: number) { + return Math.floor(Math.random() * (max - min + 1) + min); +} + +export function uniqueName() { + const config = { + dictionaries: [adjectives, animals], + separator: '-', + length: 2 + }; + return uniqueNamesGenerator(config) + '-' + randomInt(100, 999); +} + +export function generateBlob(parameters?: any) { + const gradientColors = [ + ['#2E3192', '#1BFFFF'], + ['#93A5CF', '#E4EfE9'], + ['#BFF098', '#6FD6FF'], + ['#A1C4FD', '#C2E9FB'], + ['#11998E', '#38EF7D'], + ['#D8B5FF', '#1EAE98'] + ]; + + parameters = { + seed: null, + size: 512, + edges: randomInt(3, 20), + growth: randomInt(2, 9), + name: uniqueName(), + colors: gradientColors[randomInt(0, gradientColors.length - 1)], + ...parameters + }; + const { path: svgPath, seedValue: seed } = blobshape(parameters); + return { parameters: { ...parameters, seed }, svgPath }; +} + +export function cacheHeaders(maxAgeDays = 365, cacheTags?: string[]): Record<string, string> { + // As far as the browser is concerned, it must revalidate on every request. + // However, Netlify CDN is told to keep the content cached for up to maxAgeDays (note: new deployment bust the cache by default). + // We're also setting cache tags to be able to later purge via API (see: https://www.netlify.com/blog/cache-tags-and-purge-api-on-netlify/) + const headers = { + 'Cache-Control': 'public, max-age=0, must-revalidate', // Tell browsers to always revalidate + 'Netlify-CDN-Cache-Control': `public, max-age=${maxAgeDays * 86_400}, must-revalidate` // Tells Netlify CDN the max allwed cache duration + }; + if (cacheTags?.length > 0) headers['Cache-Tag'] = cacheTags.join(','); + return headers; +} diff --git a/tailwind.config.mjs b/tailwind.config.mjs index 87a222b..7f520ee 100644 --- a/tailwind.config.mjs +++ b/tailwind.config.mjs @@ -1,13 +1,17 @@ /** @type {import('tailwindcss').Config} */ const colors = require('tailwindcss/colors'); const defaultTheme = require('tailwindcss/defaultTheme'); +const fs = require('fs'); + +const noiseBitmap = fs.readFileSync('./public/images/noise.png', { encoding: 'base64' }); +const noiseDataUri = 'data:image/png;base64,' + noiseBitmap; export default { - content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], + content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], theme: { extend: { backgroundImage: { - 'grid-pattern': "linear-gradient(to bottom, theme('colors.neutral.950 / 0%'), theme('colors.neutral.950 / 100%')), url('/images/noise.png')" + 'grid-pattern': `linear-gradient(to bottom, theme('colors.neutral.950 / 0%'), theme('colors.neutral.950 / 100%')), url('${noiseDataUri}')` }, colors: { neutral: colors.neutral @@ -22,14 +26,14 @@ export default { { lofi: { ...require('daisyui/src/theming/themes')['lofi'], - primary: '#fbb13d', - 'primary-content': '#171717', - secondary: '#0f766e', - info: '#fbb13d', - 'info-content': '#171717', + primary: '#F67280', + 'primary-content': '#1f1f1f', + secondary: '#C06C84', + info: '#F67280', + 'info-content': '#1f1f1f' } } ] }, - plugins: [require('daisyui')], -} + plugins: [require('daisyui')] +}; diff --git a/tsconfig.json b/tsconfig.json index d78f81e..7fb90fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,7 @@ { - "extends": "astro/tsconfigs/base" -} + "extends": "astro/tsconfigs/base", + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "react" + } +}
\ No newline at end of file |
