Skip to content

Commit 8022516

Browse files
committed
docs: add Astro language documentation
1 parent 7344c78 commit 8022516

2 files changed

Lines changed: 151 additions & 49 deletions

File tree

docs/docs/languages/astro.mdx

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,118 @@
1-
# Astro
1+
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.
2+
3+
## Usage
4+
5+
There are **two primary modes** for building and rendering Astro pages:
6+
7+
### Static (Default)
8+
9+
In this mode, pages are fully pre-rendered at build time.
10+
All data must be available during the build process and can be supplied through **frontmatter**, **data fetching functions**, or **integrations**.
11+
12+
**Example:** Provide data to a page using frontmatter.
13+
14+
```astro
15+
---
16+
const name = "LiveCodes";
17+
---
18+
<h1>Hello {name}!</h1>
19+
````
20+
21+
---
22+
23+
### Dynamic
24+
25+
To enable runtime rendering, configure the page as a server-rendered route or use an Astro server adapter (e.g., Node, Deno, or Vercel).
26+
27+
In this mode, values can be provided dynamically during request handling.
28+
29+
**Example:** Create a server-side API endpoint:
30+
31+
```js
32+
// src/pages/api/hello.js
33+
export async function get() {
34+
return new Response(JSON.stringify({ name: 'LiveCodes' }), {
35+
headers: { 'Content-Type': 'application/json' },
36+
});
37+
}
38+
```
39+
40+
Then fetch and render it dynamically in Astro:
41+
42+
```astro
43+
---
44+
const res = await fetch('/api/hello');
45+
const data = await res.json();
46+
---
47+
<h1>Hello {data.name}!</h1>
48+
```
49+
50+
---
51+
52+
## Language Info
53+
54+
* **Name:** Astro
55+
* **Extensions:** `.astro`
56+
* **Editor:** HTML / JSX-like
57+
* **Compiler:** Astro Compiler
58+
* **Version:** Latest (v4.x and above)
59+
60+
---
61+
62+
## Code Formatting
63+
64+
Astro uses **Prettier** by default with the official Astro plugin.
65+
66+
---
67+
68+
## Custom Settings
69+
70+
Custom settings can be passed in the `astro.config.mjs` file.
71+
72+
**Example:**
73+
74+
```js
75+
// astro.config.mjs
76+
export default {
77+
site: 'https://example.com',
78+
integrations: [],
79+
output: 'static', // or 'server'
80+
};
81+
```
82+
83+
> Please ensure that all configuration values are valid JavaScript or JSON.
84+
85+
---
86+
87+
## Example Usage
88+
89+
### Static Example
90+
91+
```astro
92+
---
93+
const message = "Hello from Astro!";
94+
---
95+
<p>{message}</p>
96+
```
97+
98+
### Dynamic Example
99+
100+
```astro
101+
---
102+
const res = await fetch('https://api.example.com/data');
103+
const data = await res.json();
104+
---
105+
<p>{data.title}</p>
106+
```
107+
108+
---
109+
110+
## Official Resources
111+
112+
* 🌐 [Astro Documentation](https://docs.astro.build)
113+
* 💻 [Astro GitHub Repository](https://github.com/withastro/astro)
114+
* 🧪 [Astro Playground](https://stackblitz.com/github/withastro/astro/tree/latest/examples/hello-world)
115+
* 📰 [Astro Blog](https://astro.build/blog)
116+
* 💬 [Astro Discord Community](https://astro.build/chat)
117+
2118

3-
TODO...

functions/vendors/templates.js

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ int main() {
693693
694694
return 0;
695695
}
696-
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var j={name:"cpp-wasm",aliases:["clang"],title:"C++ (Wasm) Starter",thumbnail:"assets/templates/cpp.svg",activeEditor:"script",markup:{language:"html",content:`
696+
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var j={name:"cpp-wasm",aliases:["clang"],title:getTemplateName("templates.starter.cpp-wasm","C++ (Wasm) Starter"),thumbnail:"assets/templates/cpp.svg",activeEditor:"script",markup:{language:"html",content:`
697697
<div class="container">
698698
<h1>Hello, <span id="name">World</span>!</h1>
699699
<img class="logo" alt="logo" src="{{ __livecodes_baseUrl__ }}assets/templates/cpp.svg" />
@@ -1194,11 +1194,11 @@ func greet() {
11941194
fmt.Println("Good evening")
11951195
}
11961196
}
1197-
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var N={name:"go-wasm",title:"Go (Wasm) Starter",thumbnail:"assets/templates/go.svg",activeEditor:"script",markup:{language:"html",content:`
1197+
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var N={name:"go-wasm",title:getTemplateName("templates.starter.go-wasm","Go (Wasm) Starter"),thumbnail:"assets/templates/go.svg",activeEditor:"script",markup:{language:"html",content:`
11981198
<div class="container">
1199-
<h1>Go WebAssembly Demo</h1>
1199+
<h1>Go (Wasm)</h1>
12001200
<img class="logo" alt="Go logo" src="{{ __livecodes_baseUrl__ }}assets/templates/go.svg" />
1201-
1201+
12021202
<div class="demo-section">
12031203
<h2>Interactive Counter</h2>
12041204
<p>Current count: <span id="counter">0</span></p>
@@ -1224,37 +1224,32 @@ func greet() {
12241224
const incrementBtn = document.querySelector("#increment-btn");
12251225
const greetBtn = document.querySelector("#greet-btn");
12261226
1227-
// Enable buttons and update text
12281227
incrementBtn.disabled = false;
12291228
incrementBtn.textContent = "Increment";
12301229
greetBtn.disabled = false;
12311230
greetBtn.textContent = "Greet";
12321231
1233-
// Counter demo
12341232
incrementBtn.onclick = async () => {
1235-
const currentCount = parseInt(document.querySelector("#counter").textContent);
1236-
1237-
const {output, error} = await livecodes.goWasm.run(currentCount.toString());
1233+
const currentCount = document.querySelector("#counter").textContent;
1234+
const {output, error} = await livecodes.goWasm.run(currentCount);
12381235
if (error) {
12391236
console.error('Error:', error);
12401237
} else {
1241-
document.querySelector("#counter").textContent = output.trim();
1238+
document.querySelector("#counter").textContent = output;
12421239
}
12431240
};
12441241
1245-
// Greeting demo
12461242
greetBtn.onclick = async () => {
12471243
const name = document.querySelector("#name-input").value;
1248-
if (!name) {
1244+
if (!name.trim()) {
12491245
alert('Please enter your name');
12501246
return;
12511247
}
1252-
12531248
const {output, error} = await livecodes.goWasm.run(name);
12541249
if (error) {
12551250
console.error('Error:', error);
12561251
} else {
1257-
document.querySelector("#greeting").textContent = output.trim();
1252+
document.querySelector("#greeting").textContent = output;
12581253
}
12591254
};
12601255
@@ -1331,38 +1326,30 @@ input[type="text"], input[type="number"] {
13311326
package main
13321327
13331328
import (
1334-
"bufio"
1335-
"fmt"
1336-
"os"
1337-
"strconv"
1338-
"strings"
1329+
"bufio"
1330+
"fmt"
1331+
"os"
1332+
"strconv"
1333+
"strings"
13391334
)
13401335
13411336
func main() {
1342-
// Read input from stdin
1343-
scanner := bufio.NewScanner(os.Stdin)
1344-
1345-
if scanner.Scan() {
1346-
input := strings.TrimSpace(scanner.Text())
1347-
1348-
// Try to parse as number (for counter demo)
1349-
if count, err := strconv.Atoi(input); err == nil {
1350-
// Counter demo - increment and return the new number
1351-
newCount := count + 1
1352-
fmt.Println(newCount)
1353-
return
1354-
}
1355-
1356-
1357-
1358-
// Greeting demo - treat as name
1359-
fmt.Printf("Hello, %s! Welcome to Go WebAssembly!\\n", input)
1360-
fmt.Println("This is running in your browser using Go compiled to WebAssembly.")
1361-
} else {
1362-
// No input provided
1363-
fmt.Println("Hello from Go WebAssembly!")
1364-
fmt.Println("This program demonstrates stdin handling in Go WASM.")
1365-
}
1337+
// Read input from stdin
1338+
scanner := bufio.NewScanner(os.Stdin)
1339+
1340+
if scanner.Scan() {
1341+
input := strings.TrimSpace(scanner.Text())
1342+
1343+
if count, err := strconv.Atoi(input); err == nil {
1344+
newCount := count + 1
1345+
fmt.Println(newCount)
1346+
return
1347+
}
1348+
1349+
fmt.Printf("Hello, %s!\\n", input)
1350+
} else {
1351+
fmt.Println("Hello from Go WebAssembly!")
1352+
}
13661353
}
13671354
`.trimStart()}};var H={name:"imba",title:getTemplateName("templates.starter.imba","Imba Starter"),thumbnail:"assets/templates/imba.svg",activeEditor:"script",markup:{language:"html",content:""},style:{language:"css",content:""},script:{language:"imba",content:`
13681355
tag app-counter
@@ -1484,7 +1471,7 @@ button.addEventListener("click", () => {
14841471
count++;
14851472
counter.innerText = count;
14861473
});
1487-
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var A={name:"jest-react",title:getTemplateName("templates.starter.jest-react","Jest/React Starter"),thumbnail:"assets/templates/jest.svg",activeEditor:"script",autotest:!0,markup:{language:"html",content:""},style:{language:"css",content:`
1474+
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var O={name:"jest-react",title:getTemplateName("templates.starter.jest-react","Jest/React Starter"),thumbnail:"assets/templates/jest.svg",activeEditor:"script",autotest:!0,markup:{language:"html",content:""},style:{language:"css",content:`
14881475
.container,
14891476
.container button {
14901477
text-align: center;
@@ -1656,7 +1643,7 @@ describe("Page", () => {
16561643
);
16571644
});
16581645
});
1659-
`.trimStart()},tools:{enabled:"all",active:"tests",status:"open"}};var O={name:"jquery",title:getTemplateName("templates.starter.jquery","jQuery Starter"),thumbnail:"assets/templates/jquery.svg",activeEditor:"script",markup:{language:"html",content:`
1646+
`.trimStart()},tools:{enabled:"all",active:"tests",status:"open"}};var Y={name:"jquery",title:getTemplateName("templates.starter.jquery","jQuery Starter"),thumbnail:"assets/templates/jquery.svg",activeEditor:"script",markup:{language:"html",content:`
16601647
<div class="container">
16611648
<h1>Hello, <span id="title">World</span>!</h1>
16621649
<img class="logo" alt="logo" src="{{ __livecodes_baseUrl__ }}assets/templates/jquery.svg" />
@@ -1682,7 +1669,7 @@ $("#counter-button").click(() => {
16821669
count += 1;
16831670
$("#counter").text(count);
16841671
});
1685-
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var Y={name:"julia",title:getTemplateName("templates.starter.julia","Julia Starter"),thumbnail:"assets/templates/julia.svg",activeEditor:"script",markup:{language:"html",content:`
1672+
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var A={name:"julia",title:getTemplateName("templates.starter.julia","Julia Starter"),thumbnail:"assets/templates/julia.svg",activeEditor:"script",markup:{language:"html",content:`
16861673
<div class="container">
16871674
<h1>Hello, <span id="name">World</span>!</h1>
16881675
<img class="logo" alt="logo" src="{{ __livecodes_baseUrl__ }}assets/templates/julia.svg" />
@@ -3966,4 +3953,4 @@ new Vue({
39663953
(i32.add (local.get $0) (i32.const 1))
39673954
)
39683955
)
3969-
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var uo=[b,I,Tt,mt,pt,Ct,d,rt,St,yt,G,wt,K,kt,vt,U,v,g,gt,J,O,h,z,D,A,C,et,Ut,S,V,y,x,H,ut,dt,Q,it,lt,ct,ht,bt,R,N,st,ot,_,j,W,T,tt,X,F,jt,q,Y,ft,k,w,P,_t,Z,u,Et,xt,nt,at,f,E];export{uo as starterTemplates};
3956+
`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var uo=[b,I,Tt,mt,pt,Ct,d,rt,St,yt,G,wt,K,kt,vt,U,v,g,gt,J,Y,h,z,D,O,C,et,Ut,S,V,y,x,H,ut,dt,Q,it,lt,ct,ht,bt,R,N,st,ot,_,j,W,T,tt,X,F,jt,q,A,ft,k,w,P,_t,Z,u,Et,xt,nt,at,f,E];export{uo as starterTemplates};

0 commit comments

Comments
 (0)