#!/bin/bash

OIFS=$IFS
NUM_LINE=2
PREFIX=cours/algo/slides/

classes=()
for i in *.md; do
    [ -f "$i" ] || break
    comp=$(echo "$fullName" | sed "${NUM_LINE}q;d" $i)
    date=$(echo "$fullName" | sed "3q;d" $i)
    IFS=':' 
    comp=($comp); 
    comp=${comp[1]}
    date=($date); 
    date=${date[1]}
    # echo $comp
    IFS='"'
    comp=($comp)
    comp=${comp[1]}
    date=($date); 
    date=${date[1]}
    # echo $comp | awk '{ print substr( $0, 1, length($0)-1 ) }'
    # echo $comp
    # date=sed "${NUM_LINE}q;d" $i
    i="${i%.*}"
    class="[${date} ${comp}](${PREFIX}${i}.pdf)"
    classes+=($class)
    # echo "[${date} ${comp}](${PREFIX}${i}.pdf)" >> index.md
done
IFS=$'\n'
classes=($(sort <<<"${classes[*]}"))
date=$(date '+%Y-%m-%d')
echo "---" >> index.md
echo "date: ${date}" >> index.md
echo "---" >> index.md
for i in ${classes[*]}; do
    echo $i >> index.md
done


IFS=$OIFS
