shell script to create a static HTML directory listing

前端 未结 4 1795
傲寒
傲寒 2021-02-07 18:43

So I\'m creating a GitHub Pages site to list all of the Gifs in my jglovier/gifs repo. GH Pages runs only static HTML/CSS/JS or Jekyll, so I cannot use an apache directory listi

4条回答
  •  误落风尘
    2021-02-07 19:12

    #!/bin/bash
    
    ROOT=/tmp/test
    HTTP="/"
    OUTPUT="_includes/site-index.html" 
    
    i=0
    echo "
      " > $OUTPUT for filepath in `find "$ROOT" -maxdepth 1 -mindepth 1 -type d| sort`; do path=`basename "$filepath"` echo "
    • $path
    • " >> $OUTPUT echo "
        " >> $OUTPUT for i in `find "$filepath" -maxdepth 1 -mindepth 1 -type f| sort`; do file=`basename "$i"` echo "
      • $file
      • " >> $OUTPUT done echo "
      " >> $OUTPUT done echo "
    " >> $OUTPUT

    My /tmp/test

    /tmp/test
    ├── accidents
    │   ├── accident2.gif
    │   ├── accident3.gif
    │   └── accident4.gif
    ├── bears
    │   ├── bears1.gif
    │   ├── bears2.gif
    │   ├── bears3.gif
    │   └── bears4.gif
    └── cats
        ├── cats1.gif
        └── cats2.gif
    

    The resulting output

    
    

    You could expand the UL with href too, but I wasn't sure if that's what you wanted.

    echo "  

    You would have to run this in the parent folder of _includes

提交回复
热议问题