···77export const prerender = 'auto';
88export const trailingSlash = 'always';
991010-export async function load({ cookies, url, setHeaders }) {
1111- setHeaders({ 'Cache-Control': 'no-cache' })
1010+export async function load({ request, cookies, url, setHeaders }) {
1111+ setHeaders({ 'Cache-Control': 'no-cache' })
1212+ let currentVisitCount = get(visitCount)
1313+ // check whether the request is from a bot or not (this doesnt need to be accurate we just want to filter out honest bots)
1414+ const ua = request.headers.get('user-agent')
1515+ const isBot = ua ? ua.toLowerCase().match(/(bot|crawl|spider|walk)/) !== null : true
1616+ if (!isBot) {
1217 const scopedCookies = scopeCookies(cookies, '/')
1318 // parse the last visit timestamp from cookies if it exists
1419 const visitedTimestamp = parseInt(scopedCookies.get('visitedTimestamp') || "0")
1520 // get unix timestamp
1621 const currentTime = new Date().getTime()
1722 const timeSinceVisit = currentTime - visitedTimestamp
1818- let currentVisitCount = get(visitCount)
1923 // check if this is the first time a client is visiting or if an hour has passed since they last visited
2024 if (visitedTimestamp === 0 || timeSinceVisit > 1000 * 60 * 60 * 24) {
2121- // increment current and write to the store
2222- currentVisitCount += 1; visitCount.set(currentVisitCount)
2323- // update the cookie with the current timestamp
2424- scopedCookies.set('visitedTimestamp', currentTime.toString())
2525- // write the visit count to a file so we can load it later again
2626- writeFileSync(visitCountFile, currentVisitCount.toString())
2525+ // increment current and write to the store
2626+ currentVisitCount += 1; visitCount.set(currentVisitCount)
2727+ // update the cookie with the current timestamp
2828+ scopedCookies.set('visitedTimestamp', currentTime.toString())
2929+ // write the visit count to a file so we can load it later again
3030+ writeFileSync(visitCountFile, currentVisitCount.toString())
2731 }
2828- return {
2929- route: url.pathname,
3030- visitCount: currentVisitCount,
3131- }
3232-}3232+ }
3333+ return {
3434+ route: url.pathname,
3535+ visitCount: currentVisitCount,
3636+ }
3737+}
+5-1
tsconfig.json
···1010 "sourceMap": true,
1111 "strict": true,
1212 "moduleResolution": "bundler",
1313- "allowImportingTsExtensions": true
1313+ "allowImportingTsExtensions": true,
1414+ "plugins": [{
1515+ "name": "typescript-svelte-plugin",
1616+ "enabled": true
1717+ }]
1418 }
1519 // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
1620 // except $lib which is handled by https://kit.svelte.dev/docs/configuration#files