view build.sh @ 27:b9aeab8d9362

Sort by date in index.html
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Tue, 18 Feb 2014 16:37:17 +0900
parents 3fb1e07004fa
children
line wrap: on
line source

#/bin/sh

cd $(dirname $0)

# source definitions
. config/definition.sh

# functions

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

directory_check() {
    if !([ -d ${slide_root_dirname} ]); then
        echo "slide directory not found :" ${slide_root_dirname}
        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 "${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

    (sort ${index_source_name} | kramdown  --template ${index_template_file}) > ${index_file_name}
    rm ${index_source_name}
}


# main

command_check
directory_check
build_slides
build_index