由Memos自动生成相册页面

上文为瀑布流样式
https://blog.memos.ee/archives/39.html

目前更新为 lightbox2 固定图片大小

引入以下

CSS

Copy
/* 页面初始化 */
.page-title{display: none;}
.page-top-card {border-radius: 12px;}
/* 页面初始化结束 */
#article-container a img {margin: 0; border-radius:0;}
.gallery-photos{width:100%;margin-top: 10px;}
.gallery-photo{min-height:5rem;width:33.3%;height:250px;padding:6px;position: relative;overflow: hidden;box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;}
.gallery-photo a{display:block;overflow: hidden;border: var(--leonus-border);}
.gallery-photo img{display: block;width:100%;animation: fadeIn 1s;cursor: pointer;transition: all .4s ease-in-out !important;}
.gallery-photo span.photo-title,.gallery-photo span.photo-time{max-width: calc(100% - 7px);position:absolute;line-height:1.8;left:4px;font-size:14px;background: rgba(0, 0, 0, 0.3);padding:0px 8px;color: #fff;animation: fadeIn 1s;}
.gallery-photo span.photo-title{bottom:4px;}
.gallery-photo span.photo-time{top:4px;}
.gallery-photo:hover img{transform: scale(1.1);}
@media screen and (max-width: 1100px) {
.gallery-photo{width:33.3%;height:200px;overflow:hidden;}
}
@media screen and (max-width: 900px) {.page-top-card {margin: 0;}}
@media screen and (max-width: 768px) {
.gallery-photo{width:49.9%;height:200px;overflow:hidden;padding:3px}
.gallery-photo span.photo-time{display:none}
.page-top-card {border-radius: 8px;}
.gallery-photo span.photo-title{left:3px;bottom:3px;}
}
@keyframes fadeIn{0% {opacity: 0;}100%{opacity: 1;}}

JS

Copy
if (1) {
let url = 'https://memos.imsun.org' // 修改api
fetch(url + '/api/v1/memo?creatorId=1&tag=照片').then(res => res.json()).then(data => {
let html = '',
imgs = []
data.forEach(item => {
let ls = item.content.match(/\!\[.*?\]\(.*?\)/g)
if (ls) imgs = imgs.concat(ls)
if (item.resourceList.length) {
item.resourceList.forEach(t => {
if (t.externalLink) imgs.push(`![](${t.externalLink})`)
else imgs.push(`![](${url}/o/r/${t.id}/${t.publicId}/${t.filename})`)
})
}
})

if (imgs) imgs.forEach(item => {
let img = item.replace(/!\[.*?\]\((.*?)\)/g, '$1'),
time, title, tat = item.replace(/!\[(.*?)\]\(.*?\)/g, '$1')
if (tat.indexOf(' ') != -1) {
time = tat.split(' ')[0]
title = tat.split(' ')[1]
} else title = tat

html += ` `
title ? html += `${title}` : ''
time ? html += `${time}` : ''
html += ` `
})
console.log(lightbox);
document.querySelector('.gallery-photos.page').innerHTML = html
imgStatus.watch('.photo-img', () => { waterfall('.gallery-photos') })
window.Lately && Lately.init({ target: '.photo-time' })
}).catch()
}

HTML

lightbox2 需要引用 jquery.min.js 如果你的主题中有引用则可以无需再次引用

Copy











可以把以上 JS 和 CSS 保存在本地 并正确引用

说明

/api/v1/memo?creatorId=1&tag=照片其中 creatorId为用户 ID tag为关键标签 Memos 记录的格式为

Copy
#照片
![2019年的杨肸子](https://im.loliko.cn/media_attachments/files/111/645/919/415/226/504/original/fd739f9205423522.jpeg)

TAG 后面要有空格 这种写法只显示标题

Copy
![2023-11-13 夜景模式下的广州](https://im.loliko.cn/media_attachments/files/111/400/772/761/903/386/original/4d8894da79565a38.jpg)

这种写法可显示标题和日期

演示

https://blog.memos.ee/album

此文由 Mix Space 同步更新至 xLog
原始链接为 https://www.paimian.cn/posts/default/2024-01-29-%E7%94%B1Memos%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E7%9B%B8%E5%86%8C%E9%A1%B5%E9%9D%A2