scripts/pirate_program/templates/index.html

179 lines
4.2 KiB
HTML
Raw Permalink Normal View History

2024-06-10 15:42:10 +02:00
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Programme du Parti Pirate</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
width: 45rem;
max-width: 1200px;
background-color: #fff;
padding: 8rem;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
font-size: 1.25rem;
}
h1 {
font-size: 24px;
margin-bottom: 10px;
}
.article {
margin-bottom: 40px;
}
.article h2 {
font-size: 18px;
margin-bottom: 10px;
}
.article .tags {
margin-bottom: 10px;
}
.article .tags a {
color: #333;
text-decoration: none;
}
.article .date {
font-size: 12px;
color: #999;
margin-bottom: 10px;
}
.article .content {
font-size: 16px;
line-height: 1.6;
color: #333;
}
.article .content p {
margin-bottom: 20px;
}
.article .content ul {
margin-left: 20px;
}
a {
color: darkslateblue;
}
2024-06-11 09:50:09 +02:00
/* Nouveaux styles pour le nuage de tags */
.tag-cloud {
width: 300px;
height: 300px;
2024-06-10 15:42:10 +02:00
position: fixed;
top: 20px;
2024-06-11 09:50:09 +02:00
right: 20px;
2024-06-10 15:42:10 +02:00
}
</style>
</head>
<body id="main">
<div class="middle w-5/6 max-w-screen-xl mt-16 ml-auto mr-auto project-container">
<div class="container">
<h1>Programme du
<a href="https://partipirate.org/index.php/">Parti Pirate</a>
</h1>
2024-06-11 09:50:09 +02:00
<section class="nuage">
<h2>nuage de mots:</h2>
<div class="word-cloud"></div>
</section>
2024-06-10 15:42:10 +02:00
{% for page in pages %}
<div class="article">
<h2>
<a href="{{ page.url}}">
{{ page.title }}
</a>
</h2>
<div class="tags">
<strong>Tags :</strong> {{ page.tags }}
</div>
<div class="date">{{ page.date }}</div>
<div class="image"><img src="{{ page.image }}" alt="image d'article"></div>
<div class="content">{{ page.content|safe }}</div>
<hr>
</div>
{% endfor %}
</div>
</div>
2024-06-11 09:50:09 +02:00
<script src="https://d3js.org/d3.v7.min.js"></script>
2024-06-10 15:42:10 +02:00
<script>
2024-06-11 09:50:09 +02:00
// Fonction pour créer le nuage de mots
function createWordCloud(texts) {
// Extraire les mots de plus de 4 lettres
var words = [];
texts.forEach(function(text) {
var matches = text.match(/\b\w{5,}\b/g);
if (matches) {
words = words.concat(matches);
}
});
// Calculer la fréquence de chaque mot
var wordFrequency = {};
words.forEach(function(word) {
if (wordFrequency[word]) {
wordFrequency[word]++;
} else {
wordFrequency[word] = 1;
}
});
// Trier les mots par fréquence décroissante
var sortedWords = Object.keys(wordFrequency).sort(function(a, b) {
return wordFrequency[b] - wordFrequency[a];
});
// Créer le nuage de mots avec d3.js
var wordCloud = d3.select(".word-cloud")
.append("svg")
.attr("width", 600)
.attr("height", 600);
// Définir une échelle de couleur allant du blanc au violet
var colorScale = d3.scaleSequential(d3.interpolateViridis)
.domain([0, d3.max(Object.values(wordFrequency))]);
// Ajouter les mots au nuage
var maxFrequency = d3.max(Object.values(wordFrequency));
wordCloud.selectAll("text")
.data(sortedWords.splice(0,20))
.enter()
.append("text")
.text(function(d) { return d; })
.attr("x", function(d, i) { return 10 + (i % 10) * 50; })
.attr("y", function(d, i) { return 10 + Math.floor(i / 10) * 20; })
.attr("font-size", function(d) { return Math.sqrt(wordFrequency[d] / maxFrequency) * 20 + "px"; })
.style("fill", function(d) { return colorScale(wordFrequency[d]); })
.style("cursor", "pointer");
}
// Récupérer les textes des articles
var texts = Array.from(document.querySelectorAll(".article .content")).map(function(div) {
return div.textContent;
});
// Appeler la fonction pour créer le nuage de mots
createWordCloud(texts);
2024-06-10 15:42:10 +02:00
</script>
</body>
</html>