From 2d727cc1eeb926f5b5ee578a0ee54269e0390a96 Mon Sep 17 00:00:00 2001 From: SayaAndy Date: Sat, 2 May 2026 12:58:40 +0700 Subject: refactor: parametrize static & photo storage url refactor: parametrize allow origins --- internal/glightbox/html_renderer.go | 42 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'internal/glightbox/html_renderer.go') diff --git a/internal/glightbox/html_renderer.go b/internal/glightbox/html_renderer.go index f71a8f2..b2cd855 100644 --- a/internal/glightbox/html_renderer.go +++ b/internal/glightbox/html_renderer.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/SayaAndy/saya-today-web/config" "github.com/SayaAndy/saya-today-web/internal/tailwind" "github.com/yuin/goldmark" "github.com/yuin/goldmark/ast" @@ -21,9 +22,10 @@ type GLightboxHTMLRenderer struct { html.Config md goldmark.Markdown anchorMatchRe *regexp.Regexp + photoStorage config.PhotoStorageConfig } -func NewGLightboxHTMLRenderer(opts ...html.Option) renderer.NodeRenderer { +func NewGLightboxHTMLRenderer(photoStorage config.PhotoStorageConfig, opts ...html.Option) renderer.NodeRenderer { r := &GLightboxHTMLRenderer{ Config: html.NewConfig(), md: goldmark.New( @@ -44,11 +46,12 @@ func NewGLightboxHTMLRenderer(opts ...html.Option) renderer.NodeRenderer { ), ), ), + anchorMatchRe: regexp.MustCompile(`(?s)<\s*a(\s+[^<]*)(href\s*=\s*["'].*?["'])\s*([^<]*)>(.*?)<\s*\/\s*a\s*>`), + photoStorage: photoStorage, } for _, opt := range opts { opt.SetHTMLOption(&r.Config) } - r.anchorMatchRe = regexp.MustCompile(`(?s)<\s*a(\s+[^<]*)(href\s*=\s*["'].*?["'])\s*([^<]*)>(.*?)<\s*\/\s*a\s*>`) return r } @@ -111,19 +114,32 @@ func (r *GLightboxHTMLRenderer) renderGLightbox(w util.BufWriter, source []byte, anchorlessCaptionHTML := r.anchorMatchRe.ReplaceAll(captionHTML, []byte("$4")) elements = append(elements, fmt.Sprintf(` - + - - - - - - + + + + + + -

%s

- %d -
`, 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)) +

%[5]s

+ %[6]d + `, + strings.Join(tagClassList, " "), + galleryID, + dayDate.Format("2006-01-02 15:04:05 -07:00"), + dataDescriptionAttribute, + anchorlessCaptionHTML, + i+1, + fmt.Sprintf(r.photoStorage.Full.BaseUrl, fullImageUrl), + fmt.Sprintf(r.photoStorage.Thumbnail1600p.BaseUrl, imageUrlWithoutExt), + fmt.Sprintf(r.photoStorage.Thumbnail1200p.BaseUrl, imageUrlWithoutExt), + fmt.Sprintf(r.photoStorage.Thumbnail800p.BaseUrl, imageUrlWithoutExt), + fmt.Sprintf(r.photoStorage.Thumbnail560p.BaseUrl, imageUrlWithoutExt), + fmt.Sprintf(r.photoStorage.Thumbnail320p.BaseUrl, imageUrlWithoutExt), + )) if glightboxDescId != "" { elements = append(elements, fmt.Sprintf(` -- cgit v1.3.1+13