From 4120d940fb6cfb1783ead3b824e9f82e23396160 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sat, 11 Nov 2023 10:24:18 +0000 Subject: [PATCH] Move site specific layouts and JS to the site folders --- assets/js/site.js | 38 ++++++++++++++++ .../{membership.md => membership/index.md} | 4 +- content/thank_you.md | 1 - .../layouts => layouts}/page/calendar.html | 0 .../lhs/layouts => layouts}/page/home.html | 0 .../page/membership.html | 4 ++ .../shortcodes/facilities.html | 0 .../shortcodes/printers.html | 0 themes/lhs/assets/js/site.js | 44 +------------------ themes/lhs/assets/js/theme.js | 6 +++ themes/lhs/layouts/partials/foot.html | 4 +- 11 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 assets/js/site.js rename content/{membership.md => membership/index.md} (96%) rename {themes/lhs/layouts => layouts}/page/calendar.html (100%) rename {themes/lhs/layouts => layouts}/page/home.html (100%) rename themes/lhs/layouts/shortcodes/memberships.html => layouts/page/membership.html (94%) rename {themes/lhs/layouts => layouts}/shortcodes/facilities.html (100%) rename {themes/lhs/layouts => layouts}/shortcodes/printers.html (100%) create mode 100644 themes/lhs/assets/js/theme.js diff --git a/assets/js/site.js b/assets/js/site.js new file mode 100644 index 0000000..8bd0dab --- /dev/null +++ b/assets/js/site.js @@ -0,0 +1,38 @@ +function titleCase(word) { + return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase(); +} + +$(document).ready(function () { + if ($('span#hackspace-status').length) { + $.getJSON("https://api.leighhack.org/space.json", function (data) { + if (data.state.open) { + message = 'Open' + if ('message' in data.state) { + message = message + ': ' + data.state.message; + } + $('span#hackspace-status').html(message); + $('div#hackspace-open').addClass('is-success'); + } else { + $('span#hackspace-status').html('Closed'); + } + }); + } + + // 'printers' shortcode + if ($('div#printer-status').length) { + $.getJSON("https://api.leighhack.org/space.json", function (data) { + if (data.sensors.ext_3d_printers.length) { + + // sort the printers + const printers = Array.from(data.sensors.ext_3d_printers).sort((a, b) => a['name'].localeCompare(b['name'])); + + printers.forEach(function (val, indx) { + var obj = $($("template#printer-block").html()); + obj.find('#printer-name').html(val['name']); + obj.find('#printer-status').html(titleCase(val['state'])); + $('div#printer-status').append(obj); + }); + } + }); + } +}); diff --git a/content/membership.md b/content/membership/index.md similarity index 96% rename from content/membership.md rename to content/membership/index.md index ed65cef..f69e92b 100644 --- a/content/membership.md +++ b/content/membership/index.md @@ -2,6 +2,8 @@ title: Join Leigh Hackspace subtitle: Become part of our community. hero_image: /images/hero-img.svg +layout: membership +show_cta: False --- Leigh Hackspace is a social enterprise created for the benefit of our members and the wider Leigh community. We depend on memberships and grants to operate, and in return we offer members access to the hackspace's facilities and resources. @@ -9,6 +11,4 @@ Being a member is being part of a social making and learning community. Our memb We suggest that you [visit the hackspace]({{< ref "/visit" >}}) in person before you commit to be a member. This will allow you to see the space, understand what is available, and how it can work for you. We have further information on our [wiki](https://wiki.leighhack.org/membership/joining/). -{{< memberships >}} - All memberships are collected on the 1st of the month, but if you wish to arrange an alternative date then please [contact us](mailto:info@leighhack.org). \ No newline at end of file diff --git a/content/thank_you.md b/content/thank_you.md index 36a14ee..982eb1c 100644 --- a/content/thank_you.md +++ b/content/thank_you.md @@ -1,7 +1,6 @@ --- title: "Thank You, and Welcome!" subtitle: "You're now a member." -draft: false show_cta: false --- diff --git a/themes/lhs/layouts/page/calendar.html b/layouts/page/calendar.html similarity index 100% rename from themes/lhs/layouts/page/calendar.html rename to layouts/page/calendar.html diff --git a/themes/lhs/layouts/page/home.html b/layouts/page/home.html similarity index 100% rename from themes/lhs/layouts/page/home.html rename to layouts/page/home.html diff --git a/themes/lhs/layouts/shortcodes/memberships.html b/layouts/page/membership.html similarity index 94% rename from themes/lhs/layouts/shortcodes/memberships.html rename to layouts/page/membership.html index 8ec2f55..de47de4 100644 --- a/themes/lhs/layouts/shortcodes/memberships.html +++ b/layouts/page/membership.html @@ -1,3 +1,6 @@ +{{ define "content" }} +{{ .Content }} +
{{- with $.Site.Data.memberships.membership_levels }} {{ range . -}} @@ -17,3 +20,4 @@ {{ end }} {{- end }}
+{{ end }} diff --git a/themes/lhs/layouts/shortcodes/facilities.html b/layouts/shortcodes/facilities.html similarity index 100% rename from themes/lhs/layouts/shortcodes/facilities.html rename to layouts/shortcodes/facilities.html diff --git a/themes/lhs/layouts/shortcodes/printers.html b/layouts/shortcodes/printers.html similarity index 100% rename from themes/lhs/layouts/shortcodes/printers.html rename to layouts/shortcodes/printers.html diff --git a/themes/lhs/assets/js/site.js b/themes/lhs/assets/js/site.js index a5843cd..ec49098 100644 --- a/themes/lhs/assets/js/site.js +++ b/themes/lhs/assets/js/site.js @@ -1,43 +1 @@ -function titleCase(word) { - return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase(); -} - -$(document).ready(function () { - $(".navbar-burger").click(function () { - $(".navbar-burger").toggleClass("is-active"); - $(".navbar-menu").toggleClass("is-active"); - }); - - if ($('span#hackspace-status').length) { - $.getJSON("https://api.leighhack.org/space.json", function (data) { - if (data.state.open) { - message = 'Open' - if ('message' in data.state) { - message = message + ': ' + data.state.message; - } - $('span#hackspace-status').html(message); - $('div#hackspace-open').addClass('is-success'); - } else { - $('span#hackspace-status').html('Closed'); - } - }); - } - - // 'printers' shortcode - if ($('div#printer-status').length) { - $.getJSON("https://api.leighhack.org/space.json", function (data) { - if (data.sensors.ext_3d_printers.length) { - - // sort the printers - const printers = Array.from(data.sensors.ext_3d_printers).sort((a, b) => a['name'].localeCompare(b['name'])); - - printers.forEach(function (val, indx){ - var obj = $($("template#printer-block").html()); - obj.find('#printer-name').html(val['name']); - obj.find('#printer-status').html(titleCase(val['state'])); - $('div#printer-status').append(obj); - }); - } - }); - } -}); +// This should be overridden in the site assets folder with any JS you need \ No newline at end of file diff --git a/themes/lhs/assets/js/theme.js b/themes/lhs/assets/js/theme.js new file mode 100644 index 0000000..d796c4d --- /dev/null +++ b/themes/lhs/assets/js/theme.js @@ -0,0 +1,6 @@ +$(document).ready(function () { + $(".navbar-burger").click(function () { + $(".navbar-burger").toggleClass("is-active"); + $(".navbar-menu").toggleClass("is-active"); + }); +}); diff --git a/themes/lhs/layouts/partials/foot.html b/themes/lhs/layouts/partials/foot.html index ccebd24..690dc04 100644 --- a/themes/lhs/layouts/partials/foot.html +++ b/themes/lhs/layouts/partials/foot.html @@ -1,6 +1,8 @@ + +{{ $theme := resources.Get "js/theme.js" }} {{ $site := resources.Get "js/site.js" }} -{{ $js := slice $site | resources.Concat "js/bundle.js" | resources.Minify }} +{{ $js := slice $site $theme | resources.Concat "js/bundle.js" | resources.Minify }} {{ $secureJS := $js | resources.Fingerprint "sha512" }} \ No newline at end of file