feat: add attachments to shmtu portal feeds with art-template (#11426)

* feat: add attachments to feeds

* fix: use art-template for custom HTML contents

* fix: replace `a` tag with `img` tag
This commit is contained in:
imbytecat 2022-12-09 21:40:00 +08:00 committed by GitHub
parent 39d97d3427
commit cd0b88f1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View File

@ -2,6 +2,9 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const path = require('path');
const { art } = require('@/utils/render');
const bootstrapHost = 'https://weixin.shmtu.edu.cn/dynamic/shmtuHttps';
const host = 'https://portal.shmtu.edu.cn/api';
@ -21,7 +24,13 @@ const processFeed = (list, caches) =>
list.map((item) =>
caches.tryGet(item.link, async () => {
const detail = await loadDetail(item.link);
item.description = detail.body.und[0].safe_value;
const files = detail.field_file;
const images = detail.field_image;
item.description = art(path.join(__dirname, 'templates/portal.art'), {
body: detail.body.und[0].safe_value,
images: images.length !== 0 && Object.keys(images).length !== 0 ? images.und : null,
files: files.length !== 0 && Object.keys(files).length !== 0 ? files.und : null,
});
item.link = detail.path;
return item;
})

View File

@ -0,0 +1,30 @@
{{@ body}}
{{if images}}
<span style="font-size:19px">
图片:
</span>
{{each images image}}
<figure>
<img src="https://weixin.shmtu.org/dynamic/getFile?fid={{image.fid}}"
alt="{{image.filename}}"
style="margin: 0 auto" />
<figcaption style="text-align:center;font-size:19px">
{{image.alt}}
</figcaption>
</figure>
{{/each}}
{{/if}}
{{if files}}
<span style="font-size:19px">
附件:
</span>
{{each files file}}
<p style="text-indent:32px">
<span style="font-size:19px">
<a href="https://weixin.shmtu.org/dynamic/getFile?fid={{file.fid}}" target="_blank">
{{file.filename}}
</a>
</span>
</p>
{{/each}}
{{/if}}