From ed70c14a2b562107a7b30142598211c53cd6c525 Mon Sep 17 00:00:00 2001 From: Ryan Watters Date: Sun, 19 Feb 2017 02:12:33 -0600 Subject: [PATCH] Add shortcode from live site for readfile example in local files template --- content/templates/local-file-templates.md | 21 ++++++++++++------- layouts/shortcodes/directoryindex.html | 13 ++++++++++++ .../layouts/partials/site-footer.html | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 layouts/shortcodes/directoryindex.html diff --git a/content/templates/local-file-templates.md b/content/templates/local-file-templates.md index d46056bf3..39ceaee97 100644 --- a/content/templates/local-file-templates.md +++ b/content/templates/local-file-templates.md @@ -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.) -{{}} +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" >}}
+ This is the call that rendered the above output: + ```html {{}} ``` -By the way, -regarding the pathURL argument, the initial slash `/` is important. -Otherwise, it becomes relative to the current web page. \ No newline at end of file + +{{% 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 \ No newline at end of file diff --git a/layouts/shortcodes/directoryindex.html b/layouts/shortcodes/directoryindex.html new file mode 100644 index 000000000..4205d4347 --- /dev/null +++ b/layouts/shortcodes/directoryindex.html @@ -0,0 +1,13 @@ +{{- $pathURL := .Get "pathURL" -}} +{{- $path := .Get "path" -}} +{{- $files := readDir $path -}} + + + +{{- range $files }} + + + + +{{- end }} +
Size in bytesName
{{ .Size }} {{ .Name }}
\ No newline at end of file diff --git a/themes/hugodocs/layouts/partials/site-footer.html b/themes/hugodocs/layouts/partials/site-footer.html index 9aaa07814..e4289a228 100644 --- a/themes/hugodocs/layouts/partials/site-footer.html +++ b/themes/hugodocs/layouts/partials/site-footer.html @@ -1,7 +1,7 @@