summaryrefslogtreecommitdiff
path: root/internal/glightbox
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'internal/glightbox')
-rw-r--r--internal/glightbox/block.go5
-rw-r--r--internal/glightbox/html_renderer.go47
-rw-r--r--internal/glightbox/parser.go9
3 files changed, 27 insertions, 34 deletions
diff --git a/internal/glightbox/block.go b/internal/glightbox/block.go
index 30cda1c..e53e67b 100644
--- a/internal/glightbox/block.go
+++ b/internal/glightbox/block.go
@@ -9,9 +9,8 @@ import (
// GLightboxBlock represents a light gallery block in the AST
type GLightboxBlock struct {
ast.BaseBlock
- Images []GLightboxImage
- Location *time.Location
- Namespace string
+ Images []GLightboxImage
+ Location *time.Location
}
type GLightboxImage struct {
diff --git a/internal/glightbox/html_renderer.go b/internal/glightbox/html_renderer.go
index ac34880..b7b256a 100644
--- a/internal/glightbox/html_renderer.go
+++ b/internal/glightbox/html_renderer.go
@@ -68,8 +68,7 @@ func (r *GLightboxHTMLRenderer) renderGLightbox(w util.BufWriter, source []byte,
var elements []string
for i, img := range gallery.Images {
- fullImageUrl := gallery.Namespace + img.URL
- imageUrlSegments := strings.Split(fullImageUrl, ".")
+ imageUrlSegments := strings.Split(img.URL, ".")
imageUrlWithoutExt := strings.Join(imageUrlSegments[:len(imageUrlSegments)-1], ".")
imageUrlParts := strings.Split(imageUrlWithoutExt, "/")
imageNameParts := strings.Split(imageUrlParts[len(imageUrlParts)-1], "-")
@@ -123,7 +122,7 @@ func (r *GLightboxHTMLRenderer) renderGLightbox(w util.BufWriter, source []byte,
</picture>
<span class="grid-tooltip-text"><p>%s</p></span>
<span class="grid-item-index">%d</span>
- </a>`, fullImageUrl, strings.Join(tagClassList, " "), galleryID, dayDate.Format("2006-01-02 15:04:05 -07:00"), dataDescriptionAttribute, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, anchorlessCaptionHTML, i+1))
+ </a>`, img.URL, strings.Join(tagClassList, " "), galleryID, dayDate.Format("2006-01-02 15:04:05 -07:00"), dataDescriptionAttribute, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, imageUrlWithoutExt, anchorlessCaptionHTML, i+1))
if glightboxDescId != "" {
elements = append(elements, fmt.Sprintf(`
@@ -133,43 +132,43 @@ func (r *GLightboxHTMLRenderer) renderGLightbox(w util.BufWriter, source []byte,
}
}
- w.WriteString(strings.ReplaceAll(`
+ w.WriteString(fmt.Sprintf(`
<div class="items-center flex flex-col">
<hr class="border-t-3 border-dotted border-main-hard mt-1 mb-2 w-[80%%] ml-auto mr-auto">
- <div class="grid masonry-grid-{id}">
- <div class="grid-sizer grid-sizer-{id}"></div>
- `+strings.Join(elements, "\n")+`
+ <div class="grid masonry-grid-%s">
+ <div class="grid-sizer grid-sizer-%s"></div>
+ %s
</div>
<hr class="border-t-3 border-dotted border-main-hard mt-1 mb-2 w-[80%%] ml-auto mr-auto">
-</div>
+</div>`, galleryID, galleryID, strings.Join(elements, "\n")))
+ w.WriteString(fmt.Sprintf(`
<script>
- var pckry_{id} = new Packery('.masonry-grid-{id}', {
- itemSelector: '.grid-item-{id}',
- columnWidth: '.grid-sizer-{id}',
+ var pckry_%s = new Packery('.masonry-grid-%s', {
+ itemSelector: '.grid-item-%s',
+ columnWidth: '.grid-sizer-%s',
percentPosition: false
});
- var imgLoad_{id}_timer;
- var imgLoad_{id} = imagesLoaded('.masonry-grid-{id}');
+ var imgLoad_%s_timer;
+ var imgLoad_%s = imagesLoaded('.masonry-grid-%s');
- function initMasonryLayout_{id}(tm) {
- clearTimeout(imgLoad_{id}_timer);
- imgLoad_{id}_timer = setTimeout(() => pckry_{id}.layout(), 100);
+ function initMasonryLayout_%s(tm) {
+ clearTimeout(imgLoad_%s_timer);
+ imgLoad_%s_timer = setTimeout(() => pckry_%s.layout(), 100);
}
- imgLoad_{id}.on('progress', initMasonryLayout_{id});
+ imgLoad_%s.on('progress', initMasonryLayout_%s);
- window.addEventListener('resize', initMasonryLayout_{id});
+ window.addEventListener('resize', initMasonryLayout_%s);
document.addEventListener('popout', (e) => {
- window.removeEventListener('resize', initMasonryLayout_{id});
- imgLoad_{id}.off('progress', initMasonryLayout_{id});
- initMasonryLayout_{id} = null;
- imgLoad_{id} = null;
+ window.removeEventListener('resize', initMasonryLayout_%s);
+ imgLoad_%s.off('progress', initMasonryLayout_%s);
+ initMasonryLayout_%s = null;
+ imgLoad_%s = null;
}, {once: true});
-</script>
-`, "{id}", galleryID))
+</script>`, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID))
}
return ast.WalkContinue, nil
diff --git a/internal/glightbox/parser.go b/internal/glightbox/parser.go
index b376034..6780090 100644
--- a/internal/glightbox/parser.go
+++ b/internal/glightbox/parser.go
@@ -29,7 +29,7 @@ func (p *GLightboxParser) Open(parent ast.Node, reader text.Reader, pc parser.Co
return nil, parser.NoChildren
}
- r := regexp.MustCompile(`^\{Gallery:([A-Za-z0-9\+\-/]+)(:([A-Za-z0-9\+\-/]+))?\}$`)
+ r := regexp.MustCompile(`^\{Gallery:([A-Za-z0-9\+\-/]+)\}$`)
trimmed := bytes.TrimSpace(line)
parts := r.FindSubmatch(trimmed)
@@ -44,12 +44,7 @@ func (p *GLightboxParser) Open(parent ast.Node, reader text.Reader, pc parser.Co
return nil, parser.NoChildren
}
- ns := ""
- if len(parts) >= 4 {
- ns = string(parts[3])
- }
-
- return &GLightboxBlock{Location: loc, Namespace: ns}, parser.NoChildren
+ return &GLightboxBlock{Location: loc}, parser.NoChildren
}
func (p *GLightboxParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) parser.State {