Compare commits

...

2 Commits

Author SHA1 Message Date
Alessandro Mauri 8f1508e200 removed find -regex and merged pattern into awk command 3 years ago
Alessandro Mauri 073c779f93 removed the use of sed -i which is not portable 3 years ago
  1. 2
      makefile
  2. 68
      rivet.sh

@ -1,4 +1,4 @@
VERSION = 0.3 VERSION = 0.3.1
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man MANPREFIX = ${PREFIX}/share/man

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

Loading…
Cancel
Save