Add /_lib/get_globals.jst
authorNick Downing <nick@ndcode.org>
Sun, 23 Jan 2022 08:36:45 +0000 (19:36 +1100)
committerNick Downing <nick@ndcode.org>
Sun, 23 Jan 2022 08:43:24 +0000 (19:43 +1100)
_lib/get_globals.jst [new file with mode: 0644]
_lib/navbar.jst
api/account/password_reset.json.jst
api/account/sign_up/send_email_verification_link.json.jst
api/contact/send_enquiry.json.jst
api/feedback.json.jst

diff --git a/_lib/get_globals.jst b/_lib/get_globals.jst
new file mode 100644 (file)
index 0000000..73cd7f3
--- /dev/null
@@ -0,0 +1,5 @@
+return async (env, transaction) => {
+  return /*await*/ (
+    await transaction.get({})
+  ).get('globals', {})
+}
index 9f200e9..b7c32d0 100644 (file)
@@ -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}.`}
         }
       }
 
index f22a687..080a97b 100644 (file)
@@ -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')
index 314f174..50e40e0 100644 (file)
@@ -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')
index 127bc7c..da3ff60 100644 (file)
@@ -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')
 
index e13452c..79a26bd 100644 (file)
@@ -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')