从 reddit 获取高分辨率图像
Fetch hi res images from reddit
我正在尝试根据新近度从 subreddit 中获取高分辨率图像。我可以拉出缩略图,但不知道如何拉出真正的高分辨率图像。
这是我的代码:
fetch('https://www.reddit.com/r/cats.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.thumbnail,
title: post.data.title
})))
.then(res => res.map(render))
.then(res => console.log(res))
const app = document.querySelector('#app');
const render = post => {
const node = document.createElement('div');
node.innerHTML = `
<a href="${post.link}">
<img src="${post.img}"/>
</a>`;
app.appendChild(node);
}
& 这是我的 fiddle
有什么想法吗?
看来您需要交换 href 和 img src
fetch('https://www.reddit.com/r/cats.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.thumbnail,
title: post.data.title
})))
.then(res => res.map(render))
.then(res => console.log(res))
const app = document.querySelector('#app');
const render = post => {
const node = document.createElement('div');
node.innerHTML = `
<a href="${post.img}">
<img src="${post.link}"/>
</a>`;
app.appendChild(node);
}
Fiddle: https://jsfiddle.net/qt7ktv4L/2/
我正在尝试根据新近度从 subreddit 中获取高分辨率图像。我可以拉出缩略图,但不知道如何拉出真正的高分辨率图像。
这是我的代码:
fetch('https://www.reddit.com/r/cats.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.thumbnail,
title: post.data.title
})))
.then(res => res.map(render))
.then(res => console.log(res))
const app = document.querySelector('#app');
const render = post => {
const node = document.createElement('div');
node.innerHTML = `
<a href="${post.link}">
<img src="${post.img}"/>
</a>`;
app.appendChild(node);
}
& 这是我的 fiddle
有什么想法吗?
看来您需要交换 href 和 img src
fetch('https://www.reddit.com/r/cats.json')
.then(res => res.json())
.then(res => res.data.children)
.then(res => res.map(post => ({
author: post.data.author,
link: post.data.url,
img: post.data.thumbnail,
title: post.data.title
})))
.then(res => res.map(render))
.then(res => console.log(res))
const app = document.querySelector('#app');
const render = post => {
const node = document.createElement('div');
node.innerHTML = `
<a href="${post.img}">
<img src="${post.link}"/>
</a>`;
app.appendChild(node);
}
Fiddle: https://jsfiddle.net/qt7ktv4L/2/