-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.html
166 lines (146 loc) · 4.64 KB
/
posts.html
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lista de Posts</title>
<link rel="stylesheet" href="styles.css"> <!-- Enlace a tu archivo CSS -->
<style>
/* Estilos generales */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
color: #333;
}
.container {
width: 90%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
background-color: #4CAF50;
color: white;
padding: 15px 0;
text-align: center;
}
header h1 {
margin: 0;
}
nav ul {
list-style: none;
padding: 0;
display: flex;
justify-content: center;
margin: 10px 0 0;
}
nav ul li {
margin: 0 10px;
}
nav ul li a {
text-decoration: none;
color: white;
font-weight: bold;
padding: 5px 10px;
border-radius: 5px;
transition: background-color 0.3s;
}
nav ul li a:hover {
background-color: #45a049;
}
.posts-container {
display: flex;
flex-direction: column;
gap: 20px;
margin-top: 20px;
}
/* Estilo de las tarjetas */
.post-card {
background-color: white;
border: 1px solid #ddd;
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.post-card:hover {
transform: translateY(-5px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.post-card a {
text-decoration: none;
color: inherit;
}
.post-card h2 {
color: #333;
margin: 0 0 10px;
font-size: 24px;
}
.post-card p {
margin: 5px 0;
line-height: 1.6;
}
.post-card small {
display: block;
margin-top: 10px;
color: #666;
font-size: 14px;
}
</style>
</head>
<body>
<header>
<div class="container">
<h1>Lista de Posts</h1>
<nav>
<ul>
<li><a href="index.html" class="btn-nav">Últimos Comentarios</a></li>
<li><a href="autores.html" class="btn-nav">Lista de Autores</a></li>
<li><a href="posts.html" class="btn-nav">Posts</a></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<section id="posts" class="posts-container">
<!-- Los datos de los posts se cargarán dinámicamente aquí -->
</section>
</div>
<script>
// URL de la API para obtener todos los posts
const API_URL = 'http://localhost:3000/posts';
// Función para cargar los posts
async function cargarPosts() {
try {
const response = await fetch(API_URL);
const data = await response.json();
// Seleccionamos el contenedor de los posts
const container = document.getElementById('posts');
container.innerHTML = ''; // Limpiar contenido previo
// Agregar cada post como una tarjeta
data.forEach(post => {
const card = document.createElement('div');
card.classList.add('post-card');
card.innerHTML = `
<a href="post.html?id=${post.id_post}">
<div class="post-card-content">
<h2>${post.titulo}</h2>
<p><strong>Autor:</strong> ${post.nombre_autor}</p>
<p>${post.contenido.substring(0, 100)}...</p> <!-- Mostrar una vista previa del contenido -->
<small><em>Publicado el: ${post.fecha}</em></small>
</div>
</a>
`;
container.appendChild(card);
});
} catch (error) {
console.error('Error al cargar los posts:', error);
}
}
// Llamar a la función al cargar la página
window.onload = cargarPosts;
</script>
</body>
</html>