-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblogPosts.js
More file actions
53 lines (44 loc) · 1.64 KB
/
blogPosts.js
File metadata and controls
53 lines (44 loc) · 1.64 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
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
import sourceMap from "./posts/sourceMap.js";
customElements.define(
"blog-posts",
class extends HTMLElement {
connectedCallback() {
const container = document.createElement("div");
container.classList.add("row", "g-4"); // Use Bootstrap's grid gap utility
const posts = sourceMap();
posts.forEach(([title, date, preview, htmlFilePath]) => {
const col = document.createElement("div");
col.classList.add(
"col-12",
"col-sm-6",
"col-md-4",
"col-lg-3",
"d-flex" // Use flexbox for equal height
);
const card = document.createElement("div");
card.classList.add("post", "card", "w-100");
card.addEventListener("click", () => {
window.location.href = htmlFilePath;
});
const cardBody = document.createElement("div");
cardBody.classList.add("card-body", "d-flex", "flex-column");
const titleEl = document.createElement("h2");
titleEl.textContent = title;
titleEl.classList.add("card-title", "post-title");
cardBody.appendChild(titleEl);
const dateEl = document.createElement("p");
dateEl.textContent = date;
dateEl.classList.add("card-text", "date");
cardBody.appendChild(dateEl);
const previewEl = document.createElement("p");
previewEl.textContent = preview;
previewEl.classList.add("card-text", "preview", "flex-grow-1");
cardBody.appendChild(previewEl);
card.appendChild(cardBody);
col.appendChild(card);
container.appendChild(col);
});
this.appendChild(container);
}
}
);