mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-14 10:18:40 +00:00
Add shortcode from live site for readfile example in local files template
This commit is contained in:
1 parent
4e159ed50c
commit
ed70c14a2b
3 files changed
+27
-9
No files matched your search
@@ -2,6 +2,7 @@
|
|||||||
title: Local File Templates
|
title: Local File Templates
|
||||||
linktitle: Local File Templates
|
linktitle: Local File Templates
|
||||||
description:
|
description:
|
||||||
|
godocref: https://golang.org/pkg/os/#FileInfo
|
||||||
date: 2017-02-01
|
date: 2017-02-01
|
||||||
publishdate: 2017-02-01
|
publishdate: 2017-02-01
|
||||||
lastmod: 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.
|
For the files in any given directory, this shortcode usefully lists their basenames and sizes, while providing links to them.
|
||||||
|
|
||||||
Already—actually—this shortcode
|
This shortcode [has already been included in this very web site][].
|
||||||
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.)
|
||||||
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" >}}
|
||||||
{{</* directoryindex path="/static/css" pathURL="/css" */>}}
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
This is the call that rendered the above output:
|
This is the call that rendered the above output:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
{{</* directoryindex path="/static/css" pathURL="/css" */>}}
|
{{</* directoryindex path="/static/css" pathURL="/css" */>}}
|
||||||
```
|
```
|
||||||
By the way,
|
|
||||||
regarding the pathURL argument, the initial slash `/` is important.
|
{{% note "Slashes are Important" %}}
|
||||||
Otherwise, it becomes relative to the current web page.
|
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
|
||||||
@@ -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>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<footer id="site-footer" class="site-footer{{if .Params.toc}} withtoc{{end}}">
|
<footer id="site-footer" class="site-footer{{if .Params.toc}} withtoc{{end}}">
|
||||||
<div class="footer-content">
|
<div class="footer-content">
|
||||||
<div class="footer-info">
|
<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">
|
<img src="{{ "images/hugo-logo/made-with-hugo-dark.png" | relURL}}" alt="Made with Hugo Logo">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in new issue
Block a user