view build.sh @ 163:b8e16c48a5a4 default tip

Update template
author atton <atton@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2017 17:18:41 +0900
parents b9aeab8d9362
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