summaryrefslogtreecommitdiff
path: root/internal/lightgallery
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'internal/lightgallery')
-rw-r--r--internal/lightgallery/block.go9
-rw-r--r--internal/lightgallery/html_renderer.go15
-rw-r--r--internal/lightgallery/parser.go19
3 files changed, 31 insertions, 12 deletions
diff --git a/internal/lightgallery/block.go b/internal/lightgallery/block.go
index dade2ea..072aa3c 100644
--- a/internal/lightgallery/block.go
+++ b/internal/lightgallery/block.go
@@ -1,11 +1,16 @@
package lightgallery
-import "github.com/yuin/goldmark/ast"
+import (
+ "time"
+
+ "github.com/yuin/goldmark/ast"
+)
// LightGalleryBlock represents a light gallery block in the AST
type LightGalleryBlock struct {
ast.BaseBlock
- Images []LightGalleryImage
+ Images []LightGalleryImage
+ Location *time.Location
}
type LightGalleryImage struct {
diff --git a/internal/lightgallery/html_renderer.go b/internal/lightgallery/html_renderer.go
index fb65b06..77b9785 100644
--- a/internal/lightgallery/html_renderer.go
+++ b/internal/lightgallery/html_renderer.go
@@ -38,13 +38,13 @@ func (r *LightGalleryHTMLRenderer) renderLightGallery(w util.BufWriter, source [
return ast.WalkContinue, nil
}
- galleryID := generateDivId(4)
+ galleryID := generateDivId(8)
w.WriteString(fmt.Sprintf(`
<div class="justify-content-center display-block m-2">
- <hr class="border-t-4 border-dotted border-main-dark mt-vmin0-8 mb-vmin0-8 w-p80 ml-auto mr-auto">
+ <hr class="border-t-4 border-dotted border-main-dark mt-[0.8vmin] mb-[0.8vmin] w-[80%%] ml-auto mr-auto">
<div id="lg-%s" class="inline-gallery-container relative ml-auto mr-auto"></div>
- <hr class="border-t-4 border-dotted border-main-dark mt-vmin0-8 mb-vmin0-8 w-p80 ml-auto mr-auto">
+ <hr class="border-t-4 border-dotted border-main-dark mt-[0.8vmin] mb-[0.8vmin] w-[80%%] ml-auto mr-auto">
</div>`, galleryID))
var dynamicElements []string
@@ -54,6 +54,7 @@ func (r *LightGalleryHTMLRenderer) renderLightGallery(w util.BufWriter, source [
imageNameParts := strings.Split(imageUrlWithoutExt, "-")
dayDate, _ := time.Parse("20060102 150405", imageNameParts[len(imageNameParts)-2]+" "+imageNameParts[len(imageNameParts)-1])
+ dayDate = dayDate.In(gallery.Location)
dynamicElements = append(dynamicElements, fmt.Sprintf(`{
src:
"https://f003.backblazeb2.com/file/sayana-photos/full/%s",
@@ -67,10 +68,10 @@ func (r *LightGalleryHTMLRenderer) renderLightGallery(w util.BufWriter, source [
thumb:
"https://f003.backblazeb2.com/file/sayana-photos/thumbnails/%s.webp",
subHtml: `+"`"+`<div class="flex flex-row light-gallery-captions">
- <p class="grow text-vmax1 text-left lh-0-9 font-spectral text-main-dark">%s</p>
- <p class="text-vmax1 text-right lh-0-9 font-spectral text-secondary">%s</p>
+ <p class="grow !text-[1vmax]/[0.9] text-left font-spectral text-main-dark">%s</p>
+ <p class="!text-[1vmax]/[0.9] text-right font-spectral text-secondary">%s</p>
</div>`+"`"+`
- }`, img.URL, img.URL, img.Caption, imageUrlWithoutExt, imageUrlWithoutExt, img.Caption, dayDate.Format("2006-01-02 15:04:05 -07:00")))
+ }`, img.URL, img.URL, escapeHTML(img.Caption), imageUrlWithoutExt, imageUrlWithoutExt, escapeHTML(img.Caption), dayDate.Format("2006-01-02 15:04:05 -07:00")))
}
w.WriteString(fmt.Sprintf(`
@@ -87,7 +88,7 @@ function createLightLibrary%s() {
closable: false,
showMaximizeIcon: true,
appendSubHtmlTo: ".lg-sub-html",
- isMobile: () => { return false; },
+ isMobile: () => false,
slideDelay: 0,
plugins: [lgZoom, lgThumbnail],
thumbWidth: 160,
diff --git a/internal/lightgallery/parser.go b/internal/lightgallery/parser.go
index 0ce209c..bd7483a 100644
--- a/internal/lightgallery/parser.go
+++ b/internal/lightgallery/parser.go
@@ -2,7 +2,10 @@ package lightgallery
import (
"bytes"
+ "log/slog"
+ "regexp"
"strings"
+ "time"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/parser"
@@ -22,16 +25,26 @@ func (p *LightGalleryParser) Trigger() []byte {
func (p *LightGalleryParser) Open(parent ast.Node, reader text.Reader, pc parser.Context) (ast.Node, parser.State) {
line, _ := reader.PeekLine()
- if !bytes.HasPrefix(line, []byte("{Gallery}")) {
+ if !bytes.HasPrefix(line, []byte("{Gallery")) {
return nil, parser.NoChildren
}
+ r := regexp.MustCompile(`^\{Gallery:([A-Za-z0-9\+\-/]+)\}$`)
+
trimmed := bytes.TrimSpace(line)
- if !bytes.Equal(trimmed, []byte("{Gallery}")) {
+ parts := r.FindSubmatch(trimmed)
+ if len(parts) < 2 {
+ slog.Warn("invalid gallery header format", slog.String("line", string(trimmed)), slog.Int("submatch_count", len(parts)))
+ return nil, parser.NoChildren
+ }
+
+ loc, err := time.LoadLocation(string(parts[1]))
+ if err != nil {
+ slog.Warn("invalid location specified for a gallery", slog.String("error", err.Error()), slog.String("line", string(trimmed)), slog.String("location", string(parts[1])))
return nil, parser.NoChildren
}
- return &LightGalleryBlock{}, parser.NoChildren
+ return &LightGalleryBlock{Location: loc}, parser.NoChildren
}
func (p *LightGalleryParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) parser.State {