feat: page content
This commit is contained in:
@@ -24,7 +24,7 @@ var ErrNotAnImage = errors.New("not an image")
|
||||
func (s *Service) getMime(path string) (mimeType string, err error) {
|
||||
info, err := s.fs.Stat(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("image file info could not be fetched")
|
||||
err = fmt.Errorf("image file info could not be fetched: %w", err)
|
||||
}
|
||||
|
||||
if mimer, ok := info.(interface{ ContentType() string }); ok {
|
||||
|
||||
@@ -4,7 +4,9 @@ import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func UIDFromPath(path string) (uid string, err error) {
|
||||
@@ -24,6 +26,12 @@ func UIDFromPath(path string) (uid string, err error) {
|
||||
return base64.RawURLEncoding.EncodeToString(b.Bytes()), nil
|
||||
}
|
||||
|
||||
func URLFromPath(path string) (url string, err error) {
|
||||
uid, err := UIDFromPath(path)
|
||||
url = "/images/" + uid
|
||||
return
|
||||
}
|
||||
|
||||
func PathFromUID(uid string) (string, error) {
|
||||
// 1. Decode the Base64 string back to compressed bytes
|
||||
compressedBytes, err := base64.RawURLEncoding.DecodeString(uid)
|
||||
@@ -45,3 +53,16 @@ func PathFromUID(uid string) (string, error) {
|
||||
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
func SourceSet(src string) string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
for i := range 19 {
|
||||
sb.WriteString(fmt.Sprintf("%s?w=%d %dw, ", src, 100*(i+1), 100*(i+1)))
|
||||
}
|
||||
|
||||
i := 20
|
||||
sb.WriteString(fmt.Sprintf("%s?w=%d %dw", src, 100*(i+1), 100*(i+1)))
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
Reference in New Issue
Block a user