view build.sh @ 11:9dca7035ab93

Generate index page for slides
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Fri, 31 Jan 2014 23:26:36 +0900
parents 455db4624bce
children daf59131cdb8
line wrap: on
line source

#/bin/sh

# source definitions
. `dirname $0`/config/definition.sh

# functions

command_check() {
    if !(which ${build_command} >& /dev/null;) then
        echo ${build_command} not found
        exit
    fi
}

slide_name_from_full_path() {
    echo $1 | sed -e 's/.[^.]*$/.html/'
}


need_build() {
    slide_name=`slide_name_from_full_path $1`

    if [ "${slide_name}" -ot "$1" ]; then
        return 0    # if exist slide and newer than src, not needed.
    fi

    return 1
}

build() {
    ${build_command} build $1 -o `dirname $1` ${build_template_option}
}

find_sources() {
    find "$(dirname $0)/${slide_root_dirname}" -name "${build_target_filename}"
}

build_slides() {
    target_list=`find_sources`
    for target in ${target_list}; do
        if need_build $target; then
            build $target
        fi
    done
}

build_index() {
    rm -f ${index_source_name}
    touch ${index_source_name}

    slide_list=`find_sources`
    for slide in ${slide_list}; do
        title=`head -5 $slide | grep "title[ ]*:" | sed -e 's/^title[ ]*:[ ]*//'`
        date=`basename $(dirname $slide)`
        echo "* ${date} : [$title]($(slide_name_from_full_path $slide))" >> ${index_source_name}
    done

    kramdown ${index_source_name} --template "$(dirname $0)/${index_template_file}" > ${index_file_name}
}


# main

command_check
build_slides
build_index