-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (35 loc) · 1.15 KB
/
Copy pathscript.js
File metadata and controls
39 lines (35 loc) · 1.15 KB
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
document.addEventListener("DOMContentLoaded", () => {
const links = document.querySelectorAll('#post-list a');
links.forEach(link => {
link.addEventListener('click', e => {
e.preventDefault();
const filename = link.getAttribute('data-post');
if (filename) {
loadPost(filename);
}
});
});
const urlParams = new URLSearchParams(window.location.search);
const postFromURL = urlParams.get('post');
if (postFromURL) {
loadPost(postFromURL);
}
// Función para manejar el clic en el botón de "Crear entrada"
const createPostButton = document.getElementById('create-post');
if (createPostButton) {
createPostButton.addEventListener('click', () => {
// Acción para el botón de crear entrada
window.location.href = "crear_entrada.html"; // Redirige a una página de creación de entradas
});
}
});
function loadPost(filename) {
fetch('posts/' + filename)
.then(res => res.ok ? res.text() : null)
.then(md => {
if (md) {
const html = marked.parse(md);
document.getElementById('content').innerHTML = html;
}
});
}