a1c6b89740
The fetchData function suffer from a race condition. If the function is called before the promise finishes, it will result in another pair of HTTP request. This does not only make the function useless but Actually, it makes it harmful as the data might be redownloaded twice. Now fetchData is not a function but rather the promise by itself. Previous callers are expected to await the variable instead, this should be not concern as awaiting a promise multiple time in JavaScript is completely safe.
22 lines
773 B
HTML
22 lines
773 B
HTML
<h3>Backlinks</h3>
|
|
<ul class="backlinks">
|
|
{{$url := urls.Parse .Site.BaseURL }}
|
|
{{$host := strings.TrimRight "/" $url.Path }}
|
|
{{$curPage := strings.TrimPrefix $host (strings.TrimRight "/" .Page.RelPermalink) }}
|
|
{{$linkIndex := getJSON "/assets/indices/linkIndex.json"}}
|
|
{{$inbound := index $linkIndex.index.backlinks $curPage}}
|
|
{{$contentTable := getJSON "/assets/indices/contentIndex.json"}}
|
|
{{if $inbound}}
|
|
{{$cleanedInbound := apply (apply $inbound "index" "." "source") "replace" "." " " "-"}}
|
|
{{- range $cleanedInbound | uniq -}}
|
|
<li>
|
|
<a href="{{$url}}{{.}}">{{index (index $contentTable .) "title"}}</a>
|
|
</li>
|
|
{{- end -}}
|
|
{{else}}
|
|
<li>
|
|
No backlinks found
|
|
</li>
|
|
{{end}}
|
|
</ul>
|