static-httpd

Sitio web estático (HTML + CSS) que sostiene el blog del autor
Log | Files | Refs

dirs-to-index.sh (1432B)


      1 #!/usr/bin/env bash
      2 
      3 TMP=$(mktemp)
      4 
      5 for file in */index.html; do
      6     [ -f "$file" ] || continue
      7 
      8     dir=$(dirname "$file")
      9 
     10     title=$(grep -oP '(?<=<p class="title">).*?(?=</p>)' "$file" | head -n1)
     11 
     12     date=$(grep -oP '(?<=<p class="date">).*?(?= • )' "$file" | head -n1)
     13 
     14     author=$(grep -oP '(?<= • ).*?(?=</p>)' "$file" | head -n1)
     15 
     16     excerpt=$(
     17         awk '
     18             /<\/header>/ {inside=1; next}
     19             inside && /<p>/ {
     20                 gsub(/<[^>]+>/,"")
     21                 print
     22                 exit
     23             }
     24         ' "$file" | cut -c1-200
     25     )
     26 
     27     order_date=$(
     28         python3 - <<EOF
     29 from datetime import datetime
     30 
     31 months = {
     32     "enero":1,
     33     "febrero":2,
     34     "marzo":3,
     35     "abril":4,
     36     "mayo":5,
     37     "junio":6,
     38     "julio":7,
     39     "agosto":8,
     40     "septiembre":9,
     41     "octubre":10,
     42     "noviembre":11,
     43     "diciembre":12
     44 }
     45 
     46 s = "$date".lower()
     47 
     48 try:
     49     day, _, month, _, year = s.split()
     50     print(f"{year}{months[month]:02d}{int(day):02d}")
     51 except:
     52     print("00000000")
     53 EOF
     54     )
     55 
     56     printf "%s\t%s\t%s\t%s\t%s\n" \
     57         "$order_date" "$dir" "$title" "$date" "$author|$excerpt" \
     58         >> "$TMP"
     59 
     60 done
     61 
     62 sort -r "$TMP" | while IFS=$'\t' read -r _ dir title date rest
     63 do
     64     author=${rest%%|*}
     65     excerpt=${rest#*|}
     66 
     67     cat <<EOF
     68 <a href="./$dir/" class="article">
     69     <p class="title">$title</p>
     70     <p class="info">$date · $author</p><p>$excerpt...</p>
     71 </a>
     72 
     73 EOF
     74 
     75 done
     76 
     77 rm "$TMP"