新建相册页面

1
hexo new page photos

参照以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<div class="gallery-items">
<div class="gallery-photos"></div>
</div>

<script>
async function loadImages() {
try {
let url = 'https://memos.imsun.org' // 修改api 适用于memos版本小于0.22.0
let response = await fetch(url + '/api/v1/memo?creatorId=1&tag=照片'); //tag为#照片 用户id为1
let data = await response.json();
let html = '';
let 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 += `<figure class="gallery-group">
<a href='${img}' data-fancybox="gallery" data-caption="${title}"> <img data-grid-maintained-target="true" src='${img}' alt="Group Image Gallery" >
<figcaption><p> ${title}</p></figcaption> </a>
</figure>`
})

document.querySelector('.gallery-photos').innerHTML = html
} catch (error) {
console.error('Failed to load images:', error);
}
}

if (1) {
loadImages();
}
</script>

参照本站