summaryrefslogtreecommitdiff
path: root/internal/glightbox
diff options
from:
to:
context:
space:
mode:
authorGravatar Saya Andy <145215889+SayaAndy@users.noreply.github.com> 2026-03-30 02:13:49 +0700
committerGravatar GitHub <noreply@github.com> 2026-03-30 02:13:49 +0700
commit8d0385546b0a5f4f3b0832fce1b4c0a10fa0a927 (patch)
tree3be8adf291fecb7611adce3d5ed610f8ac832ca2 /internal/glightbox
parent56d333f3501cfc8e5725784e29ea917d347f37d8 (diff)
parent52fbb4a4eb781dd4ba66fae0e1ceaec6721758f5 (diff)
downloadweb-0.12.3.tar.gz
web-0.12.3.zip
v0.12.3 (#24)v0.12.3
* [feat: add meta for embeds & search engines](https://github.com/SayaAndy/saya-today-web/commit/610341bc9d59f9724e8e71f663b28df1904cb038) * feat: link marker fill saturation and brightness in the global map to the publication date * [feat: add namespace parameter for gallery](https://github.com/SayaAndy/saya-today-web/commit/52fbb4a4eb781dd4ba66fae0e1ceaec6721758f5) * refactor: replace sprintf for galleryid with simple replaceall in gallery rendering
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, 34 insertions, 27 deletions
diff --git a/internal/glightbox/block.go b/internal/glightbox/block.go
index e53e67b..30cda1c 100644
--- a/internal/glightbox/block.go
+++ b/internal/glightbox/block.go
@@ -9,8 +9,9 @@ import (
// GLightboxBlock represents a light gallery block in the AST
type GLightboxBlock struct {
ast.BaseBlock
- Images []GLightboxImage
- Location *time.Location
+ Images []GLightboxImage
+ Location *time.Location
+ Namespace string
}
type GLightboxImage struct {
diff --git a/internal/glightbox/html_renderer.go b/internal/glightbox/html_renderer.go
index b7b256a..ac34880 100644
--- a/internal/glightbox/html_renderer.go
+++ b/internal/glightbox/html_renderer.go
@@ -68,7 +68,8 @@ func (r *GLightboxHTMLRenderer) renderGLightbox(w util.BufWriter, source []byte,
var elements []string
for i, img := range gallery.Images {
- imageUrlSegments := strings.Split(img.URL, ".")
+ fullImageUrl := gallery.Namespace + img.URL
+ imageUrlSegments := strings.Split(fullImageUrl, ".")
imageUrlWithoutExt := strings.Join(imageUrlSegments[:len(imageUrlSegments)-1], ".")
imageUrlParts := strings.Split(imageUrlWithoutExt, "/")
imageNameParts := strings.Split(imageUrlParts[len(imageUrlParts)-1], "-")
@@ -122,7 +123,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>`, 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))
+ </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))
if glightboxDescId != "" {
elements = append(elements, fmt.Sprintf(`
@@ -132,43 +133,43 @@ func (r *GLightboxHTMLRenderer) renderGLightbox(w util.BufWriter, source []byte,
}
}
- w.WriteString(fmt.Sprintf(`
+ w.WriteString(strings.ReplaceAll(`
<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-%s">
- <div class="grid-sizer grid-sizer-%s"></div>
- %s
+ <div class="grid masonry-grid-{id}">
+ <div class="grid-sizer grid-sizer-{id}"></div>
+ `+strings.Join(elements, "\n")+`
</div>
<hr class="border-t-3 border-dotted border-main-hard mt-1 mb-2 w-[80%%] ml-auto mr-auto">
-</div>`, galleryID, galleryID, strings.Join(elements, "\n")))
+</div>
- w.WriteString(fmt.Sprintf(`
<script>
- var pckry_%s = new Packery('.masonry-grid-%s', {
- itemSelector: '.grid-item-%s',
- columnWidth: '.grid-sizer-%s',
+ var pckry_{id} = new Packery('.masonry-grid-{id}', {
+ itemSelector: '.grid-item-{id}',
+ columnWidth: '.grid-sizer-{id}',
percentPosition: false
});
- var imgLoad_%s_timer;
- var imgLoad_%s = imagesLoaded('.masonry-grid-%s');
+ var imgLoad_{id}_timer;
+ var imgLoad_{id} = imagesLoaded('.masonry-grid-{id}');
- function initMasonryLayout_%s(tm) {
- clearTimeout(imgLoad_%s_timer);
- imgLoad_%s_timer = setTimeout(() => pckry_%s.layout(), 100);
+ function initMasonryLayout_{id}(tm) {
+ clearTimeout(imgLoad_{id}_timer);
+ imgLoad_{id}_timer = setTimeout(() => pckry_{id}.layout(), 100);
}
- imgLoad_%s.on('progress', initMasonryLayout_%s);
+ imgLoad_{id}.on('progress', initMasonryLayout_{id});
- window.addEventListener('resize', initMasonryLayout_%s);
+ window.addEventListener('resize', initMasonryLayout_{id});
document.addEventListener('popout', (e) => {
- window.removeEventListener('resize', initMasonryLayout_%s);
- imgLoad_%s.off('progress', initMasonryLayout_%s);
- initMasonryLayout_%s = null;
- imgLoad_%s = null;
+ window.removeEventListener('resize', initMasonryLayout_{id});
+ imgLoad_{id}.off('progress', initMasonryLayout_{id});
+ initMasonryLayout_{id} = null;
+ imgLoad_{id} = null;
}, {once: true});
-</script>`, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID, galleryID))
+</script>
+`, "{id}", galleryID))
}
return ast.WalkContinue, nil
diff --git a/internal/glightbox/parser.go b/internal/glightbox/parser.go
index 6780090..b376034 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\+\-/]+)\}$`)
+ r := regexp.MustCompile(`^\{Gallery:([A-Za-z0-9\+\-/]+)(:([A-Za-z0-9\+\-/]+))?\}$`)
trimmed := bytes.TrimSpace(line)
parts := r.FindSubmatch(trimmed)
@@ -44,7 +44,12 @@ func (p *GLightboxParser) Open(parent ast.Node, reader text.Reader, pc parser.Co
return nil, parser.NoChildren
}
- return &GLightboxBlock{Location: loc}, parser.NoChildren
+ ns := ""
+ if len(parts) >= 4 {
+ ns = string(parts[3])
+ }
+
+ return &GLightboxBlock{Location: loc, Namespace: ns}, parser.NoChildren
}
func (p *GLightboxParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) parser.State {