Fix bugs with file names including white spaces
This commit is contained in:
parent
cf62782735
commit
ac5a33f305
22
sw
22
sw
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# sw - suckless webframework - 2012 - MIT License - nibble <develsec.org>
|
# sw - suckless webframework - 2012 - MIT License - nibble <develsec.org>
|
||||||
|
|
||||||
sw_filter() {
|
sw_filter() {
|
||||||
|
@ -14,11 +14,10 @@ sw_main() {
|
||||||
sw_menu() {
|
sw_menu() {
|
||||||
echo "<ul>"
|
echo "<ul>"
|
||||||
[ -z "$(echo $1 | grep index.md)" ] && echo "<li><a href=\"index.html\">.</a></li>"
|
[ -z "$(echo $1 | grep index.md)" ] && echo "<li><a href=\"index.html\">.</a></li>"
|
||||||
[ "$(dirname $1)" != "." ] && echo "<li><a href=\"../index.html\">..</a></li>"
|
[ "$(dirname "$1")" != "." ] && echo "<li><a href=\"../index.html\">..</a></li>"
|
||||||
FILES=$(ls $(dirname $1) | sed -e 's,.md$,.html,g')
|
ls "$(dirname "$1")" | sed -e 's,.md$,.html,g' | while read i ; do
|
||||||
for i in $FILES ; do
|
|
||||||
sw_filter "$i" && continue
|
sw_filter "$i" && continue
|
||||||
NAME=$(echo "$i" | sed -e 's/\..*$//' -e 's/_/ /g')
|
NAME=$(echo $i | sed -e 's/\..*$//')
|
||||||
[ -z "$(echo $i | grep '\..*$')" ] && i="$i/index.html"
|
[ -z "$(echo $i | grep '\..*$')" ] && i="$i/index.html"
|
||||||
echo "<li><a href=\"$i\">$NAME</a></li>"
|
echo "<li><a href=\"$i\">$NAME</a></li>"
|
||||||
done
|
done
|
||||||
|
@ -81,24 +80,23 @@ if [ -z "$IDIR" ] || [ ! -d "$IDIR" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load config file
|
# Load config file
|
||||||
if [ ! -f $PWD/sw.conf ]; then
|
if [ ! -f "$PWD/sw.conf" ]; then
|
||||||
echo "Cannot find sw.conf in current directory"
|
echo "Cannot find sw.conf in current directory"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
. $PWD/sw.conf
|
. "$PWD/sw.conf"
|
||||||
|
|
||||||
# Setup output dir structure
|
# Setup output dir structure
|
||||||
CDIR=$PWD
|
CDIR=$PWD
|
||||||
ODIR="$CDIR/$(basename $IDIR).static"
|
ODIR="$CDIR/$(basename "$IDIR").static"
|
||||||
rm -rf "$ODIR"
|
rm -rf "$ODIR"
|
||||||
mkdir -p "$ODIR"
|
mkdir -p "$ODIR"
|
||||||
cp -rf $IDIR/* "$ODIR"
|
cp -rf "$IDIR"/* "$ODIR"
|
||||||
rm -f $(find "$ODIR" -type f -iname '*.md') #TODO: can't find do that?
|
find "$ODIR" -type f -iname '*.md' -delete
|
||||||
|
|
||||||
# Parse files
|
# Parse files
|
||||||
cd "$IDIR" || exit 1
|
cd "$IDIR" || exit 1
|
||||||
FILES=$(find . -iname '*.md' | sed -e 's,^\./,,')
|
find * -iname '*.md' | while read a ; do
|
||||||
for a in $FILES; do
|
|
||||||
b="$ODIR/$(echo $a | sed -e 's,.md$,.html,g')"
|
b="$ODIR/$(echo $a | sed -e 's,.md$,.html,g')"
|
||||||
echo "* $a"
|
echo "* $a"
|
||||||
sw_page "$a" > "$b"
|
sw_page "$a" > "$b"
|
||||||
|
|
Loading…
Reference in New Issue