kernel_panic_web/kernelpanic.lol/templates/temple.html
2025-06-05 17:56:49 -06:00

71 lines
2.0 KiB
HTML

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