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 type { Cookies } from '@sveltejs/kit'
|
||||||
|
import { existsSync, readFileSync } from 'fs'
|
||||||
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
export const scopeCookies = (cookies: Cookies, path: string) => {
|
export const scopeCookies = (cookies: Cookies, path: string) => {
|
||||||
return {
|
return {
|
||||||
@ -12,4 +14,7 @@ export const scopeCookies = (cookies: Cookies, path: string) => {
|
|||||||
cookies.delete(key, { ...props, path })
|
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 { scopeCookies, visitCount, visitCountFile } from '$lib';
|
||||||
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
import { writeFileSync } from 'fs';
|
||||||
import { get, writable } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
export const csr = true;
|
export const csr = true;
|
||||||
export const ssr = true;
|
export const ssr = true;
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
export const trailingSlash = 'always';
|
export const trailingSlash = 'always';
|
||||||
|
|
||||||
const visitCountFile = 'visitcount'
|
|
||||||
const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(visitCountFile).toString() : '0'));
|
|
||||||
|
|
||||||
export async function load({ cookies, url, setHeaders }) {
|
export async function load({ cookies, url, setHeaders }) {
|
||||||
setHeaders({ 'Cache-Control': 'no-cache' })
|
setHeaders({ 'Cache-Control': 'no-cache' })
|
||||||
const scopedCookies = scopeCookies(cookies, '/')
|
const scopedCookies = scopeCookies(cookies, '/')
|
||||||
|
Loading…
Reference in New Issue
Block a user