-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 1.08 KB
/
Copy pathscript.js
File metadata and controls
28 lines (24 loc) · 1.08 KB
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
document.addEventListener("DOMContentLoaded", async function() {
const container = document.getElementById("poem-container");
try { const response = await fetch("https://poetrydb.org/random/5/title,author,lines");
const poems = await response.json();
poems.forEach(poem => {
const preview = poem.lines.slice(0, 6).join(' ');
const card = `
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">${poem.title}</h5>
<h6 class="card-subtitle mb-2 text-muted">${poem.author}</h6>
<p class="card-text">${preview}...</p>
<a href="details.html?title=${encodeURIComponent(poem.title)}&author=${encodeURIComponent(poem.author)}&lines=${encodeURIComponent(poem.lines.join('|'))}" class="btn btn-primary">Read More..</a>
</div>
</div>
</div>
`;
container.innerHTML += card;
});
} catch (error) {
console.error("try again failed to get poems:", error);
}
});