#!/bin/sh
#Author: KGussan
#$RCSfile: wpgen.sh,v $ $Revision: 2.0 $ $Date: 2006/04/16 14:20:56 $
#notice:
#- cygwin requires shift-jis encoding in shell script.
#- cygwin requires \\ as escape sequence instead of \.
#================================================================
target_dir=""
templete_dir=cvshtml
release_dir="release"
time_start=`date +%s`

################ refresh release directory ################
echo "# $0:######## start refreshing release directory ########"
rm -rf ${release_dir}
mkdir ${release_dir}
echo "# $0:######## end refreshing release directory ########"


################ generate pc webpage ################
# 3line page, no frame

target_dir="pc"

rm -rf ${target_dir}
mkdir ${target_dir}

echo "# $0:######## start generating ${target_dir} ########"

#### generate index.html ####
echo "# $0:generating index.html"
cat ${templete_dir}/pc-header	>	${target_dir}/index.html
cat ${templete_dir}/menu.html	>>	${target_dir}/index.html
cat ${templete_dir}/pc-left		>>	${target_dir}/index.html
cat ${templete_dir}/top.html	>>	${target_dir}/index.html
cat ${templete_dir}/pc-footer	>>	${target_dir}/index.html

#### generate content's html ####
for filename in src/*; do
filename_out=${filename#src/}
echo "# $0:generating ${target_dir}/${filename_out}"
cat ${templete_dir}/pc-header	>	${target_dir}/$filename_out
cat ${templete_dir}/menu.html	>>	${target_dir}/$filename_out
cat ${templete_dir}/pc-left		>>	${target_dir}/$filename_out
cat ${filename}					>>	${target_dir}/$filename_out
cat ${templete_dir}/pc-footer	>>	${target_dir}/$filename_out
done

mv ${target_dir}/* ${release_dir}

echo "# $0:######## end generating ${target_dir} ########"


################# generate frame and mobile webpage ################
## 2line page, frame, requires menu.html
#
target_dir="frame"
#reformat=`sed "s/\.\/data/\.\.\/data/"`

rm -rf ${target_dir}
mkdir ${target_dir}

echo "# $0:######## start generating ${target_dir} ########"

echo "# $0:generating index.html"
cat ${templete_dir}/index-frame.html > ${target_dir}/index.html
echo "# $0:generating menu.html"
cat ${templete_dir}/menu-header			>	${target_dir}/menu.html
echo "<base target=\"main_frame\">"		>>	${target_dir}/menu.html
echo "<H2> <small>menu</small> </H2>"	>>	${target_dir}/menu.html
echo "<small>"							>>	${target_dir}/menu.html
cat ${templete_dir}/menu.html			>>	${target_dir}/menu.html
echo "</small>"							>>	${target_dir}/menu.html
cat ${templete_dir}/menu-footer			>>	${target_dir}/menu.html
echo "# $0:generating top.html"
cat ${templete_dir}/frame-header		>	${target_dir}/top.html
cat ${templete_dir}/top.html			>>	${target_dir}/top.html
cat ${templete_dir}/pc-footer			>>	${target_dir}/top.html

#### generate content's html ####
for filename in src/*; do
filename_out=${filename#src/}
echo "# $0:generating ${target_dir}/${filename_out}"
cat ${templete_dir}/frame-header				>	${target_dir}/$filename_out
cat ${filename}| sed "s/\.\/data/http:\/\/kgussan\.ojaru\.jp\/data/"	>>	${target_dir}/$filename_out
cat ${templete_dir}/pc-footer					>>	${target_dir}/$filename_out
done
mv ${target_dir} ${release_dir}
echo "# $0:######## end generating ${target_dir} ########"


################# generate mobile webpage ################
## 1line page, frame, requires menu.html, it's own prefix and suffix.
#
#target_dir="mobile"
##### generate content's html ####
#echo "# $0:######## start generating ${target_dir} ########"
#for filename in src/*; do
#filename_out=${filename#src/}
#echo "# $0:generating ${target_dir}/${filename_out}"
#cat ${templete_dir}/prefix_${target_dir}	>	${target_dir}/$filename_out
#cat ${filename}							>>	${target_dir}/$filename_out
#cat ${templete_dir}/suffix_${target_dir}	>>	${target_dir}/$filename_out
#done
##### generate menu.html ####
#cat ${templete_dir}/prefix_menu			>	${target_dir}/menu.html
#cat ${templete_dir}/menu.html						>>	${target_dir}/menu.html
#cat ${templete_dir}/suffix_menu			>>	${target_dir}/menu.html
##### generate index.html ####
#cat ${templete_dir}/prefix_${target_dir}	>	${target_dir}/index.html
#cat ${filename}							>>	${target_dir}/index.html
#cat ${templete_dir}/suffix_${target_dir}	>>	${target_dir}/index.html
#echo "# $0:######## end generating ${target_dir} ########"


################ copy moved-page ################
echo "# $0:######## start generating page-moved-notification ########"
echo "# $0:generating page-moved-notification"

mkdir ${release_dir}/pc
cp -f ${templete_dir}/page-moved-notification.html ${release_dir}/pc/index.html

echo "# $0:######## end generating moved-page ########"


################ generate base data ################
echo "# $0:######## start generating base-data ########"

#### default page ####
cp ${templete_dir}/config.xml ${release_dir}
cp ${templete_dir}/favicon.ico ${release_dir}
cp ${templete_dir}/kg.css ${release_dir}
cp -rf data_org ${release_dir}/data

#### frame page ####
#cp ${templete_dir}/config.xml ${release_dir}/frame/
#cp ${templete_dir}/favicon.ico ${release_dir}/frame/
#cp ${templete_dir}/kg.css ${release_dir}/frame/
#cp -rf data_org ${release_dir}/frame/data
echo "# $0:######## end generating base-data ########"


################ end, date ################
echo "# $0:######## end ########"

time_end=`date +%s`
time_taken=`expr ${time_end} - ${time_start}`
date_current=`date +%Y%m%d_%R`

echo "# $0: #### time: ${time_taken} seconds"
echo "# $0: #### date: ${date_current}"

#================================================================

