前言
使用 neodb.social 的API算是多一种选择.
豆瓣数据的获取还是不太方便
获取neodb的token
使用mastodon账号登录 https://neodb.social/
在右上角头像点击- 设置
- 找到更多设置
![2024-12-26T00:09:57.png][2]
点击 查看已授权的应用程序
![2024-12-26T00:11:01.png][1]
生成一个token即可
获取neodb API
在此使用项目
https://github.com/Lyunvy/neodb-shelf-api
可以部署在vercel上,过程就不赘述了
使用
CSS
.masonry { display: flex; flex-wrap: wrap; gap: 5px; }
.item { flex: 1 1 calc(25% - 20px); position: relative; overflow: hidden; box-sizing: border-box; }
@media (max-width: 1200px) { .item { flex: 1 1 calc(33.33% - 20px); } }
@media (max-width: 900px) { .item { flex: 1 1 calc(50% - 20px); } }
@media (max-width: 600px) { .item { flex: 1 1 100%; } }
.image-container { position: relative; width: 100%; padding-top: 150%; overflow: hidden; }
.image-container img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease-in-out; }
.item-content { position: absolute; font-size: 12px; bottom: 0; left: 0; width: auto; background-color: rgba(0, 0, 0, 0.7); color: white; padding: 10px; transform: translateY(100%); transition: transform 0.3s ease-in-out; }
.item:hover .item-content { transform: translateY(0); }
.item:hover .image-container img { transform: scale(1.1); }
.item-title a { color: white; text-decoration: none; font-size: 20px; }
.item-title a:hover { text-decoration: underline; }
|
JS
function MovieItem(movie) { const commentText = movie.comment_text ? movie.comment_text : '暂无评论'; const rating = movie.item.rating ? movie.item.rating : '暂无评分'; return ` <div class="item"> <div class="image-container"> <img src="${movie.item.cover_image_url}" alt="${movie.item.title}" onerror="this.onerror=null; this.src='placeholder.jpg';"> </div> <div class="item-content"> <div class="item-title"> <a href="${movie.item.id}" target="_blank" rel="noopener noreferrer">${movie.item.title}</a> </div> <div class="item-info">${commentText}</div> <div class="item-score">评分: ${rating}</div> </div> </div> `; }
async function fetchAndRenderMovies() { try { const response = await fetch('https://neodb.imsun.org/api?type=complete&category=movie'); const data = await response.json();
const container = document.getElementById('movieContainer'); data.forEach(movie => { container.innerHTML += MovieItem(movie); }); } catch (error) { console.error('Error fetching movie data:', error); document.getElementById('movieContainer').innerHTML = '<p>加载电影数据时出错,请稍后再试。</p>'; } }
fetchAndRenderMovies();
|
此处https://neodb.imsun.org
为部署在vercel
的地址
HTML
<link rel="stylesheet" href="/movies/movies.css"> <div class="masonry" id="movieContainer"> </div> <script defer src="/movies/movies.js"></script>
|
演示效果
https://blog.loliko.cn/movies/