1 let assert = require('assert')
2 let XDate = require('xdate')
4 return async (env, head, body, scripts) => {
5 //let cart = await _require('/online_store/cart.jst')
6 let globals = await env.site.get_json('/_config/globals.json')
7 //let icon_cart_small = await env.site.get_min_svg('/_svg/icon_cart_small.svg')
8 let icon_search_mono = await env.site.get_min_svg('/_svg/icon_search_mono.svg')
9 let logo_large = await env.site.get_min_svg('/_svg/logo_large.svg')
10 let menu = await env.site.get_menu('/_menu.json')
11 let page = await _require('/page.jst')
12 //let session = await _require('/session.jst')
14 // initialize env.sessions, env.session_key, env.session
17 // initialize env.cart
24 // extract top-level directory name
25 assert(env.parsed_url.pathname.slice(0, 1) === '/')
26 let index = env.parsed_url.pathname.indexOf('/', 1)
27 let dir = index === -1 ? '' : env.parsed_url.pathname.slice(1, index)
31 globals.site_title + ': ' + (
34 menu.entries[menu.index[dir]].name
43 // extract top-level directory name
44 assert(env.parsed_url.pathname.slice(0, 1) === '/')
45 let index = env.parsed_url.pathname.indexOf('/', 1)
46 let dir = index === -1 ? '' : env.parsed_url.pathname.slice(1, index)
48 div(style="padding-left: calc(100vw - 100%);") {
49 div.container(style="margin-top: 5px; margin-bottom: 5px;") {
51 div.'col-sm-8'.vbottom {
54 div.'col-sm-4'.vbottom(style="padding-bottom: 15px;") {
57 // Object.prototype.hasOwnProperty.call(env.session, 'account')
58 // span#signed-in-status {
60 // `Signed in as ${env.session.account}.`
62 // 'Browsing as guest.'
66 // a#sign-in(href="" hidden="") {'Sign in'}
68 // a#sign-in(href="") {'Sign in'}
71 // a#sign-out(href="") {'Sign out'}
73 // a#sign-out(href="" hidden="") {'Sign out'}
77 form(action="/search/index.html") {
79 input.form-control(name="query" type="text" placeholder="Search") {}
80 span.input-group-btn {
81 button.btn.btn-default(type="submit") {
82 _out.push(icon_search_mono)
88 //div.'col-sm-1'.vbottom {
89 // // a nested div is used to avoid hover colour on the padding
90 // div.nav-li-a(style="text-align: center;") {
91 // a(href="/online_store/view_cart/index.html") {
93 // _out.push(icon_cart_small)
97 // `${(env.cart.items || []).length}`
106 nav.navbar.navbar-default(style="margin-top: 0px; margin-bottom: 0px;") {
107 div(style="padding-left: calc(100vw - 100%);") {
108 div.container { //-fluid") {
109 // Brand and toggle get grouped for better mobile display
111 button.navbar-toggle.collapsed(type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false") {
112 span.sr-only {'Toggle navigation'}
117 //a.navbar-brand(href="#") {'Brand'}
120 // Collect the nav links, forms, and other content for toggling
121 div.collapse.navbar-collapse#bs-example-navbar-collapse-1 {
123 if (dir.length === 0)
125 a(href="/index.html") {
127 span.sr-only {'(current)'}
132 a(href="/index.html") {
136 let entries = menu.entries
137 for (let i = 0; i < entries.length; ++i)
138 if (entries[i].navbar)
139 if (entries[i].dir === dir)
141 a(href=`/${entries[i].dir}/index.html`) {
143 span.sr-only {'(current)'}
148 a(href=`/${entries[i].dir}/index.html`) {
153 ul.nav.navbar-nav.navbar-right {
155 a#give-feedback(href="") {'Give feedback'}
162 div(style="padding-left: calc(100vw - 100%); margin-bottom: 50px;") {
167 div.footer(style="padding-left: calc(100vw - 100%);") {
168 div.container { //-fluid") {
169 a(rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/") {
170 img(alt="Creative Commons License" style="border-width:0" src="/images/by-sa_3.0_88x31.png") {}
174 a(href="https://git.ndcode.org/public/ndcode_site.git") {
177 ' and licensed under a '
178 a(rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/") {
179 'Creative Commons Attribution-ShareAlike 3.0 Unported License'
184 p {'Example code fragments embedded within the text are placed in the public domain unless otherwise noted.'}
186 p {`Copyright © ${new XDate().getUTCFullYear()} ${globals.copyright}.`}
191 //div#sign-in-modal.modal.fade(role="dialog") {
192 // div.modal-dialog {
193 // div.modal-content {
194 // div.modal-header {
195 // button.close(type="button" data-dismiss="modal") {
203 // form#sign-in-form(method="post" action="/sign_in.json" role="form") {
207 // label(for="sign-in-form-email") {'Email'}
208 // 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.") {}
209 // div.help-block.with-errors {}
216 // label(for="sign-in-form-password") {'Password'}
217 // input.form-control#sign-in-form-password(type="password" name="password" required="required" placeholder="Please enter your password" data-error="Password is required.") {}
218 // div.help-block.with-errors {}
222 // input.btn.btn-success.btn-send(style="display: none;" type="submit" value="Sign in") {}
226 // 'No account yet? '
227 // a(href="/my_account/sign_up/index.html") {'Sign up'}
231 // 'Forgot password? '
232 // a(href="/my_account/password_reset/index.html") {'Password reset'}
235 // div.modal-footer {
236 // button.btn.btn-primary(type="submit" form="sign-in-form") {
239 // button.btn.btn-default(type="button" data-dismiss="modal") {
247 div#feedback-modal.modal.fade(role="dialog") {
251 button.close(type="button" data-dismiss="modal") {
260 'Did you notice something not quite right, or just want to share your impression of this page?'
262 form#feedback-form(method="post" action="/feedback.html" role="form") {
266 label(for="feedback-form-message") {'Message *'}
267 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.") {}
268 div.help-block.with-errors {}
272 p {} // fix this later
277 'These fields are required.'
278 //'Contact form template by '
279 //a(href="https://bootstrapious.com/p/how-to-build-a-working-bootstrap-feedback-form" target="_blank") {'Bootstrapious'}
284 input.btn.btn-success.btn-send(style="display: none;" type="submit" value="Send message") {}
288 button.btn.btn-primary(type="submit" form="feedback-form") {
291 button.btn.btn-default(type="button" data-dismiss="modal") {
299 div#message-modal.modal.fade(role="dialog") {
303 button.close(type="button" data-dismiss="modal") {
311 p#message-modal-message {}
314 button.btn.btn-default(type="button" data-dismiss="modal") {
324 //script(src="/js/sha256.js") {}
327 //function get_cookie(name) {
328 // let entries = document.cookie.split(';');
329 // for (let i = 0; i < entries.length; ++i) {
330 // let fields = entries[i].split('=');
331 // if (fields[0].trim() === name)
332 // return decodeURIComponent(fields[1]);
337 //// this function can be overridden in a further script
338 //function sign_in_out(status) {
344 //$('#sign-in').click(
346 // $('#sign-in-form-email').text('')
347 // $('#sign-in-form-password').text('')
348 // $('#sign-in-modal').modal('show')
352 //$('#sign-in-modal').on(
355 // $('#sign-in-form-email').focus()
358 //// when sign in form is submitted, do not reload the page
363 // e.preventDefault()
366 // url: '/my_account/sign_in.json',
369 // email: $('#sign-in-form-email').val(),
371 // get_cookie('session_key') +
372 // $('#sign-in-form-password').val()
375 // success: (data, textStatus, jqXHR) => {
376 // $('#sign-in-modal').modal('hide')
377 // switch (data.result) {
378 // case 1: // success
379 // $('#signed-in-status').text(data.signed_in_status)
380 // $('#sign-in').hide()
381 // $('#sign-out').show()
382 // sign_in_out(true) // notify navbar caller
384 // case 2: // redirect
385 // location.href = data.redirect_href
388 // $('#message-modal-message').text(data.message)
389 // $('#message-modal').modal('show')
391 // error: (jqXHR, textStatus, errorThrown) => {
392 // $('#sign-in-modal').modal('hide')
393 // $('#message-modal-message').text(errorThrown)
394 // $('#message-modal').modal('show')
402 //$('#sign-out').click(
406 // url: '/my_account/sign_out.json',
408 // success: (data, textStatus, jqXHR) => {
409 // if (data.result) {
410 // $('#signed-in-status').text(data.signed_in_status)
411 // $('#sign-in').show()
412 // $('#sign-out').hide()
413 // sign_in_out(false) // notify navbar caller
415 // $('#message-modal-message').text(data.message)
416 // $('#message-modal').modal('show')
418 // error: (jqXHR, textStatus, errorThrown) => {
419 // $('#message-modal-message').text(errorThrown)
420 // $('#message-modal').modal('show')
429 $('#give-feedback').click(
431 $('#feedback-form-message').text('')
432 $('#feedback-modal').modal('show')
436 $('#feedback-modal').on(
439 $('#feedback-form-message').focus()
442 // when feedback form is submitted, do not reload the page
450 url: '/feedback.html',
453 page: window.location.href,
454 message: $('#feedback-form-message').val()
456 success: (data, textStatus, jqXHR) => {
457 $('#feedback-modal').modal('hide')
458 $('#message-modal-message').text(data)
459 $('#message-modal').modal('show')
461 error: (jqXHR, textStatus, errorThrown) => {
462 $('#feedback-modal').modal('hide')
463 $('#message-modal-message').text(errorThrown)
464 $('#message-modal').modal('show')