Fixed bug regarding line cuts.

This commit is contained in:
Nicolás Ortega Froysa 2020-10-25 08:57:33 +01:00
parent 494d34a23f
commit 1a3b70a67c

15
sssg.sh
View File

@ -20,11 +20,11 @@ function parse {
echo -n "Generating _site/$1 ... "
touch _site/$1
# get the variables
last_find="$(grep -n "^%%%$" $1 | cut -c1)"
last_find="$(grep -n "^%%%$" $1)"
vars=()
if ! [ -z $last_find ]
then
end_line="$(expr $last_find - 1)"
end_line="$(expr ${last_find%%:*} - 1)"
for (( i=1; i<=$end_line; i++ ))
do
vars+=("$(sed "$i!d" $1)")
@ -32,21 +32,22 @@ function parse {
fi
# import templates
for i in $(grep -n "^#/" $1 | cut -c1)
for i in $(grep -n "^#/" $1)
do
end_line="$(expr $i - 1)"
end_line="$(expr ${i%%:*} - 1)"
if [ -z $last_find ]
then
sed -n "1,$end_line{p}" $1 >> _site/$1
else
start_line="$(expr $last_find + 1)"
start_line="$(expr ${last_find%%:*} + 1)"
sed -n "$start_line,$end_line{p}" $1 >> _site/$1
fi
inc_file="$(sed "$i!d" $1)"
#inc_file="$(sed "$i!d" $1)"
inc_file=${i#*:}
cat _templates/${inc_file:2} >> _site/$1
last_find="$i"
done
start_line="$(expr $last_find + 1)"
start_line="$(expr ${last_find%%:*} + 1)"
sed -n "$start_line,\$p" $1 >> _site/$1
# replace variables