diff --git a/docs/design.md b/docs/design.md index ef1a32e3b1..0c90bbc015 100755 --- a/docs/design.md +++ b/docs/design.md @@ -4,6 +4,12 @@ pageClass: routes # 设计 +## Digic Picture + +### 作品和新闻 + + + ## Blur Studio ### Works diff --git a/docs/en/design.md b/docs/en/design.md index 37b95895c6..bfd6997742 100755 --- a/docs/en/design.md +++ b/docs/en/design.md @@ -4,6 +4,12 @@ pageClass: routes # Design +## Digic Picture + +### Works & News + + + ## Blur Studio ### Works diff --git a/lib/router.js b/lib/router.js index 4d981475a8..fb726e2003 100755 --- a/lib/router.js +++ b/lib/router.js @@ -2598,4 +2598,7 @@ router.get('/bendibao/news/:city', require('./routes/bendibao/news')); // unit-image router.get('/unit-image/films/:type?', require('./routes/unit-image/films')); +// digic-picture +router.get('/digic-pictures/:menu/:tags?', require('./routes/digic-pictures/index')); + module.exports = router; diff --git a/lib/routes/digic-pictures/index.js b/lib/routes/digic-pictures/index.js new file mode 100755 index 0000000000..2f23609bff --- /dev/null +++ b/lib/routes/digic-pictures/index.js @@ -0,0 +1,72 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { menu, tags } = ctx.params; + const url = `https://digicpictures.com/${menu}/${tags}`; + const response = await got({ + method: 'get', + url: url, + }); + const data = response.data; + const $ = cheerio.load(data); + const list = $('ul#articles-slider li').get().slice(0, 5); + const articledata = await Promise.all( + list.map(async (item) => { + item = $(item); + const link = item.find('a').attr('href'); + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response2 = await got({ + method: 'get', + url: link, + }); + + const articledata = response2.data; + const $2 = cheerio.load(articledata); + const title = $2('div#main-content>div>div>div').find('h1').text(); + const time = $2('div#main-content>div>div>div:nth-child(1) p').text(); + const images = $2('#main-slider img') + .get() + .map((item) => $2(item).attr('src')); + const content = $2('div#main-content>div>div>div:nth-child(2)') + .html() + .replace(//g, '') + .replace('', '
') + .replace(/<.?p>/g, ''); + const single = { + title, + link, + time, + content, + images, + }; + ctx.cache.set(link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: 'Digic Picture', + link: 'https://www.digicpictures.com/', + item: list.map((item, index) => { + let content = ''; + const imgstyle = `style="max-width: 650px; height: auto; object-fit: contain; flex: 0 0 auto;"`; + + content += `${articledata[index].time}
${articledata[index].content}
`; + if (articledata[index].images) { + for (let p = 0; p < articledata[index].images.length; p++) { + content += `
`; + } + } + return { + title: `${articledata[index].title}`, + description: content, + link: `${articledata[index].link}`, + pubDate: `${articledata[index].time}`, + }; + }), + }; +};