@basicbenframework/cms 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import { Taxonomy } from "../../models/Taxonomy.js";
8
8
  import { Menu } from "../../models/Menu.js";
9
9
  import { Redirect } from "../../models/Redirect.js";
10
10
  import { normalizeRedirectSource, RESERVED_ROUTE_SEGMENTS, POST_ROUTE_BASE } from "../../helpers/content-paths.js";
11
- import { renderListing, renderEntry, renderPage, renderNotFound, pathOf } from "./templates.js";
11
+ import { renderListing, renderEntry, renderPage, renderNotFound, pathOf, listingPath } from "./templates.js";
12
12
  /**
13
13
  * The reference public site, rendered on the server.
14
14
  *
@@ -184,6 +184,10 @@ function themed(handler) {
184
184
  }
185
185
  export const ThemeController = {
186
186
  home: themed(async (req, res, ctx) => {
187
+ // One address per page: `/?page=2` is `/page/2`, the one the pager links.
188
+ const page = pageNumber(req);
189
+ if (page > 1)
190
+ return res.redirect(listingPath('/', page), 301);
187
191
  await listing(req, res, { title: ctx.site.name, intro: ctx.site.description, basePath: '/', heading: false }, ctx);
188
192
  }),
189
193
  /** `/blog/:slug` — a blog post. */
@@ -217,6 +221,8 @@ export const ThemeController = {
217
221
  }),
218
222
  /** `/page/:page` — the home page, paginated the WordPress way. */
219
223
  homePage: themed(async (req, res, ctx) => {
224
+ if (pageNumber(req) <= 1)
225
+ return res.redirect('/', 301);
220
226
  await listing(req, res, { title: ctx.site.name, intro: ctx.site.description, basePath: '/', heading: false }, ctx);
221
227
  }),
222
228
  category: themed(async (req, res, ctx) => {
@@ -76,6 +76,11 @@ export declare function responsiveImg(image: ResponsiveImage | null, options?: {
76
76
  }): SafeHtml | '';
77
77
  /** One entry in a listing. */
78
78
  export declare function card(ctx: ThemeContext, post: PublicPost): SafeHtml;
79
+ /**
80
+ * Page `n` of a listing. The home page pages the WordPress way, `/page/2`,
81
+ * the route it has; an archive adds `?page=2` to its own path.
82
+ */
83
+ export declare function listingPath(base: string, n: number): string;
79
84
  /** Everything in <head> a browser, a crawler or a link preview reads. */
80
85
  export declare function renderHead(ctx: ThemeContext, meta: HeadMeta): SafeHtml;
81
86
  /** The whole page around a body. */
@@ -87,7 +92,7 @@ export interface ListingView {
87
92
  posts: PublicPost[];
88
93
  page: number;
89
94
  totalPages: number;
90
- /** The listing's own path, without `?page=`. */
95
+ /** The listing's own path, without its page number. */
91
96
  basePath: string;
92
97
  /** The home page and a type archive are the site; archives are collections. */
93
98
  heading?: boolean;
@@ -67,10 +67,21 @@ export function card(ctx, post) {
67
67
  </div>
68
68
  </article>`;
69
69
  }
70
+ /**
71
+ * Page `n` of a listing. The home page pages the WordPress way, `/page/2`,
72
+ * the route it has; an archive adds `?page=2` to its own path.
73
+ */
74
+ export function listingPath(base, n) {
75
+ if (n <= 1)
76
+ return base;
77
+ if (base === '/')
78
+ return `/page/${n}`;
79
+ return `${base}${base.includes('?') ? '&' : '?'}page=${n}`;
80
+ }
70
81
  function pager(page, totalPages, base) {
71
82
  if (totalPages <= 1)
72
83
  return '';
73
- const link = (n) => (n <= 1 ? base : `${base}${base.includes('?') ? '&' : '?'}page=${n}`);
84
+ const link = (n) => listingPath(base, n);
74
85
  return html `<nav class="pager" aria-label="Pagination">
75
86
  ${page > 1 ? html `<a rel="prev" href="${link(page - 1)}">← Newer</a>` : html `<span></span>`}
76
87
  <span>Page ${page} of ${totalPages}</span>
@@ -199,7 +210,7 @@ ${raw(site.code_injection.foot)}
199
210
  }
200
211
  /** The home page, a type archive, or a category/tag/author/term archive. */
201
212
  export function renderListing(ctx, view) {
202
- const pageUrl = (n) => absolute(ctx, n <= 1 ? view.basePath : `${view.basePath}?page=${n}`);
213
+ const pageUrl = (n) => absolute(ctx, listingPath(view.basePath, n));
203
214
  const isHome = view.basePath === '/';
204
215
  const body = html `
205
216
  ${view.heading === false ? '' : html `<header>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basicbenframework/cms",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "description": "The BasicBen CMS. Posts, pages, media, an admin UI, and a headless content API.",
6
6
  "license": "MIT",