Compare commits
No commits in common. "fe82c60fe5549b46ba19494c8b0756e84cdad75b" and "2ab43bda7bf7b96759fe284256034abd7d816267" have entirely different histories.
fe82c60fe5
...
2ab43bda7b
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,7 +5,6 @@ node_modules
|
|||||||
.vercel
|
.vercel
|
||||||
/.svelte-kit
|
/.svelte-kit
|
||||||
/build
|
/build
|
||||||
/visitcount
|
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import type { Cookies } from '@sveltejs/kit'
|
|
||||||
|
|
||||||
export const scopeCookies = (cookies: Cookies, path: string) => {
|
|
||||||
return {
|
|
||||||
get: (key: string) => {
|
|
||||||
return cookies.get(key)
|
|
||||||
},
|
|
||||||
set: (key: string, value: string, props: import('cookie').CookieSerializeOptions = {}) => {
|
|
||||||
cookies.set(key, value, { ...props, path })
|
|
||||||
},
|
|
||||||
delete: (key: string, props: import('cookie').CookieSerializeOptions = {}) => {
|
|
||||||
cookies.delete(key, { ...props, path })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
import { scopeCookies } from '$lib';
|
|
||||||
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
||||||
import { get, writable } from 'svelte/store';
|
|
||||||
|
|
||||||
export const csr = true;
|
|
||||||
export const ssr = true;
|
|
||||||
export const prerender = true;
|
|
||||||
export const trailingSlash = 'always';
|
|
||||||
|
|
||||||
const visitCountFile = 'visitcount'
|
|
||||||
const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));
|
|
||||||
|
|
||||||
export async function load({ cookies, url, setHeaders }) {
|
|
||||||
setHeaders({ 'Cache-Control': 'no-cache' })
|
|
||||||
const scopedCookies = scopeCookies(cookies, '/')
|
|
||||||
// parse the last visit timestamp from cookies if it exists
|
|
||||||
const visitedTimestamp = parseInt(scopedCookies.get('visitedTimestamp') || "0")
|
|
||||||
// get unix timestamp
|
|
||||||
const currentTime = new Date().getTime()
|
|
||||||
const timeSinceVisit = currentTime - visitedTimestamp
|
|
||||||
let currentVisitCount = get(visitCount)
|
|
||||||
// check if this is the first time a client is visiting or if an hour has passed since they last visited
|
|
||||||
if (visitedTimestamp === 0 || timeSinceVisit > 1000 * 60 * 60 * 24) {
|
|
||||||
// increment current and write to the store
|
|
||||||
currentVisitCount += 1; visitCount.set(currentVisitCount)
|
|
||||||
// update the cookie with the current timestamp
|
|
||||||
scopedCookies.set('visitedTimestamp', currentTime.toString())
|
|
||||||
// write the visit count to a file so we can load it later again
|
|
||||||
writeFileSync(visitCountFile, currentVisitCount.toString())
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
route: url.pathname,
|
|
||||||
visitCount: currentVisitCount,
|
|
||||||
}
|
|
||||||
}
|
|
@ -150,25 +150,16 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
<div class="hidden md:block grow" />
|
<div class="hidden md:block grow" />
|
||||||
<div class="navbox">
|
<div
|
||||||
|
class="flex gap-3 px-1.5 text-nowrap align-middle items-center text-center place-content-center border-ralsei-white border-groove border-4"
|
||||||
|
>
|
||||||
<a title="previous site" class="hover:underline" href="https://xn--sr8hvo.ws/previous">⮜</a>
|
<a title="previous site" class="hover:underline" href="https://xn--sr8hvo.ws/previous">⮜</a>
|
||||||
<a class="hover:underline" href="https://xn--sr8hvo.ws">IndieWeb Webring</a>
|
<a class="hover:underline" href="https://xn--sr8hvo.ws">IndieWeb Webring</a>
|
||||||
<a title="next site" class="hover:underline" href="https://xn--sr8hvo.ws/next">⮞</a>
|
<a title="next site" class="hover:underline" href="https://xn--sr8hvo.ws/next">⮞</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="navbox">
|
<a class="align-middle" href="/entries/_rss">
|
||||||
<p><span class="text-ralsei-green-light text-shadow-green">{data.visitCount}</span> visit(s)</p>
|
<img class="min-w-fit hover:opacity-60" src="/valid-rss.png" alt="rss feed" />
|
||||||
</div>
|
</a>
|
||||||
<div class="navbox [gap:0.25rem_!important]">
|
|
||||||
<a class="align-middle hover:underline" href="/entries/_rss">rss</a>
|
|
||||||
/
|
|
||||||
<a class="align-middle hover:underline" href="/entries/_jsonfeed">jsonfeed</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<style lang="postcss">
|
|
||||||
.navbox {
|
|
||||||
@apply flex gap-3 px-1.5 text-nowrap align-middle items-center text-center place-content-center border-ralsei-white border-groove border-4;
|
|
||||||
}
|
|
||||||
</style>
|
|
9
src/routes/+layout.ts
Normal file
9
src/routes/+layout.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const csr = true;
|
||||||
|
export const ssr = true;
|
||||||
|
export const prerender = true;
|
||||||
|
export const trailingSlash = 'always';
|
||||||
|
|
||||||
|
export async function load({ url, setHeaders }) {
|
||||||
|
setHeaders({'Cache-Control': 'no-cache'})
|
||||||
|
return { route: url.pathname }
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
import { GUESTBOOK_BASE_URL } from '$env/static/private'
|
import { GUESTBOOK_BASE_URL } from '$env/static/private'
|
||||||
import { redirect, type Cookies } from '@sveltejs/kit'
|
import { redirect, type Cookies } from '@sveltejs/kit'
|
||||||
import auth from '$lib/guestbookAuth'
|
import auth from '$lib/guestbookAuth'
|
||||||
import { scopeCookies as _scopeCookies } from '$lib';
|
|
||||||
|
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
|
|
||||||
@ -12,7 +11,17 @@ interface Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scopeCookies = (cookies: Cookies) => {
|
const scopeCookies = (cookies: Cookies) => {
|
||||||
return _scopeCookies(cookies, '/guestbook')
|
return {
|
||||||
|
get: (key: string) => {
|
||||||
|
return cookies.get(key)
|
||||||
|
},
|
||||||
|
set: (key: string, value: string, props: import('cookie').CookieSerializeOptions = {}) => {
|
||||||
|
cookies.set(key, value, { ...props, path: "/guestbook/" })
|
||||||
|
},
|
||||||
|
delete: (key: string, props: import('cookie').CookieSerializeOptions = {}) => {
|
||||||
|
cookies.delete(key, { ...props, path: "/guestbook/" })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const postAction = (client: any, scopes: string[]) => {
|
const postAction = (client: any, scopes: string[]) => {
|
||||||
|
@ -65,12 +65,8 @@
|
|||||||
text-shadow: 0 0 4px theme(colors.ralsei.pink.regular);
|
text-shadow: 0 0 4px theme(colors.ralsei.pink.regular);
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-shadow-green {
|
|
||||||
text-shadow: 0 0 2px theme(colors.ralsei.black), 0 0 5px theme(colors.ralsei.green.light);
|
|
||||||
}
|
|
||||||
|
|
||||||
a,button,input[type=submit] {
|
a,button,input[type=submit] {
|
||||||
@apply text-shadow-green;
|
text-shadow: 0 0 2px theme(colors.ralsei.black), 0 0 5px theme(colors.ralsei.green.light);
|
||||||
cursor: url('/icons/gaze.png'), pointer;
|
cursor: url('/icons/gaze.png'), pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user