feature: add favorite articles to now page
This commit is contained in:
parent
28f8330579
commit
059ec28b00
4 changed files with 37 additions and 3 deletions
15
src/_data/articles.js
Normal file
15
src/_data/articles.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const EleventyFetch = require('@11ty/eleventy-fetch')
|
||||
|
||||
module.exports = async function () {
|
||||
const MATTER_TOKEN = process.env.ACCESS_TOKEN_MATTER
|
||||
const headers = { Authorization: `Bearer ${MATTER_TOKEN}` }
|
||||
const url = `https://web.getmatter.com/api/library_items/favorites_feed`
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
fetchOptions: { headers },
|
||||
})
|
||||
const feed = await res
|
||||
const articles = feed.feed.splice(0, 5)
|
||||
return articles
|
||||
}
|
|
@ -9,7 +9,9 @@ module.exports = async function () {
|
|||
getExtraEntryFields: (feedEntry) => {
|
||||
const images = feedEntry['description']?.match(/<img [^>]*src="[^"]*"[^>]*>/gm) || []
|
||||
return {
|
||||
image: images.length ? images.map((image) => image.replace(/.*src="([^"]*)".*/, '$1'))[0] : '',
|
||||
image: images.length
|
||||
? images.map((image) => image.replace(/.*src="([^"]*)".*/, '$1'))[0]
|
||||
: '',
|
||||
}
|
||||
},
|
||||
}).catch((error) => {
|
||||
|
|
Reference in a new issue