利用 hugo 的 partial template

layouts/partials/backlinks.html

{{ $re := $.File.BaseFileName }}
{{ $backlinks := slice }}
{{ range .Site.AllPages }}
   {{ if and (findRE $re .RawContent) (not (eq $re .File.BaseFileName)) }}
	  {{ $backlinks = $backlinks | append . }}
   {{ end }}
{{ end }}

<hr>
{{ if gt (len $backlinks) 0 }}
  <div class="bl-section">
	<h4>Links to this note</h4>
	<div class="backlinks">
	  <ul>
	   {{ range $backlinks }}
		  <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
	   {{ end }}
	 </ul>
	</div>
  </div>
{{ else  }}
  <div class="bl-section">
	<h4>No notes link to this note</h4>
  </div>
{{ end }}

然后插入到的 single.html 就行

{{ partial "backlinks.html" . }}

hugo-theme-terminal

放在项目的 layouts/partials/comments.html 中避免污染模版。