#!/usr/bin/env zsh
#
# WebNomad, your slick and static website publisher
#
# Copyright (C) 2012-2013 Denis Roio <jaromil@dyne.org>
#
# This source  code is free  software; you can redistribute  it and/or
# modify it under the terms of  the GNU Public License as published by
# the Free  Software Foundation; either  version 3 of the  License, or
# (at your option) any later version.
#
# This source code is distributed in  the hope that it will be useful,
# but  WITHOUT ANY  WARRANTY;  without even  the  implied warranty  of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Please refer to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to:
# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

QUIET=0
DEBUG=0

SYS=`dirname $0`
source $SYS/zuper/zuper

source $SYS/zuper/zuper.init

act "Initializing Webnomad"

act "Below is the log of files copied into this directory."
act "Init does not rewrite any existing file"
act

mkdir -p views/js
mkdir -p views/css
touch views/css/custom.css

[[ -r config.zsh ]] && source config.zsh

[[ -r views/abstract.txt ]] && [[ ! -r index.html ]] &&
	[[ "$WRITEDOWN_TITLE" != "" ]] && {
	cat <<EOF > views/index.html
<h1>$WRITEDOWN_TITLE</h1>
<p>
`cat views/abstract.txt | sed 's/^$/<\/p><p>/'`
</p>
EOF
}

[[ -r views/index.html ]] || {
    cat <<EOF > views/index.html
<h1>Hello world</h1>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>

<blockquote>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</blockquote>

<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.</p>

EOF
}

mkdir -p tmpl
[[ -r tmpl/header.html ]] || {
	cat <<EOF > tmpl/header.html
	<!-- You are inside your <head> here -->
	<link rel="shortcut icon" href="/favicon.ico" />
	<!-- pad down for the header -->
	<style type="text/css">
	body {   padding-top:     3em;
             padding-bottom: .5em; }
	.brand { padding: 1em 1em 1em 1em; }
	.sidebar-nav { padding: 40px; }
	</style>
EOF
}

[[ -r tmpl/footer.html ]] ||
    cp -v ${SYS}/tmpl/footer.html tmpl/

[[ -r tmpl/navbar.html ]] || {
	cat <<EOF > tmpl/navbar.html
<!-- navigation bar automatically generated by webnomad -->
<nav>
  <div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
      <a href="index">
    <div class="brand">
      <!-- customise your brand icon from css -->
      <i class="icon-home"></i> &nbsp;&nbsp;&nbsp
    </div>
      </a>
      <ul class="nav">
    <li class="divider-vertical"></li>
    <!-- customise below with a list of pages -->
      </ul>
    </div>
  </div>
</nav>

EOF
}

# TODO: make a list of main files in the navbar
# or perhaps implement a sidebar
touch config.zsh
grep '^# WEBNOMAD CONFIGURATION' config.zsh >/dev/null || {

    cat <<EOF >> config.zsh

# WEBNOMAD CONFIGURATION
TITLE="A new website made with WebNomad."

DESCRIPTION="WebNomad, your slick and static website publisher, powered by HTML5, Zsh and Bootstrap"

KEYWORDS="web, design, html"

# representative image, 1200x627 pixels is full column banner, 400 is half
# exact size indicated above is important to avoid resizes server-side
IMAGE="https://www.dyne.org/wp-content/uploads/2013/09/carciofo-webnomad.jpg"

# list of types: http://ogp.me/#types
TYPE="website"

# What is the root of this website url, after the domain
# full url includes http and no trailing slash i.e. http://www.dyne.org
# leave blank if relative, or just subdir i.e /blog
WEB_ROOT=""

# A twitter handler is necessary to activate open-graph compatible
# information that works also with twitter.
TWITTER="@DyneOrg"

#
# Anything below is safe to leave untouched
#

# Comment to disable Bootstrap
BOOTSTRAP=1

# What file extension to use for html files
EXTENSION=".html"

# What is the url for files in case indexing is used
# this can be different from WEB_ROOT in order to serve
# files from a position different from the web pages
# FILES_ROOT=""
 
# Uncomment for Flowtype
# FLOWTYPE=1
# What is the size ratio of text with respect to the width
# of its container element. This is better than setting the
# text size in an absolute way (we use Flowtype)
# FONT_RATIO=30

# Cleanup EXIF information from jpeg images (requires jhead)
# i.e: location, camera type, time of shot, editors used
EXIF_CLEAN=1
# Add a comment to EXIF in jpeg images (requires jhead)
# EXIF_COMMENT=""
# Automatically rotate the image according to EXIF information
# EXIF_ROTATE=1
EOF
}



notice "Initialization completed"
act "Look in your new WebNomad project: $B $DIR $r"
act "Customize $B config.zsh $r and then files in the $B tmpl/ $r folder"
act "Create new HTML pages in $B views/ $r"
