abtmtr-v4/views/blog/post/scripts/data_get_blog_post.js

25 lines
741 B
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";
const conv = new showdown.Converter({
simplifiedAutoLink: true,
simpleLineBreaks: true,
requireSpaceBeforeHeadingText: true,
encodeEmails: true,
excludeTrailingPunctuationFromURLs: true,
omitExtraWLInCodeBlocks: true,
});
fetch(
`https://${source}.abtmtr.link/api/collections/${blog}/posts/${urlParams.get(
"slug"
)}?body=html`
)
.then((x) => x.json())
.then(({ data }) => {
data_get.innerHTML = `<h1>${data.title}</h1>
<section>${conv.makeHtml(data.body.replace(/#\w+/gim, ""))}</section>`;
});