1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 17:30:28 -04:00

add content-type and access-control headers to hit function response

This commit is contained in:
Jake Jarvis 2021-05-30 19:30:06 -04:00
parent 03bc26a004
commit 37807e008b
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
6 changed files with 22 additions and 14 deletions

View File

@ -3,6 +3,7 @@
var wrapper = document.getElementById("meta-hits"); var wrapper = document.getElementById("meta-hits");
if (wrapper) { if (wrapper) {
// javascript is enabled so show the loading indicator
wrapper.style.display = "inline-block"; wrapper.style.display = "inline-block";
// deduce a consistent identifier for this page, no matter the URL // deduce a consistent identifier for this page, no matter the URL

View File

@ -12,7 +12,7 @@
///////////////////////// /////////////////////////
// default assets url, by default will be Twitter Inc. CDN // default assets url, by default will be Twitter Inc. CDN
base: '{{ "vendor/emoji/" | absURL }}', base: '/vendor/emoji/',
// default assets file extensions, by default '.png' // default assets file extensions, by default '.png'
ext: '.svg', ext: '.svg',

View File

@ -19,7 +19,8 @@ div.layout-single {
color: inherit; color: inherit;
} }
> span { > div {
display: inline-block;
margin-right: 1.25em; margin-right: 1.25em;
white-space: nowrap; white-space: nowrap;

View File

@ -34,9 +34,13 @@ exports.handler = async (event) => {
return { return {
statusCode: 200, statusCode: 200,
headers: { headers: {
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, no-cache, no-store, must-revalidate", "Cache-Control": "private, no-cache, no-store, must-revalidate",
Expires: "0", Expires: "0",
Pragma: "no-cache", Pragma: "no-cache",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Origin": "*",
"x-fauna-ts": result.ts.toString().slice(0, -3),
}, },
body: JSON.stringify({ body: JSON.stringify({
slug: result.data.slug, slug: result.data.slug,

View File

@ -2,19 +2,21 @@
<div class="layout layout-single"> <div class="layout layout-single">
<article> <article>
<div id="meta"> <div id="meta">
<span id="meta-date"> <div id="meta-date">
<a class="no-underline" href="{{ .Permalink }}" title="{{ .Date.Format "Mon, Jan 2 2006 3:04:05 PM MST" }}">📅 {{ .Date.Format "January 2, 2006" }}</a> <a class="no-underline" href="{{ .Permalink }}" title="{{ .Date.Format "Mon, Jan 2 2006 3:04:05 PM MST" }}">📅 {{ .Date.Format "January 2, 2006" }}</a>
</span> </div>
{{ with .Scratch.Get "sourceURL" }} {{ with .Scratch.Get "sourceURL" }}
<span id="meta-edit"> <div id="meta-edit">
<a class="no-underline" href="{{ . | safeURL }}" title="Edit this post on GitHub" target="_blank" rel="noopener">✏️ Improve This Post</a> <a class="no-underline" href="{{ . | safeURL }}" title="Edit this post on GitHub" target="_blank" rel="noopener">✏️ Improve This Post</a>
</span> </div>
{{ end }} {{ end }}
<span id="meta-hits" style="display:none;">
<div id="meta-hits" style="display: none;">
👀 👀
<div id="hit-spinner" class="spinner"><div class="spin-bounce1"></div><div class="spin-bounce2"></div><div class="spin-bounce3"></div></div> <div id="hit-spinner" class="spinner"><div class="spin-bounce1"></div><div class="spin-bounce2"></div><div class="spin-bounce3"></div></div>
<span id="hit-counter"></span> <span id="hit-counter"></span>
</span> </div>
</div> </div>
<h1 class="title"><a class="no-underline" href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h1> <h1 class="title"><a class="no-underline" href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h1>

View File

@ -1,15 +1,15 @@
{{/* only parse and append analytics script on production site */}} {{/* only parse and append analytics script on production site */}}
{{- $includeProdScripts := eq hugo.Environment "production" -}} {{- $includeProdScripts := eq hugo.Environment "production" -}}
{{- $twemoji := resources.Get "js/vendor/twemoji.js" | resources.ExecuteAsTemplate "js/vendor/twemoji.js" . -}}
{{- $counter := resources.Get "js/counter.js" -}} {{- $counter := resources.Get "js/counter.js" -}}
{{- $twemoji := resources.Get "js/vendor/twemoji.js" -}}
{{- $bundle := slice $twemoji $counter -}} {{- $bundle := slice $counter $twemoji -}}
{{- if $includeProdScripts }} {{- if $includeProdScripts -}}
{{- $fathom := resources.Get "js/fathom.js" | resources.ExecuteAsTemplate "js/fathom.js" . }} {{- $fathom := resources.Get "js/fathom.js" -}}
{{- $bundle = $bundle | append $fathom }} {{- $bundle = $bundle | append $fathom -}}
{{- end }} {{- end -}}
{{- $js := $bundle | resources.Concat "/js/app.js" -}} {{- $js := $bundle | resources.Concat "/js/app.js" -}}
<script async defer src="{{ $js.Permalink }}"></script> <script async defer src="{{ $js.Permalink }}"></script>