Name the revision in the Improve this page labelUnverified
The link already pointed at the revision the page was rendered from, but nothing said so - the reader had to hover it, or read the status bar, to see which source they were about to be shown. Print the short hash after the label, as fzakaria.com does: "Improve this page @ 694d415". The hash sits outside the translated string. It is a separator and seven hex characters, the same in every language, and leaving it in the template keeps the five i18n files from each carrying a copy of the markup. A `hugo server` or dirty-tree build has no revision and falls back to the branch name, which still resolves in the href but reads as noise in a label, so the "@ ..." is dropped and the label stands alone.
c1f6370 parent: a823897 modified
blog/layouts/partials/site-foot.html +14 -5 | @@ -1,14 +1,23 @@ | ||
| 1 | 1 | <footer class="site-foot column"> |
| 2 | 2 | {{- /* |
| 3 | - Source link for the page you are reading, pointing at the very revision the | |
| 4 | - site was built from (site.Params.repoCommit, see hugo.toml). Pages Hugo | |
| 5 | - generates without a content file - the home page, the post list - have no | |
| 6 | - .File, and get no link. | |
| 3 | + The revision the site was built from (site.Params.repoCommit, see | |
| 4 | + hugo.toml). It falls back to a branch name when there is no revision to | |
| 5 | + name - `hugo server`, or a build over a dirty tree - which still resolves | |
| 6 | + in the link below but is nothing to print, so only a real 40-character | |
| 7 | + hash is shown. | |
| 8 | + */}} | |
| 9 | + {{- $rev := site.Params.repoCommit }} | |
| 10 | + {{- $builtFrom := eq (len $rev) 40 }} | |
| 11 | + {{- /* | |
| 12 | + Source link for the page you are reading, pointing at that revision rather | |
| 13 | + than at the branch, so it shows the source this very page was rendered | |
| 14 | + from. Pages Hugo generates without a content file - the home page, the post | |
| 15 | + list - have no .File, and get no link. | |
| 7 | 16 | */}} |
| 8 | 17 | {{- with .File }} |
| 9 | 18 | {{- $source := path.Join site.Params.repoContentPath .Path }} |
| 10 | 19 | <span> |
| 11 | - <a href="{{ printf "%s/blob/%s/%s" site.Params.repoURL site.Params.repoCommit $source }}">{{ i18n "improvePage" }}</a> | |
| 20 | + <a href="{{ printf "%s/blob/%s/%s" site.Params.repoURL $rev $source }}">{{ i18n "improvePage" }}{{ if $builtFrom }} @ {{ substr $rev 0 7 }}{{ end }}</a> | |
| 12 | 21 | </span> |
| 13 | 22 | <span class="sep" aria-hidden="true">·</span> |
| 14 | 23 | {{- end }} |
| @@ -1,14 +1,23 @@ | |||
| 1 | <footer class="site-foot column"> | 1 | <footer class="site-foot column"> |
| 2 | {{- /* | 2 | {{- /* |
| 3 | - Source link for the page you are reading, pointing at the very revision the | 3 | + The revision the site was built from (site.Params.repoCommit, see |
| 4 | - site was built from (site.Params.repoCommit, see hugo.toml). Pages Hugo | 4 | + hugo.toml). It falls back to a branch name when there is no revision to |
| 5 | - generates without a content file - the home page, the post list - have no | 5 | + name - `hugo server`, or a build over a dirty tree - which still resolves |
| 6 | - .File, and get no link. | 6 | + in the link below but is nothing to print, so only a real 40-character |
| 7 | + hash is shown. | ||
| 8 | + */}} | ||
| 9 | + {{- $rev := site.Params.repoCommit }} | ||
| 10 | + {{- $builtFrom := eq (len $rev) 40 }} | ||
| 11 | + {{- /* | ||
| 12 | + Source link for the page you are reading, pointing at that revision rather | ||
| 13 | + than at the branch, so it shows the source this very page was rendered | ||
| 14 | + from. Pages Hugo generates without a content file - the home page, the post | ||
| 15 | + list - have no .File, and get no link. | ||
| 7 | */}} | 16 | */}} |
| 8 | {{- with .File }} | 17 | {{- with .File }} |
| 9 | {{- $source := path.Join site.Params.repoContentPath .Path }} | 18 | {{- $source := path.Join site.Params.repoContentPath .Path }} |
| 10 | <span> | 19 | <span> |
| 11 | - <a href="{{ printf "%s/blob/%s/%s" site.Params.repoURL site.Params.repoCommit $source }}">{{ i18n "improvePage" }}</a> | 20 | + <a href="{{ printf "%s/blob/%s/%s" site.Params.repoURL $rev $source }}">{{ i18n "improvePage" }}{{ if $builtFrom }} @ {{ substr $rev 0 7 }}{{ end }}</a> |
| 12 | </span> | 21 | </span> |
| 13 | <span class="sep" aria-hidden="true">·</span> | 22 | <span class="sep" aria-hidden="true">·</span> |
| 14 | {{- end }} | 23 | {{- end }} |