summaryrefslogtreecommitdiff
path: root/refresh.sh
blob: 66e5b206df7adf4f47536d9ea51a09d8fb03a837 (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
#!/usr/bin/env bash

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

# Clean before
rm -rf $public/projects
rm -rf $public/*.html
mkdir -p $public/projects

# Build links
build_links() {
    links=""
    for p in $(find ${projects}/ -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
}

for p in $(find ${projects}/ -maxdepth 1 -mindepth 1 -type d)
do
    name=$(basename $p)
    html=${public}/${name}.html
    js=./projects/$name/index.js
    content=$p/index.html

    # Create HTML page
    cp -r $p $public/projects/
    cat $template |sed "/\${CONTENT}/r $content"|sed '/\${CONTENT}/d' > $html
    sed -i "s#\${JS}#${js}#g" $html
    sed -i "s#\${project_name}#${name}#g" $html
    echo $html

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