You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
import("https://cdn.jsdelivr.net/npm/marked/marked.min.js");
|
|
function include(element, file) {
|
|
if (file) {
|
|
const xhttp = new XMLHttpRequest();
|
|
xhttp.onreadystatechange = function () {
|
|
if (this.readyState == 4) {
|
|
if (this.status == 200) {
|
|
if ('.md' == file.match(/\.md$/)) {
|
|
element.innerHTML = marked.parse(this.responseText);
|
|
} else {
|
|
element.innerHTML = this.responseText;
|
|
}
|
|
}
|
|
if (this.status == 404) {
|
|
element.innerHTML = "Page not found.";
|
|
}
|
|
}
|
|
}
|
|
xhttp.open("GET", file, true);
|
|
xhttp.send();
|
|
}
|
|
}
|
|
|
|
function parseIncludes()
|
|
{
|
|
const elements = document.querySelectorAll('div[include$=".html"]');
|
|
elements.forEach((element) => {
|
|
include(element, element.getAttribute('include'));
|
|
});
|
|
}
|
|
|
|
function page(file) {
|
|
include(document.getElementById('page'), file);
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
parseIncludes();
|
|
});
|