From 37807e008bab8dd47b33728241b61fa78ef29c65 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Sun, 30 May 2021 19:30:06 -0400 Subject: [PATCH] add content-type and access-control headers to hit function response --- assets/js/counter.js | 1 + assets/js/vendor/twemoji.js | 2 +- assets/sass/pages/_single.scss | 3 ++- functions/hits.js | 4 ++++ layouts/_default/single.html | 14 ++++++++------ layouts/partials/scripts/_bundle.html | 12 ++++++------ 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/assets/js/counter.js b/assets/js/counter.js index 4742697f..da157a0b 100644 --- a/assets/js/counter.js +++ b/assets/js/counter.js @@ -3,6 +3,7 @@ var wrapper = document.getElementById("meta-hits"); if (wrapper) { + // javascript is enabled so show the loading indicator wrapper.style.display = "inline-block"; // deduce a consistent identifier for this page, no matter the URL diff --git a/assets/js/vendor/twemoji.js b/assets/js/vendor/twemoji.js index f5476097..fa781cee 100644 --- a/assets/js/vendor/twemoji.js +++ b/assets/js/vendor/twemoji.js @@ -12,7 +12,7 @@ ///////////////////////// // default assets url, by default will be Twitter Inc. CDN - base: '{{ "vendor/emoji/" | absURL }}', + base: '/vendor/emoji/', // default assets file extensions, by default '.png' ext: '.svg', diff --git a/assets/sass/pages/_single.scss b/assets/sass/pages/_single.scss index 1f01f20d..75549058 100644 --- a/assets/sass/pages/_single.scss +++ b/assets/sass/pages/_single.scss @@ -19,7 +19,8 @@ div.layout-single { color: inherit; } - > span { + > div { + display: inline-block; margin-right: 1.25em; white-space: nowrap; diff --git a/functions/hits.js b/functions/hits.js index bf715eb1..917b0c52 100644 --- a/functions/hits.js +++ b/functions/hits.js @@ -34,9 +34,13 @@ exports.handler = async (event) => { return { statusCode: 200, headers: { + "Content-Type": "application/json; charset=utf-8", "Cache-Control": "private, no-cache, no-store, must-revalidate", Expires: "0", Pragma: "no-cache", + "Access-Control-Allow-Methods": "GET", + "Access-Control-Allow-Origin": "*", + "x-fauna-ts": result.ts.toString().slice(0, -3), }, body: JSON.stringify({ slug: result.data.slug, diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 51b4c9d5..8a0852fc 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -2,19 +2,21 @@
- + + {{ with .Scratch.Get "sourceURL" }} - + {{ end }} -

{{ .Title | markdownify }}

diff --git a/layouts/partials/scripts/_bundle.html b/layouts/partials/scripts/_bundle.html index 91b3e75d..befd461b 100644 --- a/layouts/partials/scripts/_bundle.html +++ b/layouts/partials/scripts/_bundle.html @@ -1,15 +1,15 @@ {{/* only parse and append analytics script on production site */}} {{- $includeProdScripts := eq hugo.Environment "production" -}} -{{- $twemoji := resources.Get "js/vendor/twemoji.js" | resources.ExecuteAsTemplate "js/vendor/twemoji.js" . -}} {{- $counter := resources.Get "js/counter.js" -}} +{{- $twemoji := resources.Get "js/vendor/twemoji.js" -}} -{{- $bundle := slice $twemoji $counter -}} +{{- $bundle := slice $counter $twemoji -}} -{{- if $includeProdScripts }} - {{- $fathom := resources.Get "js/fathom.js" | resources.ExecuteAsTemplate "js/fathom.js" . }} - {{- $bundle = $bundle | append $fathom }} -{{- end }} +{{- if $includeProdScripts -}} + {{- $fathom := resources.Get "js/fathom.js" -}} + {{- $bundle = $bundle | append $fathom -}} +{{- end -}} {{- $js := $bundle | resources.Concat "/js/app.js" -}}