Below is a drop-in replacement for the JavaScript block in the template you already installed.
It adds a “Read more / Read less” toggle that shows the first ±300 words right on your site and keeps the “Read Full Article” button at the end of the summary so the visitor never has to leave unless they choose to.
Copy everything between the two comments and paste it over the existing <script> block in your Blogger HTML editor, then save.
<!-- NEW JAVASCRIPT -->
<script>
/*<![CDATA[*/
document.addEventListener('DOMContentLoaded', function () {
/* ======== CONFIGURATION ======== */
const feedUrls = [
'https://racerxonline.com/category/news/feed',
'https://www.vitalmx.com/community/main.rss',
'http://www.motoonline.com.au/feed/',
'https://motocross.transworld.net/feed/',
'https://www.cyclenews.com/category/off-road/feed/'
];
const placeholderImage = 'https://i.ibb.co/6yC1N1Y/motocross-placeholder.jpg';
const WORD_LIMIT = 300; // how many words to show in the summary
/* ======== END CONFIG ======== */
const newsFeedContainer = document.getElementById('news-feed');
const loader = newsFeedContainer.querySelector('.loader');
/* ---------- helpers ---------- */
function stripHtml(str) {
const tmp = document.createElement('div');
tmp.innerHTML = str;
return tmp.textContent || tmp.innerText || '';
}
function truncateWords(text, limit) {
const words = text.trim().split(/\s+/);
if (words.length <= limit) return text;
return words.slice(0, limit).join(' ') + '…';
}
function formatDate(date) {
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
}
function getDomainName(url) {
try {
return new URL(url).hostname.replace('www.', '');
} catch {
return 'Unknown';
}
}
function extractImage(item, description) {
const media = item.querySelector('media\\:content, content');
if (media && media.getAttribute('url')) return media.getAttribute('url');
const enc = item.querySelector('enclosure');
if (enc && enc.getAttribute('type')?.startsWith('image/')) return enc.getAttribute('url');
const descDoc = new DOMParser().parseFromString(description, 'text/html');
const img = descDoc.querySelector('img');
if (img && img.src) return img.src;
return placeholderImage;
}
/* ---------- fetch one feed ---------- */
async function fetchFeed(url) {
const proxy = 'https://api.allorigins.win/raw?url=';
try {
const res = await fetch(proxy + encodeURIComponent(url));
if (!res.ok) throw new Error(res.status);
const text = await res.text();
const xml = new DOMParser().parseFromString(text, 'application/xml');
const items = xml.querySelectorAll('item');
return Array.from(items).map(it => ({
title: it.querySelector('title')?.textContent || 'No Title',
link: it.querySelector('link')?.textContent || '#',
pubDate: new Date(it.querySelector('pubDate')?.textContent || Date.now()),
description: stripHtml(it.querySelector('description')?.textContent || ''),
source: getDomainName(it.querySelector('link')?.textContent || url),
image: extractImage(it, it.querySelector('description')?.textContent || '')
}));
} catch (e) {
console.warn('Feed failed:', url, e);
return [];
}
}
/* ---------- render ---------- */
async function loadAllFeeds() {
const all = await Promise.all(feedUrls.map(fetchFeed));
const articles = [].concat(...all)
.sort((a, b) => b.pubDate - a.pubDate);
newsFeedContainer.innerHTML = '';
if (!articles.length) {
newsFeedContainer.innerHTML = '<p>Could not load any news feeds.</p>';
return;
}
articles.forEach(art => {
const id = 'summary-' + Math.random().toString(36).substr(2, 9);
const short = truncateWords(art.description, WORD_LIMIT);
const long = art.description;
const card = document.createElement('div');
card.className = 'news-item';
card.innerHTML = `
<div class="news-item-image-container">
<a href="${art.link}" target="_blank" rel="noopener">
<img src="${art.image}" alt="${art.title}" class="news-item-image"
onerror="this.onerror=null;this.src='${placeholderImage}';"/>
</a>
</div>
<div class="news-item-content">
<h2 class="news-item-title">
<a href="${art.link}" target="_blank" rel="noopener">${art.title}</a>
</h2>
<p class="news-item-meta">
By <strong>${art.source}</strong> on ${formatDate(art.pubDate)}
</p>
<div id="${id}-short" class="summary-short">${short}</div>
<div id="${id}-long" class="summary-long" style="display:none">${long}</div>
<button class="toggle-summary" data-id="${id}" data-state="short"
style="background:none;border:none;color:#ff6600;cursor:pointer;font-weight:bold;margin:10px 0;">
Read more
</button>
<a href="${art.link}" target="_blank" rel="noopener" class="read-more-link">Read Full Article</a>
</div>
`;
newsFeedContainer.appendChild(card);
});
/* toggle logic */
newsFeedContainer.addEventListener('click', e => {
if (!e.target.classList.contains('toggle-summary')) return;
const btn = e.target;
const id = btn.dataset.id;
const shortEl = document.getElementById(id + '-short');
const longEl = document.getElementById(id + '-long');
if (btn.dataset.state === 'short') {
shortEl.style.display = 'none';
longEl.style.display = 'block';
btn.textContent = 'Read less';
btn.dataset.state = 'long';
} else {
shortEl.style.display = 'block';
longEl.style.display = 'none';
btn.textContent = 'Read more';
btn.dataset.state = 'short';
}
});
}
loadAllFeeds();
});
/*]]>*/
</script>
<!-- END NEW JAVASCRIPT -->
Nothing else in the template needs to change.
After you save, every headline will now expand to show the first 300 words on your own domain, and the “Read Full Article” button still links to the original source.