abtmtr-v4/views/blog/scripts/data_get_blog.js

35 lines
1 KiB
JavaScript
Raw Normal View History

2023-11-26 19:14:50 +00:00
const data_get = document.getElementById("data_get");
const urlParams = new URLSearchParams(window.location.search);
const source = urlParams.get("src") || "blog";
const blog = urlParams.get("blog") || "mtr";
fetch(
`https://${source}.abtmtr.link/api/collections/${blog}/posts?body=html&page=${
urlParams.get("page") || 1
}`
)
.then((x) => x.json())
.then(({ data }) => {
data_get.innerHTML = `<style>${data.style_sheet}</style>
${data.posts
.map(
(post) => `
<h1><a href="/blog/post/?blog=${data.alias}&slug=${
post.slug
}&src=${source}" target="_blank">${post.title}</a></h1>
<p>
<button
onclick="window.manager.createWindow('/blog/post/?blog=${
data.alias
}&slug=${post.slug}&src=${source}', false)"
>
Open in Window
</button>
</p>
<p>Posted ${new Date(post.created).toLocaleDateString()}</p>
${source == "img" ? `<p><img src="${post.images[0]}" /></p>` : ""}`
)
.join("")}
`;
});