Browse Source

removed the use of sed -i which is not portable

master
Alessandro Mauri 8 months ago
parent
commit
073c779f93
  1. 63
      rivet.sh

63
rivet.sh

@ -110,6 +110,7 @@ footerfile=$srcdir/_footer.html @@ -110,6 +110,7 @@ footerfile=$srcdir/_footer.html
metafile=$srcdir/_metadata.html
objlist="$(mktemp)"
objdate="$(mktemp)"
tmpsed="$(mktemp)"
# Check if index.md is present
if ! [ -e "$srcdir"/index.md ]; then
@ -133,10 +134,14 @@ if ! [ -e "$metafile" ]; then @@ -133,10 +134,14 @@ if ! [ -e "$metafile" ]; then
fi
# Remove junk from {header,footer} files
sed -i 's/<header.*>//' "$headerfile"
sed -i 's/<\/header>//' "$headerfile"
sed -i 's/<footer.*>//' "$footerfile"
sed -i 's/<\/footer>//' "$footerfile"
sed 's/<header.*>//' "$headerfile" > "$tmpsed"
mv "$tmpsed" "$headerfile"
sed 's/<\/header>//' "$headerfile" > "$tmpsed"
mv "$tmpsed" "$headerfile"
sed 's/<footer.*>//' "$footerfile" > "$tmpsed"
mv "$tmpsed" "$headerfile"
sed 's/<\/footer>//' "$footerfile" > "$tmpsed"
mv "$tmpsed" "$headerfile"
# Remove any junk from the domain eg. [https://]domain.com[/]
domain="$(echo "$2" | sed -e 's/^https*:\/\///' -e 's/\/$//')"
@ -170,7 +175,8 @@ rm -f "$objdate" @@ -170,7 +175,8 @@ rm -f "$objdate"
while IFS="" read -r file; do
stat -c '%y' "$file" >> "$objdate"
done < "$objlist"
sed -i -e "s,^\/*[^\/]*\/,$destdir/," "$objlist"
sed -e "s,^\/*[^\/]*\/,$destdir/," "$objlist" > "$tmpsed"
mv "$tmpsed" "$objlist"
# Convert convertible files
while IFS="" read -r file; do
@ -178,18 +184,21 @@ while IFS="" read -r file; do @@ -178,18 +184,21 @@ while IFS="" read -r file; do
done < "$objlist"
# Convert the file list to a list that contains the path of all the html files
sed -i -e 's/\.md$/\.html/' "$objlist"
sed -e 's/\.md$/\.html/' "$objlist" > "$tmpsed"
mv "$tmpsed" "$objlist"
# Create a list that contains the links to all html files
linklist="$(mktemp)"
cp -f "$objlist" "$linklist"
sed -i -e "s/^$destdir//" "$linklist"
sed -e "s/^$destdir//" "$linklist" > "$tmpsed"
mv "$tmpsed" "$linklist"
# Insert metadata into <head>
if ! [ "$SKIP_META" ]; then
find "$destdir" -name "*.html" |
while IFS="" read -r file; do
sed -i "/<head>/r $metafile" "$file"
sed "/<head>/r $metafile" "$file" > "$tmpsed"
mv "$tmpsed" "$file"
done
fi
@ -216,27 +225,33 @@ EOF @@ -216,27 +225,33 @@ EOF
printf "<p><a href=\"%s\">%s - %s</a></p>\n" "$line" "$ldate" "$title" >> "$tmpfile"
done < "$linklist"
echo '</div>' >> "$tmpfile"
sed -i '/<\/body>/i REPLACE' "$destdir"/index.html
sed -i "/^REPLACE/r $tmpfile" "$destdir"/index.html
sed -i 's/^REPLACE//' "$destdir"/index.html
sed '/<\/body>/i REPLACE' "$destdir"/index.html > "$tmpsed"
mv "$tmpsed" "$destdir"/index.html
sed "/^REPLACE/r $tmpfile" "$destdir"/index.html > "$tmpsed"
mv "$tmpsed" "$destdir"/index.html
sed 's/^REPLACE//' "$destdir"/index.html > "$tmpsed"
mv "$tmpsed" "$destdir"/index.html
rm -f "$tmpfile"
fi
# enclose article inside <article></article>
find "$destdir" -name "*.html" |
while IFS="" read -r file; do
sed -i -e '/<body>/a <article>' -e '/<\/body>/i </article>' "$file"
sed -e '/<body>/a <article>' -e '/<\/body>/i </article>' "$file" > "$tmpsed"
mv "$tmpsed" "$file"
done
# Prepate the header
if ! [ "$SKIP_HEADER" ]; then
tmphead="$(mktemp)"
cp "$headerfile" "$tmphead"
sed -i '1s/^/<header>/' "$tmphead"
sed '1s/^/<header>/' "$tmphead" > "$tmpsed"
mv "$tmpsed" "$tmphead"
echo '</header>' >> "$tmphead"
find "$destdir" -name "*.html" |
while IFS="" read -r file; do
sed -i "/<body>/r $tmphead" "$file"
sed "/<body>/r $tmphead" "$file" > "$tmpsed"
mv "$tmpsed" "$file"
done
rm -f "$tmphead"
fi
@ -245,13 +260,17 @@ fi @@ -245,13 +260,17 @@ fi
if ! [ "$SKIP_FOOTER" ]; then
tmpfoot="$(mktemp)"
cp "$footerfile" "$tmpfoot"
sed -i '1s/^/<footer>/' "$tmpfoot"
sed '1s/^/<footer>/' "$tmpfoot" > "$tmpsed"
mv "$tmpsed" "$tmpfoot"
echo '</footer>' >> "$tmpfoot"
find "$destdir" -name "*.html" |
while IFS="" read -r file; do
sed -i '/<\/body>/i REPLACE' "$file"
sed -i "/^REPLACE/r $tmpfoot" "$file"
sed -i 's/^REPLACE//' "$file"
sed '/<\/body>/i REPLACE' "$file" > "$tmpsed"
mv "$tmpsed" "$file"
sed "/^REPLACE/r $tmpfoot" "$file" > "$tmpsed"
mv "$tmpsed" "$file"
sed 's/^REPLACE//' "$file" > "$tmpsed"
mv "$tmpsed" "$file"
done
rm -f "$tmpfoot"
fi
@ -264,10 +283,12 @@ if ! [ "$SKIP_SITEMAP" ]; then @@ -264,10 +283,12 @@ if ! [ "$SKIP_SITEMAP" ]; then
</urlset>
EOF
while IFS="" read -r line; do
sed -i "/<\/urlset>/i \
<url><loc>$line<\/loc><\/url>" "$destdir"/sitemap.xml
sed "/<\/urlset>/i \
<url><loc>$line<\/loc><\/url>" "$destdir"/sitemap.xml > "$tmpsed"
mv "$tmpsed" "$destdir"/sitemap.xml
done < "$linklist"
sed -i 's/^<url>/\t<url>/' "$destdir"/sitemap.xml
sed 's/^<url>/\t<url>/' "$destdir"/sitemap.xml > "$tmpsed"
mv "$tmpsed" "$destdir"/sitemap.xml
fi
# Generate atom feed

Loading…
Cancel
Save