我正在尝试将我的媒体提要集成到 gatsby 中,并且只想选择几篇文章 - 没有最新的文章。我能够使用此代码获得三篇最新文章:
索引配置
mediumRssFeed:
"https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40maxgraze",
shownArticles: 3,
文章.js
const Articles = () => {
const MAX_ARTICLES = shownArticles
const { isIntroDone, darkMode } = useContext(Context).state
const [articles, setArticles] = useState()
const articlesControls = useAnimation()
// Load and display articles after the splashScreen sequence is done
useEffect(() => {
const loadArticles = async () => {
if (isIntroDone) {
await articlesControls.start({
opacity: 1,
y: 0,
transition: { delay: 1 },
})
fetch(mediumRssFeed, { headers: { Accept: "application/json" } })
.then(res => res.json())
// Feed also contains comments, therefore we filter for articles only
.then(data => data.items.filter(item => item.categories.length > 0))
.then(newArticles => newArticles.slice(0, MAX_ARTICLES))
.then(articles => setArticles(articles))
.catch(error => console.log(error))
}
}
loadArticles()
}, [isIntroDone, articlesControls, MAX_ARTICLES])
但我希望使用 gatsby-source-medium 查询特定文章。但是,它只返回 4(甚至不返回最新的)。
有没有办法通过 gatsby-source-medium 获取我所有的文章?否则,有没有办法“硬编码”我想要的文章?我不确定如何使用 rss feed api 进行过滤。谢谢你的帮助!