I found a Hubl function that works with Hubspot blog posts but I'm not sure if it works with RSS feeds or how to make it work with them if it does:
blog_recent_posts()
Is there any solution where I can use an external RSS feed inside a custom module for a drag-and-drop email template? I just want to place these values in my code in specific places: blog title, blog url, blog featured image url.
External RSS feed within a Custom Module for a drag-and-drop email template?
Hi Jenny,
It's getting at the same idea but it doesn't really solve the problem. Apparently Hubspot doesn't offer a way to import an external RSS feed to use with the Hubspot RSS email functionality (title as subject, etc) in a custom drag-and-drop template.
I've given up on trying to make this work and I'm moving on to a different solution. Namely, migrating the external blog into Hubspot. However, in order to display blog posts from Hubspot on the client's website (where the blog currently is) I'm still going to have to build a custom integration on that site. I'm considering whether it will be easier to use the HS blog RSS or the HS API (List blog posts).
I find it frustrating that Hubspot doesn't offer a simple solution for displaying a list of their blog posts on a different website/platform. It makes sense to me that Hubspot would benefit from offering such a solution because it would enable their clients to easily drive more trafic to the Hubspot platform and thus have a higher potential for conversion.
External RSS feed within a Custom Module for a drag-and-drop email template?
In case anyone comes later and wants to load their Hubspot blogs on a different website I've used this article as a starting place to build a manual RSS parser (with jQuery):
jQuery(document).ready(function() {
if( jQuery('.home-blog').hasClass('enable-hubspot-blog') ) { // just making sure this code is only running on the correct page
var months = {
'01' : 'Jan',
'02' : 'Feb',
'03' : 'Mar',
'04' : 'Apr',
'05' : 'May',
'06' : 'Jun',
'07' : 'Jul',
'08' : 'Aug',
'09' : 'Sep',
'10' : 'Oct',
'11' : 'Nov',
'12' : 'Dec'
}
// Format the date
$.date = function(dateObject) {
var d = new Date(dateObject);
var day = d.getDate();
var month_num = d.getMonth() + 1;
if (month_num < 10) {
month_num = "0" + month_num;
}
var month = months[month_num];
var year = d.getFullYear();
var date = month + " " + day + ", " + year;
return date;
};
var feed = "https://blog.example.com/blog/rss.xml"; // RSS Feed url
var items = []; // Create an array of our RSS items
var count = 0; // Set an iterating variable to be used as the array index
// Parse the RSS feed and assign values to an object
$.ajax(feed, {
accepts:{
xml:"application/rss+xml"
},
dataType:"xml",
success:function(data) {
jQuery(data).find("item").each(function () {
var el = $(this);
var description_html = el.find("description").text();
// Pull the featured image url out of the description <img> tag:
var srcWithQuotes = description_html.match(/src\=([^\s]*)\s/)[1];
var src=srcWithQuotes.substring(1,srcWithQuotes.length - 1);
var image_url_raw = src;
var image_url = image_url_raw.split('?')[0]; // remove url parameters
var title = el.find("title").text();
var link = el.find("link").text();
// Remove HTML tags and truncate the description:
var description_long = $(description_html).text(); // remove html tags
var description = $.trim(description_long).substring(0, 140).split(" ").slice(0, -1).join(" ") + "..."; // truncate to 140 characters and add elipses
// Change the date format
var date_raw = el.find("pubDate").text();
var date = $.date(date_raw); // reformat date to: Jan 1, 2018
// Create item object
item = {
image_url : image_url,
date : date,
title : title,
link : link,
description : description
};
// Add item object to items array
items.push(item);
count++;
});
// Put your code here that will render the posts to make sure the RSS feed has loaded successfully.
}
});
}
});
External RSS feed within a Custom Module for a drag-and-drop email template?
In case anyone comes later and wants to load their Hubspot blogs on a different website I've used this article as a starting place to build a manual RSS parser (with jQuery):
jQuery(document).ready(function() {
if( jQuery('.home-blog').hasClass('enable-hubspot-blog') ) { // just making sure this code is only running on the correct page
var months = {
'01' : 'Jan',
'02' : 'Feb',
'03' : 'Mar',
'04' : 'Apr',
'05' : 'May',
'06' : 'Jun',
'07' : 'Jul',
'08' : 'Aug',
'09' : 'Sep',
'10' : 'Oct',
'11' : 'Nov',
'12' : 'Dec'
}
// Format the date
$.date = function(dateObject) {
var d = new Date(dateObject);
var day = d.getDate();
var month_num = d.getMonth() + 1;
if (month_num < 10) {
month_num = "0" + month_num;
}
var month = months[month_num];
var year = d.getFullYear();
var date = month + " " + day + ", " + year;
return date;
};
var feed = "https://blog.example.com/blog/rss.xml"; // RSS Feed url
var items = []; // Create an array of our RSS items
var count = 0; // Set an iterating variable to be used as the array index
// Parse the RSS feed and assign values to an object
$.ajax(feed, {
accepts:{
xml:"application/rss+xml"
},
dataType:"xml",
success:function(data) {
jQuery(data).find("item").each(function () {
var el = $(this);
var description_html = el.find("description").text();
// Pull the featured image url out of the description <img> tag:
var srcWithQuotes = description_html.match(/src\=([^\s]*)\s/)[1];
var src=srcWithQuotes.substring(1,srcWithQuotes.length - 1);
var image_url_raw = src;
var image_url = image_url_raw.split('?')[0]; // remove url parameters
var title = el.find("title").text();
var link = el.find("link").text();
// Remove HTML tags and truncate the description:
var description_long = $(description_html).text(); // remove html tags
var description = $.trim(description_long).substring(0, 140).split(" ").slice(0, -1).join(" ") + "..."; // truncate to 140 characters and add elipses
// Change the date format
var date_raw = el.find("pubDate").text();
var date = $.date(date_raw); // reformat date to: Jan 1, 2018
// Create item object
item = {
image_url : image_url,
date : date,
title : title,
link : link,
description : description
};
// Add item object to items array
items.push(item);
count++;
});
// Put your code here that will render the posts to make sure the RSS feed has loaded successfully.
}
});
}
});