forked from hack4impact-calpoly/bootcamp-project-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.ts
65 lines (51 loc) · 1.61 KB
/
blog.ts
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
type Blog = {
title: string;
date: string;
description: string;
image: string; //(ex. “./images/me.png”)
imageAlt: string;
slug: string; //a slug is a URL name used to redirect to a specific page
};
const blogs: Blog[] = [
{
title: "Blog #1",
date: "10/27/2024",
description: "First blog ever!",
image: "minionselfie.png",
imageAlt: "Minion taking selfie.",
slug: "./blog/blog1.html",
},
{
title: "Blog #2",
date: "10/28/2024",
description: "Second blog ever!",
image: "minionselfie.png",
imageAlt: "Minion taking selfie.",
slug: "./blog/blog2.html",
},
];
const blogContainer = document.getElementById("blog-container");
blogs.forEach((blog) => {
const blogDiv = document.createElement("div");
blogDiv.className = "blog-post";
const blogTitle = document.createElement("h1");
blogTitle.textContent = blog.title;
blogDiv.appendChild(blogTitle);
const blogDate = document.createElement("p");
blogDate.textContent = blog.date;
blogDiv.appendChild(blogDate);
const blogDescription = document.createElement("p");
blogDescription.textContent = blog.description;
blogDiv.appendChild(blogDescription);
const blogImage = document.createElement("img");
blogImage.src = blog.image;
blogImage.alt = "Image for ${blog.title}";
blogImage.width = 350;
blogImage.height = 300;
blogDiv.appendChild(blogImage);
const blogSlug = document.createElement("a");
blogSlug.href = blog.slug;
blogSlug.textContent = "Read more";
blogDiv.appendChild(blogSlug);
blogContainer && blogContainer.appendChild(blogDiv); //if it is not null, run
});