Socket
Socket
Sign inDemoInstall

akashacms-blog-podcast

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

akashacms-blog-podcast - npm Package Compare versions

Comparing version 0.4.5 to 0.6.0

guide/index.html.md

346

index.js

@@ -26,2 +26,3 @@ /**

const akasha = require('akasharender');
const mahabhuta = require('mahabhuta');
const co = require('co');

@@ -32,6 +33,6 @@

const pluginName = "akashacms-blog-podcast";
module.exports = class BlogPodcastPlugin extends akasha.Plugin {
constructor() {
super("akashacms-blog-podcast");
}
constructor() { super(pluginName); }

@@ -41,16 +42,28 @@ configure(config) {

config.addPartialsDir(path.join(__dirname, 'partials'));
config.addMahabhuta(mahabhuta);
config.addMahabhuta(module.exports.mahabhuta);
config.pluginData(pluginName).bloglist = [];
}
addBlogPodcast(config, name, blogPodcast) {
if (!config.blogPodcast) config.blogPodcast = [];
config.blogPodcast[name] = blogPodcast;
return config;
}
addBlogPodcast(config, name, blogPodcast) {
config.pluginData(pluginName).bloglist[name] = blogPodcast;
return config;
}
isLegitLocalHref(config, href) {
// console.log(`isLegitLocalHref ${util.inspect(config.pluginData(pluginName).bloglist)} === ${href}?`);
for (var blogkey in config.pluginData(pluginName).bloglist) {
var blogcfg = config.pluginData(pluginName).bloglist[blogkey];
// console.log(`isLegitLocalHref ${blogcfg.rssurl} === ${href}?`);
if (blogcfg.rssurl === href) {
return true;
}
}
return false;
}
onSiteRendered(config) {
// console.log(`blog-podcast onSiteRendered ${util.inspect(config.blogPodcast)}`);
return co(function* () {
for (var blogcfgkey in config.blogPodcast) {
var blogcfg = config.blogPodcast[blogcfgkey];
for (var blogkey in config.pluginData(pluginName).bloglist) {
var blogcfg = config.pluginData(pluginName).bloglist[blogkey];
// console.log(`blog-podcast blogcfg ${util.inspect(blogcfg)}`);

@@ -67,3 +80,3 @@ var documents = yield findBlogDocs(config, undefined, blogcfg);

var rssitems = documents2.map(doc => {
var rssitems = documents2.map(doc => {
return {

@@ -77,2 +90,26 @@ title: doc.metadata.title,

var maxItems;
if (typeof blogcfg.maxItems === 'undefined') {
maxItems = 60;
} else if (blogcfg.maxItems <= 0) {
maxItems = undefined;
} else {
maxItems = blogcfg.maxItems;
}
if (maxItems) {
let rssitems2 = [];
let count = 0;
for (let item of rssitems) {
if (count < maxItems) {
rssitems2.push(item);
// console.log(`${blogkey} PUSH ITEM ${count} ${util.inspect(item)}`);
}
count++;
}
rssitems = rssitems2;
}
// console.log(`GENERATE RSS rssitems # ${rssitems.length} maxItems ${maxItems} ${util.inspect(blogcfg)} `);
// console.log(`GENERATE RSS ${config.renderDestination + blogcfg.rssurl} ${util.inspect(rssitems)}`);

@@ -133,5 +170,5 @@

*/
function findBlogDocs(config, metadata, blogcfg) {
var findBlogDocs = co.wrap(function* (config, metadata, blogcfg) {
return akasha.documentSearch(config, {
var documents = yield akasha.documentSearch(config, {
// rootPath: docDirPath,

@@ -142,190 +179,153 @@ pathmatch: blogcfg.matchers.path ? blogcfg.matchers.path : undefined,

rootPath: blogcfg.rootPath ? blogcfg.rootPath : undefined
})
.then(documents => {
// console.log('findBlogDocs '+ util.inspect(documents));
documents.sort(function(a, b) {
var aPublicationDate = Date.parse(
a.metadata.publicationDate ? a.metadata.publicationDate : a.stat.mtime
);
var bPublicationDate = Date.parse(
b.metadata.publicationDate ? b.metadata.publicationDate : b.stat.mtime
);
if (aPublicationDate < bPublicationDate) return -1;
else if (aPublicationDate === bPublicationDate) return 0;
else return 1;
});
documents.reverse();
return documents;
})
.then(documents => {
// log(util.inspect(documents));
return documents;
});
};
});
// console.log('findBlogDocs '+ util.inspect(documents));
documents.sort((a, b) => {
var aPublicationDate = Date.parse(
a.metadata.publicationDate ? a.metadata.publicationDate : a.stat.mtime
);
var bPublicationDate = Date.parse(
b.metadata.publicationDate ? b.metadata.publicationDate : b.stat.mtime
);
if (aPublicationDate < bPublicationDate) return -1;
else if (aPublicationDate === bPublicationDate) return 0;
else return 1;
});
documents.reverse();
return documents;
});
function findBlogIndexes(config, metadata, blogcfg) {
if (!blogcfg.indexmatchers) return Promise.resolve([]);
if (!blogcfg.indexmatchers) return Promise.resolve([]);
return akasha.documentSearch(config, {
pathmatch: blogcfg.indexmatchers.path ? blogcfg.indexmatchers.path : undefined,
renderers: [ akasha.HTMLRenderer ],
return akasha.documentSearch(config, {
pathmatch: blogcfg.indexmatchers.path ? blogcfg.indexmatchers.path : undefined,
renderers: [ akasha.HTMLRenderer ],
layouts: blogcfg.indexmatchers.layouts ? blogcfg.indexmatchers.layouts : undefined,
rootPath: blogcfg.rootPath ? blogcfg.rootPath : undefined
});
});
}
var mahabhuta = [
function($, metadata, dirty, done) {
module.exports.mahabhuta = new mahabhuta.MahafuncArray("akashacms-blog-podcast", {});
var elements = [];
$('blog-news-river').each(function(i, elem) { elements.push(elem); });
async.eachSeries(elements, (element, next) => {
var blogtag = $(element).attr("blogtag");
if (!blogtag) {
blogtag = metadata.blogtag;
}
if (!blogtag) {// no blog tag, skip? error?
error("NO BLOG TAG in blog-news-river"+ metadata.document.path);
return done(new Error("NO BLOG TAG in blog-news-river"+ metadata.document.path));
}
class BlogNewsRiverElement extends mahabhuta.CustomElement {
get elementName() { return "blog-news-river"; }
process($element, metadata, dirty) {
var blogtag = $element.attr("blogtag");
if (!blogtag) {
blogtag = metadata.blogtag;
}
if (!blogtag) {// no blog tag, skip? error?
error("NO BLOG TAG in blog-news-river"+ metadata.document.path);
throw new Error("NO BLOG TAG in blog-news-river"+ metadata.document.path);
}
// log('blog-news-river '+ blogtag +' '+ metadata.document.path);
// log('blog-news-river '+ blogtag +' '+ metadata.document.path);
var blogcfg = metadata.config.blogPodcast[blogtag];
if (!blogcfg) return done(new Error('No blog configuration found for blogtag '+ blogtag));
var blogcfg = metadata.config.pluginData(pluginName).bloglist[blogtag];
if (!blogcfg) throw new Error('No blog configuration found for blogtag '+ blogtag);
var _blogcfg = {};
for (var key in blogcfg) {
_blogcfg[key] = blogcfg[key];
}
var _blogcfg = {};
for (var key in blogcfg) {
_blogcfg[key] = blogcfg[key];
}
var maxEntries = $(element).attr('maxentries');
var maxEntries = $element.attr('maxentries');
var template = $(element).attr("template");
if (!template) template = "blog-news-river.html.ejs";
var template = $element.attr("template");
if (!template) template = "blog-news-river.html.ejs";
var rootPath = $(element).attr('root-path');
if (rootPath) {
_blogcfg.rootPath = rootPath;
}
var rootPath = $element.attr('root-path');
if (rootPath) {
_blogcfg.rootPath = rootPath;
}
var docRootPath = $(element).attr('doc-root-path');
if (docRootPath) {
_blogcfg.rootPath = path.dirname(docRootPath);
}
var docRootPath = $element.attr('doc-root-path');
if (docRootPath) {
_blogcfg.rootPath = path.dirname(docRootPath);
}
findBlogDocs(metadata.config, metadata, _blogcfg)
.then(documents => {
return findBlogDocs(metadata.config, metadata, _blogcfg)
.then(documents => {
// log('blog-news-river documents '+ util.inspect(documents));
// log('blog-news-river documents '+ util.inspect(documents));
var count = 0;
var documents2 = documents.filter(doc => {
if (typeof maxEntries === "undefined"
|| (typeof maxEntries !== "undefined" && count++ < maxEntries)) {
return true;
} else return false;
});
// log('blog-news-river documents2 '+ util.inspect(documents2));
var count = 0;
var documents2 = documents.filter(doc => {
if (typeof maxEntries === "undefined"
|| (typeof maxEntries !== "undefined" && count++ < maxEntries)) {
return true;
} else return false;
});
// log('blog-news-river documents2 '+ util.inspect(documents2));
akasha.partial(metadata.config, template, {
documents: documents2,
feedUrl: _blogcfg.rssurl
})
.then(htmlRiver => {
$(element).replaceWith(htmlRiver);
next();
})
.catch(err => { next(err); });
})
.catch(err => { done(err); });
},
function(err) {
if (err) done(err);
else done();
});
},
return akasha.partial(metadata.config, template, {
documents: documents2,
feedUrl: _blogcfg.rssurl
});
});
}
}
module.exports.mahabhuta.addMahafunc(new BlogNewsRiverElement());
function($, metadata, dirty, done) {
var elements = [];
$('blog-news-index').each(function(i, elem) { elements.push(elem); });
async.eachSeries(elements, (element, next) => {
var blogtag = $(element).attr("blogtag");
if (!blogtag) {
blogtag = metadata.blogtag;
}
if (!blogtag) {// no blog tag, skip? error?
error("NO BLOG TAG in blog-news-index"+ metadata.document.path);
return done(new Error("NO BLOG TAG in blog-news-index"+ metadata.document.path));
}
class BlogNewsIndexElement extends mahabhuta.CustomElement {
get elementName() { return "blog-news-index"; }
process($element, metadata, dirty) {
var blogtag = $element.attr("blogtag");
if (!blogtag) {
blogtag = metadata.blogtag;
}
if (!blogtag) {// no blog tag, skip? error?
error("NO BLOG TAG in blog-news-index"+ metadata.document.path);
throw new Error("NO BLOG TAG in blog-news-index"+ metadata.document.path);
}
var blogcfg = metadata.config.blogPodcast[blogtag];
if (!blogcfg) return done(new Error('No blog configuration found for blogtag '+ blogtag));
var blogcfg = metadata.config.pluginData(pluginName).bloglist[blogtag];
if (!blogcfg) return done(new Error('No blog configuration found for blogtag '+ blogtag));
var template = $(element).attr("template");
if (!template) template = "blog-news-indexes.html.ejs";
var template = $element.attr("template");
if (!template) template = "blog-news-indexes.html.ejs";
findBlogIndexes(metadata.config, metadata, blogcfg)
.then(indexDocuments => {
if (indexDocuments.length <= 0) return next();
return findBlogIndexes(metadata.config, metadata, blogcfg)
.then(indexDocuments => {
return akasha.partial(metadata.config, template, { indexDocuments });
});
}
}
module.exports.mahabhuta.addMahafunc(new BlogNewsIndexElement());
return akasha.partial(metadata.config, template, { indexDocuments })
.then(htmlIndexes => {
$(element).replaceWith(htmlIndexes);
next();
});
})
.catch(err => { next(err); });
class BlogRSSIconElement extends mahabhuta.CustomElement {
get elementName() { return "blog-rss-icon"; }
process($element, metadata, dirty) {
var blogtag = $element.attr("blogtag");
if (!blogtag) {
blogtag = metadata.blogtag;
}
if (!blogtag) {// no blog tag, skip? error?
error("NO BLOG TAG in blog-rss-icon"+ metadata.document.path);
throw new Error("NO BLOG TAG in blog-rss-icon"+ metadata.document.path);
}
},
function(err) {
if (err) done(err);
else done();
});
},
var blogcfg = metadata.config.pluginData(pluginName).bloglist[blogtag];
if (!blogcfg) throw new Error('No blog configuration found for blogtag '+ blogtag);
function($, metadata, dirty, done) {
var elements = [];
$('blog-rss-icon').each(function(i, elem) { elements.push(elem); });
async.eachSeries(elements, (element, next) => {
var blogtag = $(element).attr("blogtag");
if (!blogtag) {
blogtag = metadata.blogtag;
}
if (!blogtag) {// no blog tag, skip? error?
error("NO BLOG TAG in blog-rss-icon"+ metadata.document.path);
return done(new Error("NO BLOG TAG in blog-rss-icon"+ metadata.document.path));
}
var template = $element.attr("template");
if (!template) template = "blog-rss-icon.html.ejs";
var blogcfg = metadata.config.blogPodcast[blogtag];
if (!blogcfg) return done(new Error('No blog configuration found for blogtag '+ blogtag));
return akasha.partial(metadata.config, template, {
feedUrl: blogcfg.rssurl
});
}
}
module.exports.mahabhuta.addMahafunc(new BlogRSSIconElement());
akasha.partial(metadata.config, "blog-rss-icon.html.ejs", {
feedUrl: blogcfg.rssurl
})
.then(htmlIcon => {
$(element).replaceWith(htmlIcon);
next();
})
.catch(err => { next(err); });
},
function(err) {
if (err) done(err);
else done();
});
},
function($, metadata, dirty, done) {
module.exports.mahabhuta.addMahafunc([
function($, metadata, dirty, done) {
if (! metadata.blogtag) {return done(); }
if (!metadata.config.blogPodcast) { return done(); }
var blogcfg = metadata.config.blogPodcast[metadata.blogtag];
var blogcfg = metadata.config.pluginData(pluginName).bloglist[metadata.blogtag];
if (!blogcfg) return done(new Error('No blog configuration found for blogtag '+ metadata.blogtag +' in '+ metadata.document.path));
if (! metadata.config.blogPodcast.hasOwnProperty(metadata.blogtag)) {
return done(new Error("no blogPodcast item for "+ metadata.blogtag));
}
// log('blog-next-prev '+ metadata.document.path +' '+ util.inspect(blogcfg));
var elements = [];
var elements = [];
$('blog-next-prev').each(function(i, elem) { elements.push(elem); });
if (elements.length > 0) {
// log('blog-next-prev');
// log('blog-next-prev');
findBlogDocs(metadata.config, metadata, blogcfg)

@@ -337,3 +337,3 @@ .then(documents => {

for (var j = 0; docIndex === -1 && j < documents.length; j++) {
// log(`blog-next-prev ${documents[j].docpath} === ${metadata.document.path}`);
// log(`blog-next-prev ${documents[j].docpath} === ${metadata.document.path}`);
if (documents[j].docpath === metadata.document.path) {

@@ -353,3 +353,3 @@ docIndex = j;

})
.catch(err => { next(err); });
.catch(err => { next(err); });
} else {

@@ -367,2 +367,2 @@ next(new Error('did not find document '+ metadata.document.path +' in blog'));

}
];
]);

@@ -14,5 +14,5 @@ {

},
"version": "0.4.5",
"version": "0.6.0",
"engines": {
"node": ">=0.10.1"
"node": ">=6.1"
},

@@ -19,0 +19,0 @@ "dependencies": {

# akashacms-blog-podcast
AkashaCMS plugin for blogging and podcasting
See [the AkashaCMS website](http://akashacms.com/plugins/blog-podcast.html) for documentation
See http://akashacms.com/new/plugins/blog-podcast/index.html for documentation

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc