Files
blog/frontend/server/utils/queries.ts
T

21 lines
851 B
TypeScript
Raw Normal View History

2026-09-11 11:25:14 +02:00
/** PocketBase query fragments. Only the fields the pages actually render are requested. */
2026-09-11 11:25:14 +02:00
export const ARTICLE_SUMMARY_FIELDS =
'id,title,slug,publishedAt,cover,coverAlt,expand.category.name,expand.category.slug'
2026-09-11 11:25:14 +02:00
export const ARTICLE_DETAIL_FIELDS =
'id,title,slug,content,publishedAt,cover,coverAlt,authorName,expand.category.name,expand.category.slug'
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}`
/** 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
/** Quotes a value for PocketBase's `filter` DSL, escaping embedded quotes. */
export const quote = (value: string) => `"${value.replace(/"/g, '\\"')}"`