<% 
	function resolveImgURL(from, path) {
        // check if the url provided is
        if (from !== null && !is_remote_url(path)) {
            // format `from` path
            // remove .html at the end of url
            if (from.indexOf('.html') >= 0) {
                from = from.replace('.html', '')
            }
            // remove end `/` of `from` path
            if (from.length === from.lastIndexOf('/') + 1) {
                from = from.substr(0, from.lastIndexOf('/'))
            }
            // remove end `/` of `url` path
            if (path.indexOf('/') === 1) {
                path = url.substr(1);
            }
            return url_for(from + '/' + path);

        }
        else {
            return path;
        }
    }
%>
<%
    var bg = '';
    if( theme.sidebar_bg ){
        bg = 'style="background-image: url('+ resolveImgURL(theme.image_dir,theme.sidebar_bg) +');background-size: cover;"';
    }
%>
<nav <%-bg%> id="sidebar" class="<% if(theme.sidebar_behavior){ %> behavior_<%=theme.sidebar_behavior%><% }%>">
    <div class="wrap">
    	<% if( theme.author.gravatar ){ %>
    		<div class="profile">
    			<a href="/"><img src="<%= resolveImgURL(theme.image_dir,theme.author.gravatar) %>" alt="<%= theme.author.name %>"></a>
    			<span><%= theme.author.name %></span>
    		</div>
    	<%}%>
    	<% for( var items in theme.sidebar){ %>
    		<ul class="buttons">
    			<% for( var item in theme.sidebar[items]){%>
    				<li>
                        <a <% if( is_remote_url(theme.sidebar[items][item].url) ){%> target="_blank" <%}%> class="<% if (theme.sidebar[items][item].class) { %><%= theme.sidebar[items][item].class %><% } %>" href="<%=theme.sidebar[items][item].url%>">
                            <% if(theme.sidebar[items][item].icon) {%>
                                <i class="iconfont icon-<%=theme.sidebar[items][item].icon%>" title="<%=__(theme.sidebar[items][item].title)%>"></i>
                            <%}%>
                            <span><%=__(theme.sidebar[items][item].title)%></span>
                        </a>
                    </li>
    			<%}%>
    		</ul>
    	<%}%>
    </div>
</nav>
<% if (theme.swiftype_install_key) { %>
    <script type="text/javascript">
          (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
          (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
          e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
          })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

          _st('install','<%= theme.swiftype_install_key %>','2.0.0');
    </script>
<% } %>