hexo-generator-podcasts
Version:
Hexo Generator for Podcast
69 lines (68 loc) • 3.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var template_1 = require("./template");
function generat_podcast_feed(podcastsConfig, locals) {
var categories = locals.categories;
if (podcastsConfig.path[podcastsConfig.path.length - 1] !== '/')
podcastsConfig.path += '/';
var podcast_category = categories.findOne({ name: podcastsConfig.name });
var posts = podcast_category ? podcast_category.posts.sort('date', -1).data : [];
var podcastItunesCategory = podcastsConfig.category.map(function (item) {
var data = item.split(" - ");
return {
top: data[0],
sub: data[1] ? data[1] : ''
};
});
var FeedConfig = {
title: podcastsConfig.title,
subtitle: podcastsConfig.subtitle,
feedUrl: hexo.config.url + "/" + podcastsConfig.path,
homepage: hexo.config.url,
description: podcastsConfig.description,
logo: podcastsConfig.image,
language: podcastsConfig.language ? podcastsConfig.language : "en-US",
author: podcastsConfig.author,
explicit: podcastsConfig.explicit ? podcastsConfig.explicit : "clean",
copyright: podcastsConfig.copyright,
updatePeriod: podcastsConfig.updatePeriod ? podcastsConfig.updatePeriod : "hourly",
updateFrequency: podcastsConfig.updateFrequency ? podcastsConfig.updateFrequency : 1,
type: podcastsConfig.type,
owner: podcastsConfig.owner,
category: podcastItunesCategory,
posts: posts
};
return {
path: podcastsConfig.path,
data: template_1.Template.generateFeed(FeedConfig)
};
}
hexo.extend.generator.register('podcasts', function (locals) {
var podcastsConfig = hexo.config.podcasts;
if (!podcastsConfig)
return [];
hexo.scaffold.get("episode").then(function (item) {
if (!item) {
var templateContent = fs_1.default.readFileSync(path_1.default.join(__dirname, "../template/episode.md"), "utf-8");
hexo.scaffold.set("episode", templateContent);
}
});
if (podcastsConfig instanceof Array) {
var responseArray_1 = [];
podcastsConfig.forEach(function (item) {
responseArray_1.push(generat_podcast_feed(item, locals));
});
return responseArray_1;
}
if (podcastsConfig instanceof Object) {
return generat_podcast_feed(podcastsConfig, locals);
}
});
hexo.extend.tag.register('podplayer', function () {
return " <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css\" integrity=\"sha256-uqQQGnDcmRKvhKwc5Vm4XT1GQ2oV6t1U0NR2N9tV+BQ=\" crossorigin=\"anonymous\"> <script src=\"https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js\" integrity=\"sha256-6Y7CJDaltoeNgk+ZftgCD9jLgmGv4xKUo8nQ0HgAwVo=\" crossorigin=\"anonymous\"></script> <div id=\"" + this._id + "\"></div> <script>const ap = new APlayer({ container: document.getElementById('" + this._id + "'), audio: [{ name: '" + this.title + "', url: '" + this.media + "', cover: '" + this.image + "' }] });</script>";
});