|
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:** Astro |
| 56 | +* **Extensions:** `.astro` |
| 57 | +* **Editor:** HTML / JSX-like |
| 58 | +* **Compiler:** Astro Compiler |
| 59 | +* **Version:** Latest (v4.x and above) |
| 60 | + |
| 61 | +⚠️ LiveCodes currently uses Astro v0.9.2, so some latest features may not be available. |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +## Code Formatting |
| 66 | + |
| 67 | +Astro uses **Prettier** by default with the official Astro plugin. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Custom Settings |
| 72 | + |
| 73 | +Custom settings can be passed in the `astro.config.mjs` file. |
| 74 | + |
| 75 | +**Example:** |
| 76 | + |
| 77 | +```js |
| 78 | +// astro.config.mjs |
| 79 | +export default { |
| 80 | + site: 'https://example.com', |
| 81 | + integrations: [], |
| 82 | + output: 'static', // or 'server' |
| 83 | +}; |
| 84 | +``` |
| 85 | + |
| 86 | +> Please ensure that all configuration values are valid JavaScript or JSON. |
| 87 | +
|
| 88 | +--- |
| 89 | + |
| 90 | +## Example Usage |
| 91 | + |
| 92 | +### Static Example |
| 93 | + |
| 94 | +```astro |
| 95 | +--- |
| 96 | +const message = "Hello from Astro!"; |
| 97 | +--- |
| 98 | +<p>{message}</p> |
| 99 | +``` |
| 100 | + |
| 101 | +### Dynamic Example |
| 102 | + |
| 103 | +```astro |
| 104 | +--- |
| 105 | +const res = await fetch('https://api.example.com/data'); |
| 106 | +const data = await res.json(); |
| 107 | +--- |
| 108 | +<p>{data.title}</p> |
| 109 | +``` |
| 110 | + |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## Official Resources |
| 115 | + |
| 116 | +* 🌐 [Astro Documentation](https://docs.astro.build) |
| 117 | +* 💻 [Astro GitHub Repository](https://github.com/withastro/astro) |
| 118 | +* 🧪 [Astro Playground](https://stackblitz.com/github/withastro/astro/tree/latest/examples/hello-world) |
| 119 | +* 📰 [Astro Blog](https://astro.build/blog) |
| 120 | +* 💬 [Astro Discord Community](https://astro.build/chat) |
| 121 | +* 🌐 [Astro Starter Template](https://livecodes.io/?template=astro) |
| 122 | + |
| 123 | + |
0 commit comments