data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add visited count

dusk 9af7bf36 2ab43bda

+62 -27
+15
src/lib/index.ts
··· 1 + import type { Cookies } from '@sveltejs/kit' 2 + 3 + export const scopeCookies = (cookies: Cookies, path: string) => { 4 + return { 5 + get: (key: string) => { 6 + return cookies.get(key) 7 + }, 8 + set: (key: string, value: string, props: import('cookie').CookieSerializeOptions = {}) => { 9 + cookies.set(key, value, { ...props, path }) 10 + }, 11 + delete: (key: string, props: import('cookie').CookieSerializeOptions = {}) => { 12 + cookies.delete(key, { ...props, path }) 13 + } 14 + } 15 + }
+25
src/routes/+layout.server.ts
··· 1 + import { scopeCookies } from '$lib'; 2 + import { get, writable } from 'svelte/store'; 3 + 4 + export const csr = true; 5 + export const ssr = true; 6 + export const prerender = true; 7 + export const trailingSlash = 'always'; 8 + 9 + const visitCount = writable(0); 10 + 11 + export async function load({ cookies, url, setHeaders }) { 12 + setHeaders({ 'Cache-Control': 'no-cache' }) 13 + const scopedCookies = scopeCookies(cookies, '/') 14 + const visitedTimestamp = parseInt(scopedCookies.get('visitedTimestamp') || "0") 15 + const currentTime = new Date().getTime() 16 + const timeSinceVisit = currentTime - visitedTimestamp 17 + if (visitedTimestamp === 0 || timeSinceVisit > 1000 * 60 * 60) { 18 + visitCount.set(get(visitCount) + 1) 19 + scopedCookies.set('visitedTimestamp', currentTime.toString()) 20 + } 21 + return { 22 + route: url.pathname, 23 + visitCount: get(visitCount), 24 + } 25 + }
+15 -6
src/routes/+layout.svelte
··· 150 150 {/if} 151 151 {/each} 152 152 <div class="hidden md:block grow" /> 153 - <div 154 - 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" 155 - > 153 + <div class="navbox"> 156 154 <a title="previous site" class="hover:underline" href="https://xn--sr8hvo.ws/previous">⮜</a> 157 155 <a class="hover:underline" href="https://xn--sr8hvo.ws">IndieWeb Webring</a> 158 156 <a title="next site" class="hover:underline" href="https://xn--sr8hvo.ws/next">⮞</a> 159 157 </div> 160 - <a class="align-middle" href="/entries/_rss"> 161 - <img class="min-w-fit hover:opacity-60" src="/valid-rss.png" alt="rss feed" /> 162 - </a> 158 + <div class="navbox"> 159 + <p><span class="text-ralsei-green-light text-shadow-green">{data.visitCount}</span> visit(s)</p> 160 + </div> 161 + <div class="navbox [gap:0.25rem_!important]"> 162 + <a class="align-middle hover:underline" href="/entries/_rss">rss</a> 163 + / 164 + <a class="align-middle hover:underline" href="/entries/_jsonfeed">jsonfeed</a> 165 + </div> 163 166 </div> 164 167 </div> 165 168 </nav> 169 + 170 + <style lang="postcss"> 171 + .navbox { 172 + @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; 173 + } 174 + </style>
-9
src/routes/+layout.ts
··· 1 - export const csr = true; 2 - export const ssr = true; 3 - export const prerender = true; 4 - export const trailingSlash = 'always'; 5 - 6 - export async function load({ url, setHeaders }) { 7 - setHeaders({'Cache-Control': 'no-cache'}) 8 - return { route: url.pathname } 9 - }
+2 -11
src/routes/guestbook/+page.server.ts
··· 1 1 import { GUESTBOOK_BASE_URL } from '$env/static/private' 2 2 import { redirect, type Cookies } from '@sveltejs/kit' 3 3 import auth from '$lib/guestbookAuth' 4 + import { scopeCookies as _scopeCookies } from '$lib'; 4 5 5 6 export const prerender = false; 6 7 ··· 11 12 } 12 13 13 14 const scopeCookies = (cookies: Cookies) => { 14 - return { 15 - get: (key: string) => { 16 - return cookies.get(key) 17 - }, 18 - set: (key: string, value: string, props: import('cookie').CookieSerializeOptions = {}) => { 19 - cookies.set(key, value, { ...props, path: "/guestbook/" }) 20 - }, 21 - delete: (key: string, props: import('cookie').CookieSerializeOptions = {}) => { 22 - cookies.delete(key, { ...props, path: "/guestbook/" }) 23 - } 24 - } 15 + return _scopeCookies(cookies, '/guestbook') 25 16 } 26 17 27 18 const postAction = (client: any, scopes: string[]) => {
+5 -1
src/styles/app.css
··· 65 65 text-shadow: 0 0 4px theme(colors.ralsei.pink.regular); 66 66 } 67 67 68 - a,button,input[type=submit] { 68 + .text-shadow-green { 69 69 text-shadow: 0 0 2px theme(colors.ralsei.black), 0 0 5px theme(colors.ralsei.green.light); 70 + } 71 + 72 + a,button,input[type=submit] { 73 + @apply text-shadow-green; 70 74 cursor: url('/icons/gaze.png'), pointer; 71 75 } 72 76