Hugo博客添加相册功能

2023-03-27 10:20:06 浏览数 (1)

1. 插件介绍

我采用的是nanogallery2这个插件,里面有具体的配置文档: Titlenanogallery2用法指导

2. shortchodes配置

layouts/shortcodes下面添加两个文件:gallery.html和galleries.html,其中gallery.html里面放入如下代码:

代码语言:javascript复制
<a href="{{ .Get "src" }}" data-ngThumb="{{ .Get "src" }}">{{ .Get "title" }}</a>

在galleries.html里面放入如下代码:

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nanogallery2@3.0.5/dist/css/nanogallery2.min.css">
    <script src="https://cdn.jsdelivr.net/npm/nanogallery2@3.0.5/dist/jquery.nanogallery2.min.js"></script>
</head>
<body>

<div data-nanogallery2='{
	 "thumbnailDisplayTransition":          "none",
     "thumbnailDisplayTransitionDuration":  500,
     "thumbnailDisplayInterval":            30,
     "galleryDisplayTransition":            "none",
     "galleryDisplayTransitionDuration":    500,
     "galleryDisplayMode": "rows",
     "thumbnailDisplayOutsideScreen": "false",
     "eventsDebounceDelay": 10,
     "thumbnailL1BorderHorizontal": 0,
     "thumbnailL1BorderVertical": 0,
     "thumbnailLabel": {
        "titleFontSize": "0.6em"
     },
     "thumbnailHoverEffect2": "image_scale_1.00_1.10|label_backgroundColor_rgba(0,0,0,0)_rgba(255,255,255,0)",
     "galleryTheme": {
        "thumbnail": {
            "borderRadius": "8px"
        }
     },
     "thumbnailToolbarImage": {
        "topLeft": "",
        "topRight": "",
        "bottomLeft": "",
        "bottomRight": ""
     },
     "viewerToolbar":   {
        "display": true,
        "standard": "label"
     },
     "viewerTools":     {
        "topLeft":    "pageCounter, playPauseButton",
        "topRight":   "downloadButton, rotateLeft, zoomButton, fullscreenButton, closeButton"
     },
     "viewerGalleryTWidth": 40,
     "viewerGalleryTHeight": 40
}'>
    {{ .Inner }}
</div>
</body>
</html>

data-nanogallery2里面的配置可以在官方文档查看各种配置方法,调整出合适自己的样式,也可以直接使用我已经配置好的。

3. 使用方法

代码语言:javascript复制
[comment]: <> 使用的时候把前面的a去掉
{a{< galleries >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/q4ban2nqnmb.png" title="香克斯">}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/2zzedptkzlg.png" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/nmiwuoaqs40.png" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/q4ban2nqnmb.png" title="香克斯" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/2zzedptkzlg.png" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/nmiwuoaqs40.png" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/q4ban2nqnmb.png" title="香克斯" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/2zzedptkzlg.png" >}}
{a{< gallery src="https://img.yuanmabao.com/zijie/pic/2023/03/27/nmiwuoaqs40.png" >}}
{a{< /galleries >}}

0 人点赞