-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
31 lines (29 loc) · 844 Bytes
/
main.js
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
// const container = document.querySelector(".container");
// fetch("./asset/db.json")
// .then((res) => {
// return res.json();
// })
// .then((data) => {
// data.posts.sort((a, b) => b.createdAt - a.createdAt);
// data.posts.forEach((post) => {
// container.innerHTML += `
// <a class="post-div" href=${post.link} target="_blank">
// <img src=${post.url} loading="lazy" alt="project image" />
// </a>
// `;
// });
// });
const container = document.querySelector(".container");
db.collection("posts")
.orderBy("createdAt", "desc")
.onSnapshot((snap) => {
container.innerHTML = "";
snap.forEach((doc) => {
let post = doc.data();
container.innerHTML += `
<a class="post-div" href=${post.link} target="_blank">
<img src=${post.url} loading="lazy" alt="project image" />
</a>
`;
});
});