diff --git a/README.md b/README.md index d256045..c1f3c2b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ bangumis: color_summary: "#555" # 追番项简介的颜色 bgmtv_uid: mmdjiji # bgm.tv的uid download_image: true # 下载图片并使用本地图片,否则使用bgm.tv提供的网络图源 + image_level: c # 图片高清等级 (l, c, m, s, g) lazyload: true # 是否开启懒加载 margin: 20px # 封面图的偏移量微调 ``` diff --git a/dist/templates/bangumi.ejs b/dist/templates/bangumi.ejs index 98441bd..dbf2c46 100644 --- a/dist/templates/bangumi.ejs +++ b/dist/templates/bangumi.ejs @@ -19,19 +19,19 @@
- <% wantWatch.forEach(function(item){ %> + <% wantWatch.forEach(function(item) { %> <%- include('bgm-template.ejs', { item, loading, color_meta }) %> <% }); %> <%- include('pagination.ejs', {__: __}) %>
- <% watching.forEach(function(item){ %> + <% watching.forEach(function(item) { %> <%- include('bgm-template.ejs', { item, loading, color_meta }) %> <% }); %> <%- include('pagination.ejs', {__: __}) %>
- <% watched.forEach(function(item){ %> + <% watched.forEach(function(item) { %> <%- include('bgm-template.ejs', { item, loading, color_meta }) %> <% }); %> <%- include('pagination.ejs', {__: __}) %> diff --git a/dist/templates/bgm-template.ejs b/dist/templates/bgm-template.ejs index 2f72df6..3aad476 100644 --- a/dist/templates/bgm-template.ejs +++ b/dist/templates/bgm-template.ejs @@ -3,7 +3,7 @@ <% if(download_image) { %> " data-src="<%= `/images/${item.image}` %>" referrerPolicy="no-referrer" width="110" style="width:110px;margin:<%= margin %> auto;" /> <% } else { %> - " data-src="<%= `/images/${item.image}` %>" referrerPolicy="no-referrer" width="110" style="width:110px;margin:<%= margin %> auto;" /> + " data-src="<%= `/images/${item.image}` %>" referrerPolicy="no-referrer" width="110" style="width:110px;margin:<%= margin %> auto;" /> <% } %>
diff --git a/index.js b/index.js index 0363ccb..3da0db9 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,10 @@ hexo.extend.generator.register('bangumis', function (locals) { return; } + if (!fs.existsSync(path.join(this.source_dir, '/images/loading.gif'))) { + fs.copyFile(path.join(__dirname, 'img/loading.gif'), path.join(this.source_dir, '/images/loading.gif')); + } + return require('./dist/bangumi-generator').call(this, locals); }); hexo.extend.console.register('bangumis', 'Generate pages of bangumis for Hexo', options, function (args) { @@ -53,13 +57,14 @@ hexo.extend.console.register('bangumis', 'Generate pages of bangumis for Hexo', var _this$config$bangumis2 = this.config.bangumis, enable = _this$config$bangumis2.enable, bgmtv_uid = _this$config$bangumis2.bgmtv_uid, - download_image = _this$config$bangumis2.download_image; + download_image = _this$config$bangumis2.download_image, + image_level = _this$config$bangumis2.image_level; if (!enable) { return; } - getBgmData(bgmtv_uid, download_image, this.source_dir); + getBgmData(bgmtv_uid, download_image, image_level, this.source_dir); } else { log.info('Unknown command, please use "hexo bangumis -h" to see the available commands'); } diff --git a/src/index.js b/src/index.js index ec7eb73..223092a 100644 --- a/src/index.js +++ b/src/index.js @@ -40,11 +40,11 @@ hexo.extend.console.register('bangumis', 'Generate pages of bangumis for Hexo', log.info('Please add config to _config.yml'); return; } - const { enable, bgmtv_uid, download_image } = this.config.bangumis; + const { enable, bgmtv_uid, download_image, image_level } = this.config.bangumis; if (!enable) { return; } - getBgmData(bgmtv_uid, download_image, this.source_dir); + getBgmData(bgmtv_uid, download_image, image_level, this.source_dir); } else { log.info('Unknown command, please use "hexo bangumis -h" to see the available commands'); } diff --git a/src/lib/bangumi-generator.js b/src/lib/bangumi-generator.js index bb4efd7..1086d3d 100644 --- a/src/lib/bangumi-generator.js +++ b/src/lib/bangumi-generator.js @@ -42,6 +42,7 @@ module.exports = async function (locals) { lazyload: config.bangumis.lazyload ?? true, margin: config.bangumis.margin ?? '20px', download_image: config.bangumis.download_image ?? false, + image_level: config.bangumis.image_level ?? 'c', wantWatch, watched, watching, diff --git a/src/lib/get-bgm-data.js b/src/lib/get-bgm-data.js index b7c6025..68a83c3 100644 --- a/src/lib/get-bgm-data.js +++ b/src/lib/get-bgm-data.js @@ -163,9 +163,9 @@ const getBangumi = async (bgm, cachePath) => { log.info(`Get bangumi (${bangumi_id}) Failed, maybe invalid!`); }; -const getImage = (image_url, imagesPath) => { +const getImage = (image_url, imagesPath, image_level) => { if (image_url && !fs.existsSync(`${imagesPath}/${image_url}`)) { - fetch(`https://lain.bgm.tv/pic/cover/c/${image_url}`, { + fetch(`https://lain.bgm.tv/pic/cover/${image_level}/${image_url}`, { method: 'GET', headers: { 'Content-Type': 'application/octet-stream' } }).then((res) => res.buffer()) @@ -177,7 +177,7 @@ const getImage = (image_url, imagesPath) => { } }; -module.exports.getBgmData = async (bgmtv_uid, download_image, source_dir) => { +module.exports.getBgmData = async (bgmtv_uid, download_image, image_level, source_dir) => { // create folders if not exist const bangumisPath = path.join(source_dir, '/_data/bangumis'); const cachePath = path.join(bangumisPath, '/cache'); @@ -209,7 +209,7 @@ module.exports.getBgmData = async (bgmtv_uid, download_image, source_dir) => { if (info) { result.push(info); if (download_image) { - getImage(info.image, imagesPath); + getImage(info.image, imagesPath, image_level); } log.info(`Get bangumi 《${info.name_cn || info.name}》 (${info.id}) Success!`); }