Skip to content

Instantly share code, notes, and snippets.

@scripting
Last active April 15, 2024 14:20
Show Gist options
  • Save scripting/550f3f0ea0f808446d690560b7871856 to your computer and use it in GitHub Desktop.
Save scripting/550f3f0ea0f808446d690560b7871856 to your computer and use it in GitHub Desktop.
function getBlogrollOptions (headLevelAtts) {
/*
4/15/24; 8:58:41 AM by DW
The author of the blog can enable a blogroll via three head-level attributes.
We're looking for these --
blogrollUsername -- required
blogrollServer -- optional
blogrollCategory -- optional
Defaults
If blogrollServer is not specified, we use feedland.com
If blogrollCategory is not specified, we don't specify one in the URLs we generate
We translate those values to the ones the blogroll software needs --
urlSocketServer
urlFeedlandViewBlogroll
urlBlogrollOpml
We return undefined if no blogroll is called for, otherwise it has the three values we transmit to the blogroll software.
*/
const urlFeedlandCom = "https://feedland.com/";
const wsUrlFeedlandCom = "wss://feedland.com:443/_ws/";
var username = headLevelAtts.blogrollUsername;
var urlServer = headLevelAtts.blogrollServer;
var catname = headLevelAtts.blogrollCategory;
var urlSocketServer, urlFeedlandViewBlogroll;
if (username === undefined) { //username is required
return (undefined);
}
else {
username = trimWhitespace (username);
if (username.length == 0) {
return (undefined);
}
else {
if (urlServer === undefined) {
urlServer = urlFeedlandCom;
}
urlServer = trimWhitespace (urlServer);
if (!endsWith (urlServer, "/")) {
urlServer += "/";
}
if (catname !== undefined) {
catname = trimWhitespace (catname);
if (catname.length == 0) {
catname = undefined;
}
}
//set urlSocketServer
if (urlServer == urlFeedlandCom) {
urlSocketServer = "wss://feedland.com:443/_ws/";
}
else {
urlSocketServer = replaceAll (urlServer, "https://", "wss://");
}
//set urlFeedlandViewBlogroll
urlFeedlandViewBlogroll = urlServer + "?username=" + urlEncode (username);
if (catname !== undefined) {
urlFeedlandViewBlogroll += "&catname=" + urlEncode (catname);
}
//set urlBlogrollOpml
urlBlogrollOpml = urlServer + "opml?screenname=" + urlEncode (username);
if (catname !== undefined) {
urlBlogrollOpml += "&catname=" + urlEncode (catname);
}
return ({urlSocketServer, urlFeedlandViewBlogroll, urlBlogrollOpml});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment