{"id":13572866,"url":"https://github.com/netlify-templates/astro-toolbox","last_synced_at":"2025-05-13T17:58:38.263Z","repository":{"id":43206031,"uuid":"504725225","full_name":"netlify-templates/astro-toolbox","owner":"netlify-templates","description":"Netlify ❤️ Astro: a simple template to give you the code you need to use Netlify features with Astro.","archived":false,"fork":false,"pushed_at":"2024-05-27T08:20:02.000Z","size":1726,"stargazers_count":87,"open_issues_count":6,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-28T22:05:18.704Z","etag":null,"topics":["astro","forms","netlify","redirects","serverless-functions","template"],"latest_commit_sha":null,"homepage":"https://astro-toolbox.netlify.app","language":"Astro","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netlify-templates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-18T02:36:50.000Z","updated_at":"2024-06-03T05:52:09.574Z","dependencies_parsed_at":"2023-11-20T04:29:02.787Z","dependency_job_id":"dfc5b5e3-962b-4b1c-a993-ddb6b9629e18","html_url":"https://github.com/netlify-templates/astro-toolbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":"netlify-templates/astro-quickstart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify-templates%2Fastro-toolbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify-templates%2Fastro-toolbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify-templates%2Fastro-toolbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify-templates%2Fastro-toolbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netlify-templates","download_url":"https://codeload.github.com/netlify-templates/astro-toolbox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253999823,"owners_count":21997336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["astro","forms","netlify","redirects","serverless-functions","template"],"created_at":"2024-08-01T15:00:22.620Z","updated_at":"2025-05-13T17:58:38.232Z","avatar_url":"https://github.com/netlify-templates.png","language":"Astro","readme":"# Astro Toolbox Template  \n\n![Netlify + Astro](https://user-images.githubusercontent.com/43764894/223557634-f62606c5-bdf9-476c-9264-0d3728189962.png)\n\nThis is an [Astro](https://astro.build) project bootstrapped from the Astro CLI. It is a reference on how to integrate commonly used features within [Netlify](https://netlify.com) for Astro. \n\n[![Deploy to Netlify Button](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify-templates/astro-toolbox?utm_campaign=template-team\u0026utm_source=dtn-button\u0026utm_medium=dtn-button\u0026utm_term=astro-tt-dtn-button\u0026utm_content=astro-tt-dtn-button)\n\nClick this button and it will help you create a new repo, create a new Netlify project, and deploy!\n\nHere's a video for more info: https://youtu.be/GrSLYq6ZTes\n\u0026 a blog post too: https://ntl.fyi/3IrbbN7.\n\n## Table of Contents:\n\n- [Getting Started](#getting-started)\n  - [Running locally with the Netlify CLI](#running-locally-with-the-netlify-cli)\n- [Deploy to Netlify](#deploy-to-netlify)\n  - [Deploying using the Netlify CLI](#deploying-using-the-netlify-cli)\n- [Forms](#forms)\n  - [Adding a Custom Submission Page](#adding-a-custom-submission-page)\n  - [Blocking Bot Spam with a Honeypot Field](#blocking-bot-spam-with-a-honeypot-field)\n  - [Forms Resources](#forms-resources)\n- [Netlify Functions](#netlify-functions)\n  - [Netlify Functions Resources](#netlify-functions-resources)\n- [Redirects](#redirects)\n  - [Redirect Resources](#redirect-resources)\n- [Astro + Netlify Resources](#astro--netlify-resources)\n- [Project Structure](#project-structure)\n- [Commands](#commands)\n- [Testing](#testing)\n  - [Included Default Testing](#included-default-testing)\n  - [Removing Renovate](#removing-renovate)\n  - [Removing Cypress](#removing-cypress)\n\n## Getting Started\n\nIf you want to get started locally, you can clone the project, install the dependencies and run the dev command!\n\n```\ngit clone https://github.com/netlify-templates/astro-toolbox/\ncd astro-toolbox\nnpm install\nnpm run dev\n```\n\nYou can then open up \u003chttp://localhost:3000\u003e with your browser to see the result! Open up `pages/index.astro` and modify the code to see the changes auto update as you save.\n\n\u003e 🧠 Just a heads up, you will not be able to see the function data or redirect output until you run locally with `netlify dev` (info below in [Netlify CLI section](#running-locally-with-the-netlify-cli))\n\n### Running locally with the Netlify CLI\n\nWhen using this template, you might want to see Netlify features such as redirects, functions, or preview the deploy locally first. To do, this you can install and use the Netlify CLI!\n\n```\nnpm install -g netlify-cli # to install the Netlify CLI tool globally\nnetlify dev\n```\n\nAnd now your project should be running on \u003chttp://localhost:8888\u003e.\n\n## Deploy to Netlify\n### Deploying using the Netlify CLI\n\n #### 1. Cloning + Install Packages\n\n  - Clone this repo with one of these options:\n\n    - Click the 'Use this template' button at the top of the page\n    - Or via the command line `git clone https://github.com/netlify-templates/astro-toolbox`\n\n  - Then install the necessary packages and run the project locally to make sure everything works.\n\n    ```bash\n    npm install\n    npm run dev\n    ```\n\n  \u003e Alternatively, you can run this locally with [the Netlify CLI](https://docs.netlify.com/cli/get-started/)'s by running the `netlify dev` command for more options like receiving a live preview to share (`netlify dev --live`) and the ability to test [Netlify Functions](https://www.netlify.com/products/functions) and [redirects](https://docs.netlify.com/routing/redirects/). \n\n  #### 2. Deploying\n  - Install the Netlify CLI globally `npm install netlify-cli -g`\n    \n  - Run `npm run build`\n\n  - Then use the `netlify deploy` for a deploy preview link or `netlify deploy --prod` to deploy to production\n\n  Here are a few other ways you can deploy this template:\n    \n  - Use the Netlify CLI's create from template command `netlify sites:create-template astro-toolbox` which will create a repo, Netlify project, and deploy it\n    \n  - If you want to utilize continuous deployment through GitHub webhooks, run the Netlify command `netlify init` to create a new project based on your repo or `netlify link` to connect your repo to an existing project\n\n## Forms\n\nNetlify Forms are a way to wire up your native HTML into being able to seamlessly handle submissions. To get a form working, we need to add two extra things:\n\n1. An extra attribute on the `form` tag, `netlify`\n\nAdding this attribute to our `form` tag will let Netlify know when it loads the page, that it needs to be aware of submissions made through it.\n\n2. A hidden input in the form, `\u003cinput type=\"hidden\" name=\"form-name\" value=\"feedback\" /\u003e`\n\nAdding this extra input allows our form to be given a name that Netlify can store submissions to. It is a hidden input so your users won't see it but it will pass along the name of our form to Netlify when we submit. In our Netlify Admins site under Forms, we will see our Active Form named `feedback` and all submissions will go there.\n\nWith both of those we're ready for folks to give us feedback!\n\n### Adding a custom submission page\n\nWhile Netlify provides a default submission page for folks, we can customize it as well! With the `action` attribute on the `form` tag we will be able to direct our users to our own page.\n\nIn [`components/FeedbackForm.js`](https://github.com/netlify-templates/astro-toolbox/blob/main/src/components/FeedbackForm.astro) you'll see the form has the attribute `action=\"/success\"` this will take our user to the custom route `/success` which we created under [`pages/success.js`](https://github.com/netlify-templates/astro-toolbox/blob/main/src/pages/success.astro). As long as the page exists, you can direct folks to it!\n\n### Blocking bot spam with a honeypot field\n\nMany bots scan through webpages and try to see what pages and forms they can get access to. Instead of letting our website receive spam submissions, we can filter out unrelated submissions with a visually-hidden input field.\n\n```html\n\u003cp class=\"hidden\"\u003e\n  \u003clabel\u003e\n    Don’t fill this out if you’re human: \u003cinput name=\"bot-field\" /\u003e\n  \u003c/label\u003e\n\u003c/p\u003e\n```\n\nSince screenreader users will still have this announced, it is important for us to\ncommunicate that this is a field not meant to be filled in.\n\nFor this to work we also need to add a `netlify-honeypot` attribute to the form element.\n\n```html\n\u003cform netlify data-netlify-honeypot=\"bot-field\" name=\"feedback method=\"POST\" action=\"/success\"\u003e\u003c/form\u003e\n```\n\n[See it here in the template code.](https://github.com/netlify-templates/next-toolbox/blob/main/components/FeedbackForm.js#L8)\n\n### Forms Resources\n\n- [Netlify Forms Setup](https://docs.netlify.com/forms/setup/)\n- [Netlify Forms](https://www.netlify.com/products/forms/#main)\n- [Netlify Forms - Form Triggered Functions](https://docs.netlify.com/functions/trigger-on-events/)\n- [Netlify Forms - Using reCAPTCHA 2](https://docs.netlify.com/forms/spam-filters/#recaptcha-2-challenge)\n\n## Netlify Functions\n\nWith Netlify, you can build out server-side code without having to setup and maintain a dedicated server. Inside of our default folder path, [`netlify/functions`](./netlify/functions) you can see an example of the format for JavaScript functions with the [`joke.js`](./netlify/functions/joke.js) file.\n\nThe function format expects an `async` function named `handler` to be exported.*\n\n```js\nexport const handler = async () =\u003e {\n  // Your code goes in here!\n}\n```\n\n* *Note: ESLint may report that the async is unnecessary if there is no `await` code within the function, but the `async` is required. Do not delete it.*\n\nThis will be the function that will be invoked whenever a client makes a request to the generated endpoints. The endpoint's format is followed as `/.netlify/functions/joke`. So whenever the site is deployed, if you go to `https://\u003csite base url\u003e/.netlify/functions/joke` you will see a random joke!\n\n\u003e Side note: In our example, we're using `import` to include data from another location and `export const const handler` to let our function be consumed by Netlify. We're able to do this because of [esbuild](https://esbuild.github.io). This is a bundler configuration we set in our `netlify.toml` under `[functions]`.\n\n### Netlify Functions Resources\n\nThere is quite a bit you can do with these functions, so here are some additional resources to learn more!\n\n- [Netlify Function Format](https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format)\n- [Build Netlify Functions with TypeScript](https://docs.netlify.com/functions/build-with-typescript/)\n- [Event-triggered Functions](https://docs.netlify.com/functions/trigger-on-events/)\n- [What are Background Functions](https://www.netlify.com/blog/2021/01/07/what-are-background-functions/)\n- [Netlify Functions - Examples](https://functions.netlify.com/examples/)\n- [Using esbuild as your bundler for new ECMAScript Features](https://www.netlify.com/blog/2021/04/02/modern-faster-netlify-functions/)\n\n## Redirects\n\nIn the [`netlify.toml`](./netlify.toml) configuration file there is an example of how to implement redirects. Redirects can be used to do many things from redirecting Single Page Apps more predictably, redirecting based on country/language to leveraging On-Demand Builders for [Distributed Persistant Rendering](https://www.netlify.com/blog/2021/04/14/distributed-persistent-rendering-a-new-jamstack-approach-for-faster-builds/). \n\nIn the example we'll be using redirects to have a shorter endpoint to Netlify functions. By default, you call a Netlify function when requesting a path like `https://yoursite.netlify.com/.netlify/functions/functionName`. Instead, we'll redirect all calls from a path including `/api` to call on the Netlify functions. So the path will be `https://yoursite.netlify.com/api/functionName`, a lot easier to remember too. \n\n\n### Example\n```toml\n[[redirects]]\nfrom = \"/api/*\"\nto = \"/.netlify/functions/:splat\"\nstatus = 200\nforce = true\n```\n\nFirst, we create a section in the `.toml` for the redirect using `[[redirects]]`. Each redirect should have this line to start the redirect code, and the redirects will be executed in the order they appear in the `.toml` from top to bottom.\n\nThe bare minimum needed is the `from` and `to`, letting the [CDN](https://www.netlify.com/blog/edge-cdn-serverless-cloud-meaaning) know when a route is requested, the `from`, forward it on to another path, the `to`. In the example, we also added an 'Ok' status code, 200, and set the `force` to true to make sure it _always_ redirects from the `from` path.\n\nThere are many ways to use redirects. Check out the resouces below to learn more.\n\n### Redirect Resources\n\n- [Redirect syntax and configuration](https://docs.netlify.com/routing/redirects/#syntax-for-the-netlify-configuration-file)\n- [Redirect options](https://docs.netlify.com/routing/redirects/redirect-options/)\n- [Creating better, more predicatable redirect rules for SPAs](https://www.netlify.com/blog/2020/04/07/creating-better-more-predictable-redirect-rules-for-spas/)\n- [Redirect by country or language](https://docs.netlify.com/routing/redirects/redirect-options/#redirect-by-country-or-language)\n- [On-Demand Builders](https://docs.netlify.com/configure-builds/on-demand-builders/)\n\n## Astro + Netlify Resources\n\nHere are some resources to help you on your Astro + Netlify coding fun!\n\n- [Astro on Netlify Integration Page](https://docs.netlify.com/integrations/frameworks/astro)\n\n- [Build wicked fast sites with Astro: An Introduction](https://www.netlify.com/blog/2021/07/08/build-wicked-fast-sites-with-astro-an-introduction/#main)\n\n- [A Template for Building Shopify Stores with Astro and the Storefront API](https://www.netlify.com/blog/2021/07/23/build-a-modern-shopping-site-with-astro-and-serverless-functions)\n\nHope this template helps :) Happy coding 👩🏻‍💻!\n\n---\n\n## Project Structure\n\nInside of your Astro project, you'll see the following folders and files:\n\n```\n/\n├── public/\n│   └── favicon.ico\n├── src/\n│   ├── components/\n│   │   └── Layout.astro\n│   └── pages/\n│       └── index.astro\n└── package.json\n```\n\nAstro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.\n\nThere's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components or layouts.\n\nAny static assets, like images, can be placed in the `public/` directory.\n\n## Commands\n\nAll commands are run from the root of the project, from a terminal:\n\n| Command           | Action                                       |\n| :---------------- | :------------------------------------------- |\n| `npm install`     | Installs dependencies                        |\n| `npm run dev`     | Starts local dev server at `localhost:3000`  |\n| `npm run build`   | Build your production site to `./dist/`      |\n| `npm run preview` | Preview your build locally, before deploying |\n\n\n## Testing\n\n### Included Default Testing\n\nWe’ve included some tooling that helps us maintain these templates. This template currently uses:\n\n- [Renovate](https://www.mend.io/free-developer-tools/renovate/) - to regularly update our dependencies\n- [Cypress](https://www.cypress.io/) - to run tests against how the template runs in the browser\n- [Cypress Netlify Build Plugin](https://github.com/cypress-io/netlify-plugin-cypress) - to run our tests during our build process\n\nIf your team is not interested in this tooling, you can remove them with ease!\n\n### Removing Renovate\n\nIn order to keep our project up-to-date with dependencies we use a tool called [Renovate](https://github.com/marketplace/renovate). If you’re not interested in this tooling, delete the `renovate.json` file and commit that onto your main branch.\n\n### Removing Cypress\n\nFor our testing, we use [Cypress](https://www.cypress.io/) for end-to-end testing. This makes sure that we can validate that our templates are rendering and displaying as we’d expect. By default, we have Cypress not generate deploy links if our tests don’t pass. If you’d like to keep Cypress and still generate the deploy links, go into your `netlify.toml` and delete the plugin configuration lines:\n\n```diff\n[[plugins]]\n  package = \"netlify-plugin-cypress\"\n-  [plugins.inputs.postBuild]\n-    enable = true\n-\n-  [plugins.inputs]\n-    enable = false \n```\n\nIf you’d like to remove the `netlify-plugin-cypress` build plugin entirely, you’d need to delete the entire block above instead. And then make sure sure to remove the package from the dependencies using:\n\n```bash\nnpm uninstall -D netlify-plugin-cypress\n```\n\nAnd lastly if you’d like to remove Cypress entirely, delete the entire `cypress` folder and the `cypress.config.ts` file. Then remove the dependency using:\n\n```bash\nnpm uninstall cypress\n```\n","funding_links":[],"categories":["Astro"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlify-templates%2Fastro-toolbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetlify-templates%2Fastro-toolbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlify-templates%2Fastro-toolbox/lists"}