-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.astro
140 lines (132 loc) · 3.11 KB
/
index.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
import Layout from "../layouts/Layout.astro";
import Card from "../components/Card.astro";
// To use Deno KV, swiitch this import to "resources_kv" in the same directory
import { addResource, listResources, Resource } from "../data/resources";
// Process form submission if required
if (Astro.request.method === "POST") {
try {
const data = await Astro.request.formData();
const resource: Resource = {
url: data.get("url")?.toString() || "",
title: data.get("title")?.toString() || "",
summary: data.get("summary")?.toString() || "",
};
await addResource(resource);
} catch (error) {
console.error(error);
}
// Redirect to home page to avoid duplicate form submissions
return Astro.redirect('/');
}
// Get a list of resources
const resources: Resource[] = await listResources();
---
<Layout title="Welcome to Deno 🦕">
<main>
<h1>Welcome to <span class="text-gradient">Deno 🦕</span></h1>
<div class="news-form">
<p>
Welcome to Deno! Add your own links and resources using the form below.
</p>
<hr/>
<form method="POST">
<label for="url">URL</label>
<input type="url" name="url" id="url" required/>
<br/>
<label for="title">Title</label>
<input type="text" name="title" id="title" required/>
<br/>
<label for="summary">Summary</label>
<input type="text" name="summary" id="summary" required/>
<br/>
<button type="submit">Submit</button>
</form>
</div>
<ul role="list" class="link-card-grid">
{resources.map((resource) => (
<Card
href={resource.url}
title={resource.title}
body={resource.summary}
/>
))}
</ul>
</main>
</Layout>
<style>
main {
margin: auto;
padding: 1.5rem;
max-width: 60ch;
}
h1 {
font-size: 3rem;
font-weight: 800;
margin: 0;
}
hr, p {
margin: 5px 0;
}
label {
font-size: 0.875rem;
font-style: italic;
}
input {
width: 100%;
padding: 5px;
margin: 0 0 5px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
cursor: pointer;
margin: 10px 0 0 0;
padding: 10px;
font-weight: bold;
color: #fff;
background-image: var(--accent-gradient);
background-size: 400%;
background-position: 0%;
border: none;
border-radius: 4px;
}
button:hover {
background-position: 10%;
}
.text-gradient {
background-image: var(--accent-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 400%;
background-position: 0%;
}
.news-form {
line-height: 1.6;
margin: 1rem 0;
border: 1px solid rgba(var(--accent), 25%);
background-color: white;
padding: 1rem;
border-radius: 0.4rem;
}
.news-form code {
font-size: 0.875em;
font-weight: bold;
background: rgba(var(--accent), 12%);
color: rgb(var(--accent));
border-radius: 4px;
padding: 0.3em 0.45em;
}
.news-form strong {
color: rgb(var(--accent));
}
.link-card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
gap: 1rem;
padding: 0;
margin: 0;
}
</style>