2023-09-13 22:28:13 +00:00
|
|
|
{% extends "layout.html" %}
|
2023-09-19 09:05:38 +00:00
|
|
|
|
|
|
|
|
{% block title %}{{ this.title }}{% endblock %}
|
|
|
|
|
|
2023-09-13 22:28:13 +00:00
|
|
|
{% block bgstuff %}
|
|
|
|
|
background-color: black;
|
2023-09-19 09:05:38 +00:00
|
|
|
color:white;
|
2023-09-13 22:28:13 +00:00
|
|
|
{% endblock %}
|
2023-09-19 09:05:38 +00:00
|
|
|
|
2023-09-13 22:28:13 +00:00
|
|
|
{% block body %}
|
|
|
|
|
{{ this.body }}
|
2023-09-19 09:05:38 +00:00
|
|
|
|
|
|
|
|
<div id="wikipedia-data">
|
2024-11-30 23:21:11 +00:00
|
|
|
<h2>Y ahora, unas cuantas palabras de Wikipedia</h2>
|
2025-04-16 18:41:23 +00:00
|
|
|
<h3 id="article-title"></h3>
|
|
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-04-16 18:41:23 +00:00
|
|
|
const wikipediaAPI = 'https://en.wikipedia.org/w/api.php';
|
|
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
const pageTitles = ['List_of_hackers', 'Cybersecurity', 'Open-source_software', 'History_of_Linux'];
|
2025-04-16 18:41:23 +00:00
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
const pageTitle = pageTitles[Math.floor(Math.random() * pageTitles.length)];
|
2025-04-16 18:41:23 +00:00
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
const params = {
|
2025-04-16 18:41:23 +00:00
|
|
|
origin: '*', // Required for CORS from Wikipedia
|
2023-09-19 09:05:38 +00:00
|
|
|
action: 'query',
|
|
|
|
|
format: 'json',
|
|
|
|
|
titles: pageTitle,
|
|
|
|
|
prop: 'extracts|pageimages',
|
2025-04-16 18:41:23 +00:00
|
|
|
exintro: true,
|
|
|
|
|
explaintext: true,
|
2023-09-19 09:05:38 +00:00
|
|
|
piprop: 'original',
|
2025-04-16 18:41:23 +00:00
|
|
|
pithumbsize: 400,
|
2025-05-29 20:46:02 +00:00
|
|
|
ulssetlang: 'es',
|
2023-09-19 09:05:38 +00:00
|
|
|
};
|
2025-04-16 18:41:23 +00:00
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
const url = `${wikipediaAPI}?${new URLSearchParams(params)}`;
|
2025-04-16 18:41:23 +00:00
|
|
|
|
|
|
|
|
fetch(url)
|
2023-09-19 09:05:38 +00:00
|
|
|
.then((response) => response.json())
|
|
|
|
|
.then((data) => {
|
|
|
|
|
const pageId = Object.keys(data.query.pages)[0];
|
2025-04-16 18:41:23 +00:00
|
|
|
const page = data.query.pages[pageId];
|
|
|
|
|
|
|
|
|
|
const articleTitle = page.title;
|
|
|
|
|
const articleIntro = page.extract;
|
|
|
|
|
const articleImage = page.original ? page.original.source : '';
|
|
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
console.log('Article Title:', articleTitle);
|
|
|
|
|
console.log('Article Intro:', articleIntro);
|
|
|
|
|
console.log('Article Image:', articleImage);
|
2025-04-16 18:41:23 +00:00
|
|
|
|
2023-09-19 09:05:38 +00:00
|
|
|
document.getElementById('article-title').textContent = articleTitle;
|
|
|
|
|
document.getElementById('article-intro').textContent = articleIntro;
|
2025-04-16 18:41:23 +00:00
|
|
|
|
|
|
|
|
if (articleImage) {
|
|
|
|
|
document.getElementById('article-image').src = articleImage;
|
|
|
|
|
document.getElementById('article-image').style.display = 'block';
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('article-image').style.display = 'none';
|
|
|
|
|
}
|
2023-09-19 09:05:38 +00:00
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
});
|
2025-04-16 18:41:23 +00:00
|
|
|
</script>
|
|
|
|
|
|
2023-09-13 22:28:13 +00:00
|
|
|
{% endblock %}
|