Skip to content

Commit

Permalink
add optional author field
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed Jun 8, 2023
1 parent cc88ceb commit a62749c
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Differences in docker version

Create note

curl -v -F title=hello -F text=world -F attachment=@somefile.pdf http://127.0.0.1:8080/notes?token=deadbeaf
curl -v -F author=reddec -F title=hello -F text=world -F attachment=@somefile.pdf http://127.0.0.1:8080/notes?token=deadbeaf


## Sample note
Expand Down
32 changes: 32 additions & 0 deletions api/client/oas_request_encoders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions api/client/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion internal/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ type Renderer struct {
engine goldmark.Markdown
}

func (r *Renderer) Render(title, content string, attachments []string) ([]byte, error) {
func (r *Renderer) Render(title, content string, author string, attachments []string) ([]byte, error) {
var out bytes.Buffer
if err := r.engine.Convert([]byte(content), &out); err != nil {
return nil, fmt.Errorf("render: %w", err)
}
vd := &viewData{
Title: title,
Author: author,
Style: template.CSS(style),
HTML: template.HTML(out.String()),
Attachments: attachments,
Expand All @@ -71,6 +72,7 @@ func (r *Renderer) Render(title, content string, attachments []string) ([]byte,

type viewData struct {
Title string
Author string
Attachments []string
Style template.CSS
HTML template.HTML
Expand Down
7 changes: 6 additions & 1 deletion internal/render/template.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
</article>
{{- end}}
<footer>
<p>{{now.UTC.Format "02 Jan 2006 15:04:05"}} UTC</p>
<p>
{{now.UTC.Format "02 Jan 2006 15:04:05"}} UTC
{{- with .Author}}
&copy; {{.}}
{{- end}}
</p>
</footer>
</main>
</body>
Expand Down
64 changes: 64 additions & 0 deletions internal/server/api/oas_request_decoders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions internal/server/api/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/server/impl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (srv *Server) storeNote(ctx context.Context, req *api.DraftMultipart, id st
attachments = append(attachments, name.Name)
}
}
html, err := srv.Renderer.Render(req.Title, req.Text, attachments)
html, err := srv.Renderer.Render(req.Title, req.Text, req.Author.Value, attachments)
if err != nil {
return fmt.Errorf("render HTML: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ components:
type: string
description: Note body
example: This is long text
author:
type: string
description: Optional (and not verifiable) author of note
example: RedDec
hide_attachments:
type: boolean
default: false
Expand Down

0 comments on commit a62749c

Please sign in to comment.