-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html_BAK
175 lines (170 loc) · 6.34 KB
/
index.html_BAK
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>volteret4</title>
<style>
/* Estilos para el header y la barra lateral */
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #181a1c;
padding: 10px;
}
header h1 {
font-size: 1.5em;
font-weight: bold;
color: white;
}
aside {
position: fixed;
top: 0;
left: 0;
width: 200px;
height: 100%;
background-color: #181a1c;
padding-top: 60px;
overflow-y: auto;
margin-right: 20px;
}
a:visited {
color: lightgray;
}
.index {
font-size: 16px;
margin-left: 20px;
}
.index .folder {
cursor: pointer;
}
.index ul {
display: none;
margin-left: 1px;
}
/* Estilos para reducir el margen izquierdo de cada elemento dentro del índice de cada mes */
.index ul li {
margin-left: 1px;
}
.index .folder.opened ul {
display: block;
}
/* Estilos para el contenedor de los últimos posts y elementos individuales */
#latest-posts {
display: flex;
flex-wrap: wrap;
margin-top: 80px; /* ajusta el valor según la altura de la barra superior vacía */
margin-left: 220px; /* Ancho de la barra lateral más margen derecho */
justify-content: space-between;
}
.post-container {
width: calc(33.333% - 10px); /* Restar 10px para tener en cuenta el margen */
margin-bottom: 10px;
}
.post-container img {
width: 100%;
height: auto;
}
/* Estilos para el fondo, color de letra y fuente */
body {
background-color: #181a1c;
color: white;
font-family: Monospace, sans-serif;
}
/* Estilos para subrayar texto */
em {
text-decoration: underline;
}
</style>
</head>
<body>
<header>
<h1>volteret4</h1>
</header>
<aside>
<h2><a href="index.html">volteret4</a></h2>
<div class="index" id="post-index"></div>
</aside>
<div id="latest-posts"></div>
<script>
// Función para agrupar los posts por mes y año
function groupByMonth(posts) {
const groupedPosts = {};
posts.forEach((post) => {
const dateParts = post.fecha.split('-');
const monthYear = `${dateParts[1]}-${dateParts[2]}`;
if (!groupedPosts[monthYear]) {
groupedPosts[monthYear] = [];
}
groupedPosts[monthYear].push(post);
});
return groupedPosts;
}
// Función para crear el índice de posts en la barra lateral
function createPostIndex(posts) {
const index = document.getElementById('post-index');
const groupedPosts = groupByMonth(posts);
Object.entries(groupedPosts).forEach(([monthYear, monthPosts]) => {
const folder = document.createElement('div');
folder.classList.add('folder');
// Obtener el nombre del mes a partir del número de mes
const dateParts = monthYear.split('-');
const monthName = new Date(dateParts[1], dateParts[0] - 1).toLocaleString('es', { month: 'long' });
folder.textContent = `${monthName} ${dateParts[0]}`;
index.appendChild(folder);
const nestedUl = document.createElement('ul');
monthPosts.forEach((post, index) => {
const nestedLi = document.createElement('li');
const nestedA = document.createElement('a');
nestedA.href = `post.html?postIndex=${index}`;
nestedA.textContent = post.title;
nestedLi.appendChild(nestedA);
nestedUl.appendChild(nestedLi);
});
folder.appendChild(nestedUl);
// Agregar un controlador de eventos click para hacer que los elementos de la barra lateral sean interactivos
folder.addEventListener('click', () => {
folder.classList.toggle('opened');
});
});
}
// Función para mostrar los últimos 9 posts y enlazar a las páginas dinámicas
function displayLatestPosts() {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const posts = JSON.parse(xhr.responseText);
// Llamar a la función createPostIndex() aquí
createPostIndex(posts);
const numberOfPostsToShow = 30;
const latestPosts = posts.slice(-numberOfPostsToShow);
const latestPostsContainer = document.getElementById('latest-posts');
latestPostsContainer.style.display = 'flex';
latestPostsContainer.style.flexWrap = 'wrap';
latestPosts.forEach((post, i) => {
const postContainer = document.createElement('div');
postContainer.classList.add('post-container');
postContainer.innerHTML = `
<img src="${post.image}" alt="${post.title}">
<h2>${post.title}</h2>
`;
latestPostsContainer.appendChild(postContainer);
postContainer.addEventListener('click', function() {
window.location.href = `post.html?postIndex=${posts.length - numberOfPostsToShow + i}`;
});
});
}
};
xhr.open('GET', 'posts.json', true);
xhr.send();
}
// Obtener el índice del post de la URL
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const postIndex = urlParams.get('postIndex');
displayLatestPosts();
</script>
</body>
</html>