feat: page content
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package page
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
@@ -62,12 +59,12 @@ func (s *Service) getPageHeaders(ctx context.Context, uid string) (page PageHead
|
||||
|
||||
slog.Debug("loaded page infos", "cover", coverImage, "content", contentMD)
|
||||
|
||||
content, err := s.fs.Read(contentMD.Path())
|
||||
page.md, err = s.fs.Read(contentMD.Path())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
title := titleRGX.FindStringSubmatch(string(content))
|
||||
title := titleRGX.FindStringSubmatch(string(page.md))
|
||||
if len(title) < 2 {
|
||||
err = fmt.Errorf("%w: no matches for title", ErrMalFormedInput)
|
||||
return
|
||||
@@ -81,14 +78,3 @@ func (s *Service) getPageHeaders(ctx context.Context, uid string) (page PageHead
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getImageUID(path string) string {
|
||||
var b bytes.Buffer
|
||||
// NewWriter with NoDict (nil) creates a raw DEFLATE compressor
|
||||
zw, _ := flate.NewWriter(&b, flate.BestCompression)
|
||||
|
||||
zw.Write([]byte(path))
|
||||
zw.Close() // Essential to flush the final bits
|
||||
|
||||
return base64.RawURLEncoding.EncodeToString(b.Bytes())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user