From fda97b0a24464398eccb7c2834fa2eeb28ba4e63 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Sun, 23 Jan 2022 19:36:45 +1100 Subject: [PATCH] Add /_lib/get_globals.jst --- _lib/get_globals.jst | 5 +++ _lib/navbar.jst | 35 +++++++------------ api/account/password_reset.json.jst | 12 ++++--- .../send_email_verification_link.json.jst | 12 ++++--- api/contact/send_enquiry.json.jst | 14 +++++--- api/feedback.json.jst | 9 +++-- 6 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 _lib/get_globals.jst diff --git a/_lib/get_globals.jst b/_lib/get_globals.jst new file mode 100644 index 0000000..73cd7f3 --- /dev/null +++ b/_lib/get_globals.jst @@ -0,0 +1,5 @@ +return async (env, transaction) => { + return /*await*/ ( + await transaction.get({}) + ).get('globals', {}) +} diff --git a/_lib/navbar.jst b/_lib/navbar.jst index 9f200e9..b7c32d0 100644 --- a/_lib/navbar.jst +++ b/_lib/navbar.jst @@ -3,6 +3,7 @@ let XDate = require('xdate') return async (env, head, body, scripts) => { //let cart = await _require('/online_store/cart.jst') + let get_globals = await _require('/_lib/get_globals.jst') let get_session = await _require('/_lib/get_session.jst') //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') @@ -14,10 +15,14 @@ return async (env, head, body, scripts) => { //await cart(env) let transaction = await env.site.Transaction() - let signed_in_as + let signed_in_as, site_title, copyright try { let session = await get_session(env, transaction) signed_in_as = session.get_json('signed_in_as', null) + + let globals = await get_globals(env, transaction) + site_title = globals.get_json('site_title') + copyright = globals.get_json('copyright') } finally { transaction.rollback() @@ -33,18 +38,11 @@ return async (env, head, body, scripts) => { let dir = index === -1 ? '' : env.parsed_url.pathname.slice(1, index) title { - let transaction = await env.site.database.Transaction() - try { - let globals = await (await transaction.get({})).get('globals') - ;`${await globals.get_json('site_title')}: ${ - dir.length === 0 ? - 'Home' : - menu.entries[menu.index[dir]].name - }` - } - finally { - transaction.rollback() - } + `${site_title}: ${ + dir.length === 0 ? + 'Home' : + menu.entries[menu.index[dir]].name + }` } await head(_out) @@ -209,16 +207,7 @@ return async (env, head, body, scripts) => { p {'Example code fragments embedded within the text are placed in the public domain unless otherwise noted.'} - p { - let transaction = await env.site.database.Transaction() - try { - let globals = await (await transaction.get({})).get('globals') - ;`Copyright © ${new XDate().getUTCFullYear()} ${await globals.get('copyright')}.` - } - finally { - transaction.rollback() - } - } + p {`Copyright © ${new XDate(env.now).getUTCFullYear()} ${copyright}.`} } } diff --git a/api/account/password_reset.json.jst b/api/account/password_reset.json.jst index f22a687..080a97b 100644 --- a/api/account/password_reset.json.jst +++ b/api/account/password_reset.json.jst @@ -3,8 +3,9 @@ let nodemailer = require('nodemailer') let XDate = require('xdate') return async env => { - let post_request = await _require('/_lib/post_request.jst') + let get_globals = await _require('/_lib/get_globals.jst') let get_session = await _require('/_lib/get_session.jst') + let post_request = await _require('/_lib/post_request.jst') let Problem = await _require('/_lib/Problem.jst') await post_request( @@ -50,11 +51,14 @@ return async env => { {password, link_code, expires: expires.getTime()} ) - let root = await transaction.get({}) nodemailer_noreply = nodemailer.createTransport( - await (await root.get('nodemailer')).get_json('noreply') + await ( + await ( + await transaction.get({}) + ).get('nodemailer') + ).get_json('noreply') ) - let globals = await root.get('globals') + let globals = await get_globals(env, transaction) site_url = await globals.get_json('site_url') noreply_from = await globals.get_json('noreply_from') noreply_signature = await globals.get_json('noreply_signature') diff --git a/api/account/sign_up/send_email_verification_link.json.jst b/api/account/sign_up/send_email_verification_link.json.jst index 314f174..50e40e0 100644 --- a/api/account/sign_up/send_email_verification_link.json.jst +++ b/api/account/sign_up/send_email_verification_link.json.jst @@ -3,8 +3,9 @@ let nodemailer = require('nodemailer') let XDate = require('xdate') return async env => { - let post_request = await _require('/_lib/post_request.jst') + let get_globals = await _require('/_lib/get_globals.jst') let get_session = await _require('/_lib/get_session.jst') + let post_request = await _require('/_lib/post_request.jst') let Problem = await _require('/_lib/Problem.jst') await post_request( @@ -56,11 +57,14 @@ return async env => { {link_code, expires: expires.getTime()} ) - let root = await transaction.get({}) nodemailer_noreply = nodemailer.createTransport( - await (await root.get('nodemailer')).get_json('noreply') + await ( + await ( + await transaction.get({}) + ).get('nodemailer') + ).get_json('noreply') ) - let globals = await root.get('globals') + let globals = await get_globals(env, transaction) site_url = await globals.get_json('site_url') noreply_from = await globals.get_json('noreply_from') noreply_signature = await globals.get_json('noreply_signature') diff --git a/api/contact/send_enquiry.json.jst b/api/contact/send_enquiry.json.jst index 127bc7c..da3ff60 100644 --- a/api/contact/send_enquiry.json.jst +++ b/api/contact/send_enquiry.json.jst @@ -1,9 +1,10 @@ let nodemailer = require('nodemailer') let XDate = require('xdate') -return async env => { - let post_request = await _require('/_lib/post_request.jst') +return async env => {a + let get_globals = await _require('/_lib/get_globals.jst') let get_session = await _require('/_lib/get_session.jst') + let post_request = await _require('/_lib/post_request.jst') let Problem = await _require('/_lib/Problem.jst') await post_request( @@ -36,11 +37,14 @@ return async env => { // initialize env.session_key, set cookie in env.response get_session(env, transaction) - let root = await transaction.get({}) nodemailer_contact = nodemailer.createTransport( - await (await root.get('nodemailer')).get_json('contact') + await ( + await ( + await transaction.get({}) + ).get('nodemailer') + ).get_json('contact') ) - let globals = await root.get('globals') + let globals = await get_globals(env, transaction) contact_from = await globals.get_json('contact_from') contact_to = await globals.get_json('contact_to') diff --git a/api/feedback.json.jst b/api/feedback.json.jst index e13452c..79a26bd 100644 --- a/api/feedback.json.jst +++ b/api/feedback.json.jst @@ -26,11 +26,14 @@ return async env => { // initialize env.session_key, set cookie in env.response await get_session(env, transaction) - let root = await transaction.get({}) nodemailer_feedback = nodemailer.createTransport( - await (await root.get('nodemailer')).get_json('feedback') + await ( + await ( + await transaction.get({}) + ).get('nodemailer') + ).get_json('feedback') ) - let globals = await root.get('globals') + let globals = await get_globals(env, transaction) feedback_from = await globals.get_json('feedback_from') feedback_to = await globals.get_json('feedback_to') -- 2.34.1