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