Understanding post frequency and content velocity is key to maintaining a consistent engineering log. On dervic.blog, we don't just write; we measure. By combining PHP's array manipulation with Chart.js, we can generate real-time activity heatmaps. ⌨️
PHP: Aggregating Monthly Data 🏗️
First, we iterate through our flat-file directory and count how many posts belong to each month. We then format this data into a JSON array that JavaScript can understand. 🧪
<?php
$files = glob("content/*.md");
$counts = array_fill(1, 12, 0); // Jan to Dec
foreach ($files as $file) {
$content = file_get_contents($file);
preg_match('/date:\s*(\d{4})-(\d{2})/', $content, $matches);
if (isset($matches[2])) {
$month = (int)$matches[2];
$counts[$month]++;
}
}
// Prepare data for Chart.js
$chartData = array_values($counts); 📈
?>
Rendering the Visualization 📡
Using the Chart.js library, we inject our PHP array into the frontend logic to render a high-performance bar chart. 🛠️
const ctx = document.getElementById('postChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
datasets: [{
label: 'Posts Published',
data: <?php echo json_encode($chartData); ?>,
backgroundColor: '#000',
borderColor: '#000',
borderWidth: 1
}]
},
options: {
scales: { y: { beginAtZero: true } }
}
});
Summary 🏁
Turning raw metadata into visual intelligence transforms a simple blog into a Technical Dashboard.
This integration demonstrates how a flat-file system can still provide powerful analytical capabilities without the need for a traditional database. 🚀
If you liked this post, please LIKE or COMMENT below! 💬✨
Comments (0)