Add shortcode from live site for readfile example in local files template

This commit is contained in:
Ryan Watters 2017-02-19 02:12:33 -06:00
parent 4e159ed50c
commit ed70c14a2b
3 changed files with 27 additions and 9 deletions

View File

@ -2,6 +2,7 @@
title: Local File Templates
linktitle: Local File Templates
description:
godocref: https://golang.org/pkg/os/#FileInfo
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
@ -45,16 +46,20 @@ So, let's create a new shortcode using `readDir`:
For the files in any given directory, this shortcode usefully lists their basenames and sizes, while providing links to them.
Already—actually—this shortcode
has been included in this very web site.
So, let's list some of its CSS files.
(If you click on their names, you can reveal the contents.)
{{</* directoryindex path="/static/css" pathURL="/css" */>}}
This shortcode [has already been included in this very web site][].
So, let's list some of its CSS files. (If you click on their names, you can reveal the contents.)
{{< directoryindex path="/static/css" pathURL="/css" >}}
<br />
This is the call that rendered the above output:
```html
{{</* directoryindex path="/static/css" pathURL="/css" */>}}
```
By the way,
regarding the pathURL argument, the initial slash `/` is important.
Otherwise, it becomes relative to the current web page.
{{% note "Slashes are Important" %}}
The initial slash `/` in `pathURL` is important. Otherwise, `pathURL` becomes relative to the current web page.
{{% /note %}}
[has already been included in this very web site]: https://github.com/spf13/hugo/blob/master/docs/layouts/shortcodes/directoryindex.html

View File

@ -0,0 +1,13 @@
{{- $pathURL := .Get "pathURL" -}}
{{- $path := .Get "path" -}}
{{- $files := readDir $path -}}
<table>
<th>Size in bytes</th>
<th>Name</th>
{{- range $files }}
<tr>
<td>{{ .Size }}</td>
<td><a href="{{ $pathURL }}{{ .Name | relURL }}"> {{ .Name }}</a></td>
</tr>
{{- end }}
</table>

View File

@ -1,7 +1,7 @@
<footer id="site-footer" class="site-footer{{if .Params.toc}} withtoc{{end}}">
<div class="footer-content">
<div class="footer-info">
<span>By <a href="//spf13.com" target="_blank">spf13</a> and friends.</span>
<span>By <a href="http://spf13.com" target="_blank">spf13</a> and friends.</span>
<img src="{{ "images/hugo-logo/made-with-hugo-dark.png" | relURL}}" alt="Made with Hugo Logo">
</div>
<div>