refactor: move visit count to lib
All checks were successful
create archive with lfs / tag (push) Successful in 8s
All checks were successful
create archive with lfs / tag (push) Successful in 8s
This commit is contained in:
parent
3ba07e7b93
commit
d62b71db61
@ -1,4 +1,6 @@
|
||||
import type { Cookies } from '@sveltejs/kit'
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
export const scopeCookies = (cookies: Cookies, path: string) => {
|
||||
return {
|
||||
@ -12,4 +14,7 @@ export const scopeCookies = (cookies: Cookies, path: string) => {
|
||||
cookies.delete(key, { ...props, path })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const visitCountFile = 'visitcount'
|
||||
export const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));
|
@ -1,15 +1,12 @@
|
||||
import { scopeCookies } from '$lib';
|
||||
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { scopeCookies, visitCount, visitCountFile } from '$lib';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { get } 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, '/')
|
||||
|
Loading…
Reference in New Issue
Block a user