2026-09-11 11:25:14 +02:00
|
|
|
/** PocketBase query fragments. Only the fields the pages actually render are requested. */
|
2026-09-11 13:52:13 +02:00
|
|
|
import type { Locale } from '#shared/utils/locale'
|
2026-08-25 11:42:17 +02:00
|
|
|
|
2026-09-11 11:25:14 +02:00
|
|
|
export const ARTICLE_SUMMARY_FIELDS =
|
2026-09-11 13:52:13 +02:00
|
|
|
'id,title,titleEn,slug,publishedAt,cover,coverAlt,coverAltEn,expand.category.name,expand.category.nameEn,expand.category.slug'
|
2026-08-25 11:42:17 +02:00
|
|
|
|
2026-09-11 11:25:14 +02:00
|
|
|
export const ARTICLE_DETAIL_FIELDS =
|
2026-09-11 13:52:13 +02:00
|
|
|
'id,title,titleEn,slug,content,contentEn,publishedAt,cover,coverAlt,coverAltEn,authorName,expand.category.name,expand.category.nameEn,expand.category.slug'
|
|
|
|
|
|
|
|
|
|
export const CATEGORY_FIELDS = 'name,nameEn,slug'
|
2026-08-25 11:42:17 +02:00
|
|
|
|
|
|
|
|
export const PAGE_SIZE = 12
|
|
|
|
|
|
2026-09-11 11:25:14 +02:00
|
|
|
export const pagination = (page: number, perPage = PAGE_SIZE) => `page=${page}&perPage=${perPage}`
|
2026-08-25 11:42:17 +02:00
|
|
|
|
|
|
|
|
/** Reads a positive integer query param, falling back to 1. */
|
|
|
|
|
export const pageParam = (value: unknown): number => {
|
|
|
|
|
const page = Number(value)
|
|
|
|
|
return Number.isInteger(page) && page > 0 ? page : 1
|
|
|
|
|
}
|
2026-09-11 11:25:14 +02:00
|
|
|
|
2026-09-11 13:52:13 +02:00
|
|
|
/** Reads a `lang` query param, falling back to Italian for anything but `en`. */
|
|
|
|
|
export const langParam = (value: unknown): Locale => (value === 'en' ? 'en' : 'it')
|
|
|
|
|
|
2026-09-11 11:25:14 +02:00
|
|
|
/** Quotes a value for PocketBase's `filter` DSL, escaping embedded quotes. */
|
|
|
|
|
export const quote = (value: string) => `"${value.replace(/"/g, '\\"')}"`
|