自動化 shortcode
このページは、まだ未完成です。。。 nicotalk&キャラ素材配布所 http://www.nicotalk.com/charasozai_kt.html (2024年5月16日) この記事を作った動機 markdown のテンプレートを作るにおいて、テンプレートを作ったついでに、そのテンプレート内で初めて真面目に hugo の機能を使った気がするので次いでにその例を記録するだけ。ただの自己満と言われればそうなのかもしれない。 内容 layouts/shortcodes/Images/MMD/Data.html {{ $folder := .Get "folder" }} <ul> {{$path := printf "static/Images/MMD/%s" $folder}} {{range readDir $path}} {{$filepath := printf "%s/%s" $path .Name}} {{$filepath := replace $filepath "static" ""}} {{if strings.Contains .Name ".blend"}} <li> <a download href="{{$filepath}}">{{.Name}}</a> </li> {{end}} {{if strings.Contains .Name ".zip"}} <li> <a download href="{{$filepath}}">{{.Name}}</a> </li> {{end}} {{end}} </ul> archetypes/Images/MMD.md +++ date = '{{ .Date }}' draft = false title = '{{ replace .File.ContentBaseName "-" " " | title }}' +++ ## data \{\{<Images/MMD/Data folder="\{\{.File.ContentBaseName}}">}} ## Images and Videos \{\{<Images/MMD/ShowImageAndVideo folder="\{\{.File.ContentBaseName}}">}} readDir strings.Contains replace 参考にしたサイトとか https://gohugo.io/functions/os/readdir/#article https://gohugo.io/functions/strings/contains/#article https://gohugo.io/functions/strings/replace/#article ...