28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
/**
|
|
* Path to an archive listing: /pl/artykuly, /pl/artykuly?page=2.
|
|
*
|
|
* Pagination goes in the query string rather than the path. A path segment
|
|
* (/pl/artykuly/2) would be ambiguous with an entry slugged "2", and the
|
|
* alternative (/pl/artykuly/strona/2) drags in yet another localized segment to
|
|
* configure and translate. Google has understood ?page= for years, and
|
|
* rel=next/prev — the reason people used to prefer path segments — was retired.
|
|
*/ export function buildArchivePath({ archiveSlug, locale, page = 1 }) {
|
|
const base = `/${locale}/${archiveSlug}`;
|
|
return page > 1 ? `${base}?page=${page}` : base;
|
|
}
|
|
/** Path to a single entry: /pl/artykuly/moj-post. */ export function buildEntryPath({ archiveSlug, entrySlug, locale }) {
|
|
return `/${locale}/${archiveSlug}/${entrySlug}`;
|
|
}
|
|
/**
|
|
* Reads a page number out of a query parameter.
|
|
*
|
|
* Anything that isn't a positive integer is page 1 — `?page=abc`, `?page=-5`,
|
|
* `?page=1.5` and a repeated `?page=1&page=2` all have to resolve to something,
|
|
* and silently showing the first page beats a 500 on a URL a crawler invented.
|
|
*/ export function parsePageParam(value) {
|
|
const raw = Array.isArray(value) ? value[0] : value;
|
|
const n = Number(raw);
|
|
return Number.isInteger(n) && n > 0 ? n : 1;
|
|
} //# sourceMappingURL=paths.js.map
|
|
|
|
//# sourceMappingURL=paths.js.map
|