I have some content (tweets imports) with title and content very similar; how can I hide the title when it is very similar (more than 90% the same characters as the content) ?
(I have a LOT of tweets, I could re-import them and rewrite them, but this looks like a lot of work)
{{ define "main" }}
{{- $lenTitle := float (len .Title) -}}
{{- $lenContent := float (len (chomp .RawContent)) -}}
{{- $ratioLen := div $lenTitle $lenContent -}}
{{- $ratioThreshold := 0.90 -}}
{{- if (not (in (lower .Content) (lower .Title))) }}
<h1>{{ .Title }}</h1>
{{- else -}}
{{- if lt $ratioLen $ratioThreshold }}
<h1>{{ .Title }}</h1>
{{- end -}}
{{- end }}
{{ .Content }}
<!-- Remove this div when you're done testing. -->
<div style="color: green;">
The title is {{ $lenTitle }} characters long.<br>
The content is {{ $lenContent }} characters long.<br>
The ratio of title length to content length is {{ printf "%3.1f%%" (mul 100 $ratioLen) }}.<br>
The defined threshold ratio is {{ printf "%3.1f%%" (mul 100 $ratioThreshold) }}.<br>
{{- if in (lower .Content) (lower .Title) }}
The title appears within the content.<br>
{{- else }}
The title does not appear within the content.<br>
{{- end -}}
{{- if lt $ratioLen $ratioThreshold }}
The ratio of title length to content length is less than the threshold ratio.
{{- else }}
The ratio of title length to content length is greater than or equal ot the threshold ratio.
{{- end }}
</div>
{{ end }}