|
1 | 1 | # Astro |
2 | 2 |
|
3 | | -TODO... |
| 3 | +Astro is a modern static site builder focused on delivering fast, content-driven websites. It uses a “zero JavaScript by default” approach and supports multiple frameworks like React, Vue, and Svelte through an islands architecture. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +There are **two primary modes** for building and rendering Astro pages: |
| 8 | + |
| 9 | +### Static (Default) |
| 10 | + |
| 11 | +In this mode, pages are fully pre-rendered at build time. |
| 12 | +All data must be available during the build process and can be supplied through **frontmatter**, **data fetching functions**, or **integrations**. |
| 13 | + |
| 14 | +**Example:** Provide data to a page using frontmatter. |
| 15 | + |
| 16 | +```astro |
| 17 | +--- |
| 18 | +const name = "LiveCodes"; |
| 19 | +--- |
| 20 | +<h1>Hello {name}!</h1> |
| 21 | +``` |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +### Dynamic |
| 26 | + |
| 27 | +To enable runtime rendering, configure the page as a server-rendered route or use an Astro server adapter (e.g., Node, Deno, or Vercel). |
| 28 | + |
| 29 | +In this mode, values can be provided dynamically during request handling. |
| 30 | + |
| 31 | +**Example:** Create a server-side API endpoint: |
| 32 | + |
| 33 | +```js |
| 34 | +export async function GET() { |
| 35 | + return new Response(JSON.stringify({ name: 'LiveCodes' }), { |
| 36 | + headers: { 'Content-Type': 'application/json' }, |
| 37 | + }); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +Then fetch and render it dynamically in Astro: |
| 42 | + |
| 43 | +```astro |
| 44 | +--- |
| 45 | +const res = await fetch('https://jsonplaceholder.typicode.com/users/1'); |
| 46 | +const data = await res.json(); |
| 47 | +--- |
| 48 | +<h1>Hello {data.name}!</h1> |
| 49 | +``` |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Language Info |
| 54 | + |
| 55 | +### Name |
| 56 | + |
| 57 | +`astro` |
| 58 | + |
| 59 | +### Extension |
| 60 | + |
| 61 | +`astro` |
| 62 | + |
| 63 | +## Editor |
| 64 | + |
| 65 | +`markup` |
| 66 | + |
| 67 | +## Compiler |
| 68 | + |
| 69 | +Astro compiler |
| 70 | + |
| 71 | +### Version |
| 72 | + |
| 73 | +`@astrojs/compiler`: `v2.2.8` |
| 74 | + |
| 75 | +## Code Formatting |
| 76 | + |
| 77 | +Using [Prettier](https://prettier.io/). |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Example Usage |
| 82 | + |
| 83 | +### Static Example |
| 84 | + |
| 85 | +```astro |
| 86 | +--- |
| 87 | +const message = "Hello from Astro!"; |
| 88 | +--- |
| 89 | +<p>{message}</p> |
| 90 | +``` |
| 91 | + |
| 92 | +### Dynamic Example |
| 93 | + |
| 94 | +```astro |
| 95 | +--- |
| 96 | +const res = await fetch('https://api.example.com/data'); |
| 97 | +const data = await res.json(); |
| 98 | +--- |
| 99 | +<p>{data.title}</p> |
| 100 | +``` |
| 101 | + |
| 102 | +## Links |
| 103 | + |
| 104 | +- [Astro Documentation](https://docs.astro.build) |
| 105 | +- [Astro Starter Template](https://livecodes.io/?template=astro) |
| 106 | + |
| 107 | + |
0 commit comments