let assert = require('assert') let XDate = require('xdate') return async (env, head, body, scripts) => { //let cart = await _require('/online_store/cart.jst') let globals = await env.site.get_json('/_config/globals.json') //let icon_cart_small = await env.site.get_min_svg('/_svg/icon_cart_small.svg') let icon_search_mono = await env.site.get_min_svg('/_svg/icon_search_mono.svg') let logo_large = await env.site.get_min_svg('/_svg/logo_large.svg') let menu = await env.site.get_menu('/_menu.json') let page = await _require('/page.jst') //let session = await _require('/session.jst') // initialize env.sessions, env.session_key, env.session //await session(env) // initialize env.cart //await cart(env) await page( env, // head async _out => { // extract top-level directory name assert(env.parsed_url.pathname.slice(0, 1) === '/') let index = env.parsed_url.pathname.indexOf('/', 1) let dir = index === -1 ? '' : env.parsed_url.pathname.slice(1, index) title { _out.push( globals.site_title + ': ' + ( dir.length === 0 ? 'Home' : menu.entries[menu.index[dir]].name ) ) } await head(_out) }, // body async _out => { // extract top-level directory name assert(env.parsed_url.pathname.slice(0, 1) === '/') let index = env.parsed_url.pathname.indexOf('/', 1) let dir = index === -1 ? '' : env.parsed_url.pathname.slice(1, index) div.container { div.row.align-items-center.py-3 { div.col-sm-8 { _out.push(logo_large) } div.'col-sm-4' { //div { // let signed_in = // Object.prototype.hasOwnProperty.call(env.session, 'account') // span#signed-in-status { // if (signed_in) // `Signed in as ${env.session.account}.` // else // 'Browsing as guest.' // } // ' ' // if (signed_in) // a#sign-in(href="" hidden="") {'Sign in'} // else // a#sign-in(href="") {'Sign in'} // ' ' // if (signed_in) // a#sign-out(href="") {'Sign out'} // else // a#sign-out(href="" hidden="") {'Sign out'} //} //p {} form/*.form-inline*/(action="/search/index.html") { div.input-group { input.form-control(name="query" type="text" placeholder="Search" aria-describedby="search-button") {} div.input-group-append { button.btn.btn-outline-secondary#search-button(type="submit") { _out.push(icon_search_mono) } } } } } //div.'col-sm-1'.vbottom { // // a nested div is used to avoid hover colour on the padding // div.nav-li-a(style="text-align: center;") { // a(href="/online_store/view_cart/index.html") { // div.cart-icon { // _out.push(icon_cart_small) // } // div.cart-number { // div.cart-circle { // `${(env.cart.items || []).length}` // } // } // } // } //} } } nav.navbar.navbar-expand-lg.navbar-dark.bg-primary { div.container { //a.navbar-brand(href="#") {'Navbar'} //' ' button.navbar-toggler(type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation") { span.navbar-toggler-icon {} } div.collapse.navbar-collapse#navbarSupportedContent { ul.navbar-nav.mr-auto { if (dir.length === 0) li.nav-item.active { a.nav-link(href="/index.html") { 'Home' span.sr-only {' (current)'} } } else li.nav-item { a.nav-link(href="/index.html") {'Home'} } let entries = menu.entries for (let i = 0; i < entries.length; ++i) if (entries[i].navbar) if (entries[i].dir === dir) li.nav-item.active { a.nav-link(href=`/${entries[i].dir}/index.html`) { `${entries[i].name}` span.sr-only {' (current)'} } } else li.nav-item { a.nav-link(href=`/${entries[i].dir}/index.html`) { `${entries[i].name}` } } //li.nav-item.dropdown { // a.nav-link.dropdown-toggle#navbarDropdown(href="#" role="button" data-toggle="dropdown" aria-expanded="false") { // 'Dropdown' // } // div.dropdown-menu(aria-labelledby="navbarDropdown") { // a.dropdown-item(href="#") { // 'Action' // } // ' ' // a.dropdown-item(href="#") { // 'Another action' // } // div.dropdown-divider {} // a.dropdown-item(href="#") { // 'Something else here' // } // } //} //li.nav-item { // a.nav-link.disabled { // 'Disabled' // } //} } ul.navbar-nav.ml-auto { li.nav-item { a.nav-link#give-feedback(href="") {'Give feedback'} } } } } } div.container { await body(_out) } footer { div.container { a(rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/") { img(alt="Creative Commons License" style="border-width:0;" src="/images/by-sa_3.0_88x31.png") {} } p { 'This website is ' a(href="https://git.ndcode.org/public/ndcode_site.git") { 'open source' } ' and licensed under a ' a(rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/") { 'Creative Commons Attribution-ShareAlike 3.0 Unported License' } '.' } p {'Example code fragments embedded within the text are placed in the public domain unless otherwise noted.'} p {`Copyright © ${new XDate().getUTCFullYear()} ${globals.copyright}.`} } } // hidden part //div#sign-in-modal.modal.fade(role="dialog") { // div.modal-dialog { // div.modal-content { // div.modal-header { // span.h4.modal-title {'Sign in'} // } // div.modal-body { // form#sign-in-form(method="post" action="/sign_in.json" role="form") { // div.row { // div.col-md-12 { // div.form-group { // label(for="sign-in-form-email") {'Email'} // input.form-control#sign-in-form-email(type="text" name="email" placeholder="Please enter your email address" required="required" data-error="Email address is required.") {} // div.help-block.with-errors {} // } // } // } // div.row { // div.col-md-12 { // div.form-group { // label(for="sign-in-form-password") {'Password'} // input.form-control#sign-in-form-password(type="password" name="password" required="required" placeholder="Please enter your password" data-error="Password is required.") {} // div.help-block.with-errors {} // } // } // } // input.btn.btn-success.btn-send(style="display: none;" type="submit" value="Sign in") {} // } // p { // 'No account yet? ' // a(href="/my_account/sign_up/index.html") {'Sign up'} // } // p { // 'Forgot password? ' // a(href="/my_account/password_reset/index.html") {'Password reset'} // } // } // div.modal-footer { // button.btn.btn-primary(type="submit" form="sign-in-form") { // 'Sign in' // } // button.btn.btn-outline-secondary(type="button" data-dismiss="modal") { // 'Cancel' // } // } // } // } //} div#feedback-modal.modal.fade(role="dialog") { div.modal-dialog { div.modal-content { div.modal-header { span.h4.modal-title {'Give feedback'} } div.modal-body { p { 'Did you notice something not quite right, or just want to share your impression of this page?' } form#feedback-form(method="post" action="/feedback.html" role="form") { div.row { div.col-md-12 { div.form-group { label(for="feedback-form-message") {'Message *'} textarea.form-control#feedback-form-message(name="message" placeholder="Please tell us your thoughts" rows="4" required="required" data-error="Please, leave us a message.") {} div.help-block.with-errors {} } } } p {} // fix this later div.row { div.col-md-12 { p.text-muted { strong {'*'} 'These fields are required.' //'Contact form template by ' //a(href="https://bootstrapious.com/p/how-to-build-a-working-bootstrap-feedback-form" target="_blank") {'Bootstrapious'} //'.' } } } input.btn.btn-success.btn-send(style="display: none;" type="submit" value="Send message") {} } } div.modal-footer { button.btn.btn-primary(type="submit" form="feedback-form") { 'Submit' } button.btn.btn-outline-secondary(type="button" data-dismiss="modal") { 'Cancel' } } } } } div#message-modal.modal.fade(role="dialog") { div.modal-dialog { div.modal-content { div.modal-header { span.h4.modal-title {'Message'} } div.modal-body { p#message-modal-message {} } div.modal-footer { button.btn.btn-outline-secondary(type="button" data-dismiss="modal") { 'Close' } } } } } }, // scripts async _out => { //script(src="/js/sha256.js") {} script { //function get_cookie(name) { // let entries = document.cookie.split(';'); // for (let i = 0; i < entries.length; ++i) { // let fields = entries[i].split('='); // if (fields[0].trim() === name) // return decodeURIComponent(fields[1]); // } // return undefined; //} //// this function can be overridden in a further script //function sign_in_out(status) { //} $(document).ready( () => { //// sign in form //$('#sign-in').click( // () => { // $('#sign-in-form-email').text('') // $('#sign-in-form-password').text('') // $('#sign-in-modal').modal('show') // return false // } //) //$('#sign-in-modal').on( // 'shown.bs.modal', // () => { // $('#sign-in-form-email').focus() // } //) //// when sign in form is submitted, do not reload the page //$(document).on( // 'submit', // '#sign-in-form', // e => { // e.preventDefault() // $.ajax( // { // url: '/my_account/sign_in.json', // type: 'POST', // data: { // email: $('#sign-in-form-email').val(), // password: sha256( // get_cookie('session_key') + // $('#sign-in-form-password').val() // ).toString('hex') // }, // success: (data, textStatus, jqXHR) => { // $('#sign-in-modal').modal('hide') // switch (data.result) { // case 1: // success // $('#signed-in-status').text(data.signed_in_status) // $('#sign-in').hide() // $('#sign-out').show() // sign_in_out(true) // notify navbar caller // break // case 2: // redirect // location.href = data.redirect_href // break // } // $('#message-modal-message').text(data.message) // $('#message-modal').modal('show') // }, // error: (jqXHR, textStatus, errorThrown) => { // $('#sign-in-modal').modal('hide') // $('#message-modal-message').text(errorThrown) // $('#message-modal').modal('show') // } // } // ) // } //) //// sign out button //$('#sign-out').click( // () => { // $.ajax( // { // url: '/my_account/sign_out.json', // type: 'GET', // success: (data, textStatus, jqXHR) => { // if (data.result) { // $('#signed-in-status').text(data.signed_in_status) // $('#sign-in').show() // $('#sign-out').hide() // sign_in_out(false) // notify navbar caller // } // $('#message-modal-message').text(data.message) // $('#message-modal').modal('show') // }, // error: (jqXHR, textStatus, errorThrown) => { // $('#message-modal-message').text(errorThrown) // $('#message-modal').modal('show') // } // } // ) // return false // } //) // feedback form $('#give-feedback').click( () => { $('#feedback-form-message').text('') $('#feedback-modal').modal('show') return false } ) $('#feedback-modal').on( 'shown.bs.modal', () => { $('#feedback-form-message').focus() } ) // when feedback form is submitted, do not reload the page $(document).on( 'submit', '#feedback-form', e => { e.preventDefault() $.ajax( { url: '/feedback.html', type: 'POST', data: { page: window.location.href, message: $('#feedback-form-message').val() }, success: (data, textStatus, jqXHR) => { $('#feedback-modal').modal('hide') $('#message-modal-message').text(data) $('#message-modal').modal('show') }, error: (jqXHR, textStatus, errorThrown) => { $('#feedback-modal').modal('hide') $('#message-modal-message').text(errorThrown) $('#message-modal').modal('show') } } ) } ) } ) } await scripts(_out) } ) }