summaryrefslogtreecommitdiff
path: root/refresh.sh
blob: 0d2529800ef69f0207dfb7a972cd6d4dcea8e19a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash

wai=$(dirname $(readlink -f "$0")) # Current script directory
projects_dir=${wai}/projects
www_dir=${wai}/public/
projects_out_dir=${www_dir}/projects/
template_file=${wai}/template.html

# Clean before
rm -f $www_dir/*.html
rm -fr $projects_out_dir/*

# Build links
build_links() {
    links=""
    for p in $(find ${projects_dir}/ -maxdepth 1 -mindepth 1 -type d)
    do
        name=$(basename $p)
        [ $name == $1 ] && active="active" || active=""
        
        links="${links}\n"'<a href="'${name}'.html" class="btn btn-primary '$active'">'${name}'</a>'
    done
    tmp=$(mktemp)
    echo -e "$links" > $tmp
    echo $tmp
}

# Build html
for p in $(find ${projects_dir}/ -maxdepth 1 -mindepth 1 -type d)
do
    name=$(basename $p)
    html=$projects_out_dir/$name/index.html
    js=$projects_out_dir/$name/index.js
    js2=projects/$name/index.js
    page=${www_dir}/${name}.html
    echo $p
    # Create html
    echo $projects_out_dir
    cp -r $p $projects_out_dir/
    cat $template_file |sed "/\${CONTENT}/r $html"|sed '/\${CONTENT}/d' > $page
    sed -i "s#\${JS}#${js2}#g" $page
    sed -i "s#\${project_name}#${name}#g" $page

    # Add links
    links_file=$(build_links $name)
    sed -i "/\${LINKS}/r $links_file" $page
    sed -i '/\${LINKS}/d' $page
done