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
|
return tlink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var controlCharRegex = regexp.MustCompile(`\p{Cc}`)
|
||||||
|
|
||||||
func TimelineItemsToJSON(items []TimelineItem) string {
|
func TimelineItemsToJSON(items []TimelineItem) string {
|
||||||
// NOTE(asaf): As of 2021-06-22: This only serializes the data necessary for snippet showcase.
|
// NOTE(asaf): As of 2021-06-22: This only serializes the data necessary for snippet showcase.
|
||||||
builder := strings.Builder{}
|
builder := strings.Builder{}
|
||||||
|
@ -314,11 +316,13 @@ func TimelineItemsToJSON(items []TimelineItem) string {
|
||||||
|
|
||||||
builder.WriteString(`"description":"`)
|
builder.WriteString(`"description":"`)
|
||||||
jsonString := string(item.Description)
|
jsonString := string(item.Description)
|
||||||
|
jsonString = strings.ToValidUTF8(jsonString, "")
|
||||||
jsonString = strings.ReplaceAll(jsonString, `\`, `\\`)
|
jsonString = strings.ReplaceAll(jsonString, `\`, `\\`)
|
||||||
jsonString = strings.ReplaceAll(jsonString, `"`, `\"`)
|
jsonString = strings.ReplaceAll(jsonString, `"`, `\"`)
|
||||||
jsonString = strings.ReplaceAll(jsonString, "\n", "\\n")
|
jsonString = strings.ReplaceAll(jsonString, "\n", "\\n")
|
||||||
jsonString = strings.ReplaceAll(jsonString, "\r", "\\r")
|
jsonString = strings.ReplaceAll(jsonString, "\r", "\\r")
|
||||||
jsonString = strings.ReplaceAll(jsonString, "\t", "\\t")
|
jsonString = strings.ReplaceAll(jsonString, "\t", "\\t")
|
||||||
|
jsonString = controlCharRegex.ReplaceAllString(jsonString, "")
|
||||||
builder.WriteString(jsonString)
|
builder.WriteString(jsonString)
|
||||||
builder.WriteString(`",`)
|
builder.WriteString(`",`)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<a class="user" data-tmpl="userLink"></a>
|
<a class="user" data-tmpl="userLink"></a>
|
||||||
<a data-tmpl="date" class="datetime tr" style="flex: 1 1 auto;"></a>
|
<a data-tmpl="date" class="datetime tr" style="flex: 1 1 auto;"></a>
|
||||||
</div>
|
</div>
|
||||||
<div data-tmpl="description">
|
<div class="pre overflow-auto" data-tmpl="description">
|
||||||
Unknown description
|
Unknown description
|
||||||
</div>
|
</div>
|
||||||
<div data-tmpl="tags" class="pt2 flex"></div>
|
<div data-tmpl="tags" class="pt2 flex"></div>
|
||||||
|
@ -42,4 +42,4 @@
|
||||||
|
|
||||||
<template id="timeline_item_tag">
|
<template id="timeline_item_tag">
|
||||||
<div data-tmpl="tag" class="bg-theme-dimmer ph2 pv1 br2"></div>
|
<div data-tmpl="tag" class="bg-theme-dimmer ph2 pv1 br2"></div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<a class="user" href="{{ .Snippet.OwnerUrl }}">{{ .Snippet.OwnerName }}</a>
|
<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>
|
<a class="tr" style="flex: 1 1 auto;" href="{{ .Snippet.Url }}">{{ timehtml (relativedate .Snippet.Date) .Snippet.Date }}</a>
|
||||||
</div>
|
</div>
|
||||||
<p class="mb2">{{ .Snippet.Description }}</p>
|
<div class="pre overflow-auto mb2">{{ .Snippet.Description }}</div>
|
||||||
<div>
|
<div>
|
||||||
{{ range .Snippet.EmbedMedia }}
|
{{ range .Snippet.EmbedMedia }}
|
||||||
{{ if eq .Type mediaimage }}
|
{{ if eq .Type mediaimage }}
|
||||||
|
|
Loading…
Reference in New Issue