Fixed showcase issue
Cleaned up bad unicode and control characters from snippet description
This commit is contained in:
parent
faa582f6da
commit
d01731f4cd
|
@ -297,6 +297,8 @@ func LinkToTemplate(link *models.Link) Link {
|
|||
return tlink
|
||||
}
|
||||
|
||||
var controlCharRegex = regexp.MustCompile(`\p{Cc}`)
|
||||
|
||||
func TimelineItemsToJSON(items []TimelineItem) string {
|
||||
// NOTE(asaf): As of 2021-06-22: This only serializes the data necessary for snippet showcase.
|
||||
builder := strings.Builder{}
|
||||
|
@ -314,11 +316,13 @@ func TimelineItemsToJSON(items []TimelineItem) string {
|
|||
|
||||
builder.WriteString(`"description":"`)
|
||||
jsonString := string(item.Description)
|
||||
jsonString = strings.ToValidUTF8(jsonString, "")
|
||||
jsonString = strings.ReplaceAll(jsonString, `\`, `\\`)
|
||||
jsonString = strings.ReplaceAll(jsonString, `"`, `\"`)
|
||||
jsonString = strings.ReplaceAll(jsonString, "\n", "\\n")
|
||||
jsonString = strings.ReplaceAll(jsonString, "\r", "\\r")
|
||||
jsonString = strings.ReplaceAll(jsonString, "\t", "\\t")
|
||||
jsonString = controlCharRegex.ReplaceAllString(jsonString, "")
|
||||
builder.WriteString(jsonString)
|
||||
builder.WriteString(`",`)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<a class="user" data-tmpl="userLink"></a>
|
||||
<a data-tmpl="date" class="datetime tr" style="flex: 1 1 auto;"></a>
|
||||
</div>
|
||||
<div data-tmpl="description">
|
||||
<div class="pre overflow-auto" data-tmpl="description">
|
||||
Unknown description
|
||||
</div>
|
||||
<div data-tmpl="tags" class="pt2 flex"></div>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<a class="user" href="{{ .Snippet.OwnerUrl }}">{{ .Snippet.OwnerName }}</a>
|
||||
<a class="tr" style="flex: 1 1 auto;" href="{{ .Snippet.Url }}">{{ timehtml (relativedate .Snippet.Date) .Snippet.Date }}</a>
|
||||
</div>
|
||||
<p class="mb2">{{ .Snippet.Description }}</p>
|
||||
<div class="pre overflow-auto mb2">{{ .Snippet.Description }}</div>
|
||||
<div>
|
||||
{{ range .Snippet.EmbedMedia }}
|
||||
{{ if eq .Type mediaimage }}
|
||||
|
|
Loading…
Reference in New Issue