diff --git a/lib/v2/shmtu/portal.js b/lib/v2/shmtu/portal.js index 671fc32c2..871dd95e6 100644 --- a/lib/v2/shmtu/portal.js +++ b/lib/v2/shmtu/portal.js @@ -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; }) diff --git a/lib/v2/shmtu/templates/portal.art b/lib/v2/shmtu/templates/portal.art new file mode 100644 index 000000000..b4bfd91fe --- /dev/null +++ b/lib/v2/shmtu/templates/portal.art @@ -0,0 +1,30 @@ +{{@ body}} +{{if images}} + + 图片: + + {{each images image}} +
+ {{image.filename}} +
+ {{image.alt}} +
+
+ {{/each}} +{{/if}} +{{if files}} + + 附件: + + {{each files file}} +

+ + + {{file.filename}} + + +

+ {{/each}} +{{/if}}