/* كود التصحيح النهائي لضمان عرض المقالات */
(function() {
function initApp() {
var BLOG = window.location.protocol + '//' + window.location.hostname;
var path = window.location.pathname;
var area = document.getElementById('js-posts-area');
if (!area) return;
// تحديد نوع الصفحة بدقة أكبر
var isPost = path.length > 5 && (path.indexOf('.html') !== -1 || path.split('/').length > 2);
var feedUrl = '';
if (isPost) {
// جلب المقال الفردي باستخدام نظام البحث بالرابط لضمان التوافق
feedUrl = BLOG + '/feeds/posts/default?alt=json&q=' + encodeURIComponent(path);
} else if (path.indexOf('/search/label/') !== -1) {
var label = decodeURIComponent(path.split('/search/label/')[1].split('/')[0].split('?')[0]);
feedUrl = BLOG + '/feeds/posts/default/-/' + encodeURIComponent(label) + '?alt=json&max-results=12';
} else {
feedUrl = BLOG + '/feeds/posts/default?alt=json&max-results=10&orderby=published';
}
area.innerHTML = 'جاري تحميل المحتوى...
';
fetch(feedUrl)
.then(function(res) { return res.json(); })
.then(function(data) {
var entries = (data.feed && data.feed.entry) || [];
var html = '';
if (entries.length === 0) {
html = 'لا يوجد مقالات حالياً. تأكد من تفعيل (خلاصة الموقع) من إعدادات بلوجر.
';
} else if (isPost) {
// عرض المقالة الفردية
html = fullHTML(entries[0]);
} else {
// عرض قائمة المقالات
html = '';
entries.forEach(function(e) { html += cardHTML(e); });
html += '
';
html += pagerHTML(data.feed);
}
renderArea(area, html);
})
.catch(function() {
area.innerHTML = 'حدث خطأ في الاتصال بالخادم.
';
});
}
// التأكد من تشغيل الكود بعد تحميل المتصفح لكل العناصر
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initApp);
} else {
initApp();
}
})();