Skip to content

Commit

Permalink
Merge pull request #196 from inovex/init-keep-description-once
Browse files Browse the repository at this point in the history
keepDescription: initialize bluemonday policy only once
  • Loading branch information
MichaelEischer authored Jan 7, 2025
2 parents e931025 + 8e91e91 commit 313a29a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/transformation/keepDescription.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ package transformation

import (
"strings"
"sync"

"github.com/aquilax/truncate"
"github.com/inovex/CalendarSync/internal/models"
"github.com/microcosm-cc/bluemonday"
)

// KeepDescription allows to keep the description of an event.
type KeepDescription struct{}
type KeepDescription struct {
policy *bluemonday.Policy
initPolicy sync.Once
}

func (t *KeepDescription) Name() string {
return "KeepDescription"
}

func (t *KeepDescription) Transform(source models.Event, sink models.Event) (models.Event, error) {
t.initPolicy.Do(func() {
t.policy = bluemonday.UGCPolicy()
})

// need to remove microsoft html overhead (the description in outlook contains a lot of '\r\n's)
p := bluemonday.UGCPolicy()
description := strings.ReplaceAll(source.Description, "\r\n", "")
sanitizedDescription := p.Sanitize(description)
sanitizedDescription := t.policy.Sanitize(description)
sanitizedDescription2 := strings.TrimSpace(sanitizedDescription)

// Since the description cannot exceed a specified amount in some sinks (e.g. google)
Expand Down

0 comments on commit 313a29a

Please sign in to comment.