Blot

Show posts from Substack on the start page?

I have a Substack newsletter and would like to try and show recent entries in some sort of widget on my start page. Is there an easy way to this? I would like it to follow the style of my current template, so an embedded widget probably does not work.

Asked a year ago Edit
2 replies

This looks like a good guide and the live demo looks decent and is customizable.

Are you able to follow the steps in the guide? You'll add the JS to your template's script.js file, the CSS to your template's style.css file and then copy and paste the HTML into your start page.

a year ago Edit

The instructions in the guide need a few tweaks. Here is the full and final steps to add a Substack embed to your site:

First, add the following wherever you want the list of substack posts to appear, either in your template or in a post or page in your folder:

<div id="substack-feed-embed"></div> 

Add the following to your template's script.js, making sure to set substackUrl to your Substack:

const options = {
    substackUrl: "example.substack.com",
    posts: 3,
    showImages: true,
    showDates: true,
};

!function(){let t=window.SubstackFeedWidget||{},e={...options},s=document.querySelectorAll(".substack-feed-embed, #substack-feed-embed");if(!s.length)return;let a=t=>{try{return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"2-digit"}).format(new Date(t))}catch{return""}},r=t=>t?/^https?:\/\//i.test(t)?t:`https://${t}`:"",l=t=>{if(!t)return null;let e=t.match(/<img[^>]+src="([^"]+)"/i);return e?e[1]:null},n=(t,e=150)=>t&&t.length>e?`${t.slice(0,e)}…`:t||"",i=(t,e)=>{let s=document.createElement("a");s.className="substack-card",s.target="_blank",s.rel="noopener",s.href=t.link;let r=document.createElement("div");if(r.className="substack-post",e.showImages){let i=l(t.content);if(i){let c=document.createElement("img");c.className="substack-thumbnail",c.loading="lazy",c.sizes="568px",c.alt=t.title||"Substack post image",c.src=i,r.appendChild(c)}}let o=document.createElement("div"),u=document.createElement("h3");if(u.className="substack-title",u.textContent=t.title||"Untitled",o.appendChild(u),e.showDates&&t.pubDate){let d=document.createElement("p");d.className="substack-date",d.textContent=a(t.pubDate),o.appendChild(d)}let p=document.createElement("p");return p.className="substack-desc",p.textContent=n(t.description,160),o.appendChild(p),r.appendChild(o),s.appendChild(r),s},c=(t,e=1e4)=>{let s=new AbortController,a=setTimeout(()=>s.abort(),e);return fetch(t,{signal:s.signal}).finally(()=>clearTimeout(a))};s.forEach(async t=>{let s={substackUrl:t.getAttribute("data-substack-url")||e.substackUrl,posts:parseInt(t.getAttribute("data-posts"),10)||e.posts,showImages:"false"!==(t.getAttribute("data-show-images")||`${e.showImages}`),showDates:"false"!==(t.getAttribute("data-show-dates")||`${e.showDates}`)};if(!s.substackUrl){t.innerHTML='<p class="substack-error">Error: No Substack URL specified.</p>';return}let a=r(s.substackUrl),l=`https://api.rss2json.com/v1/api.json?rss_url=${encodeURIComponent(`${a}/feed`)}`;t.innerHTML='<div class="substack-skeleton">Loading…</div>';try{let n=await c(l,12e3);if(!n.ok)throw Error(`HTTP ${n.status}`);let o=await n.json();if("ok"!==o.status||!Array.isArray(o.items))throw Error(o.message||"Failed to parse feed");let u=o.items.slice(0,Math.max(1,s.posts));if(!u.length){t.innerHTML='<p class="substack-empty">No posts available.</p>';return}t.innerHTML="",u.forEach(e=>{t.appendChild(i(e,s))})}catch(d){console.error("Substack feed error:",d),t.innerHTML='<p class="substack-error">Could not load posts. Please try again later.</p>'}})}();

Add the following to your template's style.css:

 .substack-card {
     text-decoration: none
}
 .substack-date {
    
}
 .substack-card p {
    margin-bottom:0
}
 .substack-feed-embed {
     display: grid;
     gap: 20px;
}
 .substack-post {
     display: flex;
     gap: 24px;
     align-items: flex-start;
     margin-bottom: 20px;
     padding: 18px;
     border: 1px solid #eee;
     border-radius: 8px;
}
 .substack-title {
    margin-top:0;
}
 .substack-thumbnail {
     width: 120px;
     height: 120px;
     object-fit: cover;
     border-radius: 8px;
     flex-shrink: 0;
}
 .substack-post div {
     flex: 1;
}

Please let me know if I can help with this

a year ago Edit

Your reply