@tansy/blog 0.1.0 → 0.1.2

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ What changed in each release of `@tansy/blog`. Releases up to 0.1.1 went out with every other
4
+ package on one version and are described in [tansy's changelog](../../CHANGELOG.md).
5
+
6
+ ## 0.1.2 — 2026-11-22
7
+
8
+ The parts `@tansy/blog/render` exports now fit inside a theme's own design without CSS to undo them.
9
+
10
+ - **Parts carry no outer margin or border.** The plugin's own post page still places them as before,
11
+ inside `.bl-main`, so it looks the same. A theme that embeds `MorePosts` or `PostComments` now gets
12
+ no top margin, padding or rule above them, and `PostMeta`, `PostCategories`, `PostTags` and
13
+ `PostList` bring no outer margin either. A theme that relied on that spacing sets it itself, as the
14
+ blog, dispatch and magazine themes in this repository now do: until you upgrade those themes, the
15
+ space and rule above "More posts" and the comments are missing on their post pages.
16
+ - **Headings are the theme's.** `PostComments` takes `heading`, `formHeading` and `headingLevel`, and
17
+ `MorePosts` takes `heading` and `headingLevel`. A string replaces the text, `false` hides the
18
+ heading while the section keeps the default text as its `aria-label`, and `headingLevel` (2 to 6)
19
+ sets the main heading's level, with the form heading and the post titles in `MorePosts` one below.
20
+ `PostList` takes `headingLevel` for its post titles. All new props are optional.
21
+ - **Ids no longer collide.** The headings take their ids from React's `useId`, so two parts on one
22
+ page don't share `bl-comments-title` or `bl-more-title`.
23
+ - **Class hooks for every element a theme styles:** `bl-comments-title`, `bl-form-title`,
24
+ `bl-more-title`, `bl-comments-empty` and `bl-replies`, beside the existing class names. Every rule
25
+ weighs a single class, so one class of the theme's overrides it.
package/blog.css CHANGED
@@ -1,4 +1,9 @@
1
- /* The blog plugin's pages. Colours, fonts and widths come from the active theme's --site-* tokens, with plain fallbacks. */
1
+ /*
2
+ * The blog plugin's pages. Colours, fonts and widths come from the active theme's --site-* tokens, with plain fallbacks.
3
+ * The exported parts (.bl-meta, .bl-kicker, .bl-list, .bl-tags, .bl-more, .bl-comments) carry no outer margin or border:
4
+ * the plugin's own template places them, under :where(.bl-main) at the end, and a theme that embeds them places them itself.
5
+ * Every selector weighs one class, so one class of the theme's overrides it.
6
+ */
2
7
  .bl-main {
3
8
  max-width: var(--site-size-measure, 42rem);
4
9
  margin: 0 auto;
@@ -10,15 +15,15 @@
10
15
  .bl-main h1 { font-size: 2.25rem; line-height: 1.2; margin: 0 0 0.5rem; }
11
16
  .bl-main a { color: var(--site-color-accent, inherit); }
12
17
  .bl-muted, .bl-meta { color: var(--site-color-muted, #666); }
13
- .bl-meta { font-size: 0.875rem; margin: 0 0 1rem; }
14
- .bl-kicker { font-size: 0.8125rem; letter-spacing: 0.04em; text-transform: uppercase; margin: 0 0 0.5rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }
18
+ .bl-meta { font-size: 0.875rem; margin: 0; }
19
+ .bl-kicker { font-size: 0.8125rem; letter-spacing: 0.04em; text-transform: uppercase; margin: 0; display: flex; gap: 0.75rem; flex-wrap: wrap; }
15
20
  .bl-cover { width: 100%; height: auto; border-radius: var(--site-radius-card, 0.5rem); margin: 0 0 1.5rem; }
16
21
  .bl-body > * + * { margin-top: var(--site-space-gap, 1.25rem); }
17
- .bl-list { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; gap: var(--site-space-gap, 1.5rem); }
22
+ .bl-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--site-space-gap, 1.5rem); }
18
23
  .bl-item { padding-bottom: var(--site-space-gap, 1.5rem); border-bottom: 1px solid var(--site-color-border, #e5e5e5); }
19
24
  .bl-item-title { font-size: 1.375rem; margin: 0 0 0.25rem; }
20
25
  .bl-featured .bl-item-title::before { content: "★ "; color: var(--site-color-accent, currentColor); }
21
- .bl-tags { list-style: none; padding: 0; margin: 2rem 0 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
26
+ .bl-tags { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
22
27
  .bl-tags a, .bl-tags span { display: inline-block; padding: 0.125rem 0.625rem; border: 1px solid var(--site-color-border, #ddd); border-radius: 999px; font-size: 0.8125rem; text-decoration: none; }
23
28
  .bl-quote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--site-color-accent, currentColor); font-style: italic; }
24
29
  .bl-quote cite { display: block; font-style: normal; color: var(--site-color-muted, #666); margin-top: 0.25rem; }
@@ -38,9 +43,8 @@
38
43
  .bl-editor-placeholder { padding: 1rem; border: 1px dashed var(--site-color-border, #ccc); border-radius: var(--site-radius-card, 0.5rem); }
39
44
  .bl-editor-placeholder p { margin: 0; }
40
45
  .bl-code { overflow-x: auto; padding: 1rem; border-radius: var(--site-radius-card, 0.5rem); background: color-mix(in srgb, var(--site-color-text, #222) 6%, transparent); font-size: 0.875rem; }
41
- .bl-more, .bl-comments { margin-top: var(--site-space-section, 3rem); padding-top: 1.5rem; border-top: 1px solid var(--site-color-border, #e5e5e5); }
42
46
  .bl-thread { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 1rem; }
43
- .bl-thread .bl-thread { margin-left: 1.5rem; }
47
+ .bl-replies { margin-left: 1.5rem; }
44
48
  .bl-comment-body { white-space: pre-line; overflow-wrap: anywhere; margin: 0 0 0.25rem; }
45
49
  .bl-form { display: grid; gap: 0.375rem; margin: 1rem 0; }
46
50
  .bl-form input, .bl-form textarea { font: inherit; padding: 0.5rem; border: 1px solid var(--site-color-border, #ccc); border-radius: 0.375rem; background: transparent; color: inherit; }
@@ -51,3 +55,10 @@
51
55
  .bl-link { font: inherit; font-size: 0.875rem; background: none; border: 0; padding: 0; color: var(--site-color-accent, inherit); cursor: pointer; text-decoration: underline; }
52
56
  .bl-error { color: #c53030; margin: 0; }
53
57
  .bl-pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: var(--site-space-section, 3rem); font-size: 0.875rem; color: var(--site-color-muted, #666); }
58
+ /* Inner spacing: a post's meta inside a list item or a comment. */
59
+ :where(.bl-item, .bl-comment) .bl-meta { margin-bottom: 1rem; }
60
+ /* Where the plugin's own template places the parts. */
61
+ :where(.bl-main) .bl-meta { margin-bottom: 1rem; }
62
+ :where(.bl-main) .bl-kicker { margin-bottom: 0.5rem; }
63
+ :where(.bl-main) .bl-list, :where(.bl-main) .bl-tags { margin-top: 2rem; }
64
+ :where(.bl-main) > .bl-more, :where(.bl-main) > .bl-comments { margin-top: var(--site-space-section, 3rem); padding-top: 1.5rem; border-top: 1px solid var(--site-color-border, #e5e5e5); }
package/comments.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type SiteWords } from "tansy/react";
2
+ import type { HeadingLevel } from "./text";
2
3
  export interface PublicComment {
3
4
  id: number;
4
5
  name: string;
@@ -7,9 +8,18 @@ export interface PublicComment {
7
8
  createdAt: string;
8
9
  pending?: boolean;
9
10
  }
11
+ /** How a theme titles the comments: see `PostComments` in render.tsx. */
12
+ export interface CommentsHeadings {
13
+ /** The section's heading. A string replaces "Comments"; `false` shows none, and the section keeps "Comments" as its `aria-label`. */
14
+ heading?: string | false;
15
+ /** The heading over the form. A string replaces "Leave a comment"; `false` shows none. */
16
+ formHeading?: string | false;
17
+ /** The section heading's level, 2 to 6, default 2. The form heading is one level below. */
18
+ headingLevel?: HeadingLevel;
19
+ }
10
20
  /** Approved comments from the page, plus the reader's own new ones. Replies go one level deep. */
11
- export declare function Comments({ postId, initial, words: given }: {
21
+ export declare function Comments({ postId, initial, words: given, heading, formHeading, headingLevel }: {
12
22
  postId: number;
13
23
  initial: PublicComment[];
14
24
  words?: SiteWords;
15
- }): import("react").JSX.Element;
25
+ } & CommentsHeadings): import("react").JSX.Element;
package/comments.js CHANGED
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { useId, useState } from "react";
4
4
  import { apiPath } from "tansy/react";
5
5
  import { blogWords } from "./site-messages";
6
+ import { Heading } from "./heading";
6
7
  function CommentForm({ postId, parent, onPosted, onCancel, words }) {
7
8
  const { t } = words;
8
9
  const id = useId();
@@ -41,9 +42,10 @@ function Entry({ comment, children, words }) {
41
42
  return (_jsxs("li", { className: "bl-comment", children: [_jsxs("p", { className: "bl-meta", children: [_jsx("strong", { children: comment.name }), " \u00B7 ", _jsx("time", { dateTime: comment.createdAt, children: comment.createdAt ? words.formatDate(comment.createdAt) : "" }), comment.pending && _jsxs(_Fragment, { children: [" \u00B7 ", words.t("blog.waiting")] })] }), _jsx("p", { className: "bl-comment-body", children: comment.body }), children] }));
42
43
  }
43
44
  /** Approved comments from the page, plus the reader's own new ones. Replies go one level deep. */
44
- export function Comments({ postId, initial, words: given }) {
45
+ export function Comments({ postId, initial, words: given, heading, formHeading, headingLevel = 2 }) {
45
46
  const words = blogWords(given);
46
47
  const { t } = words;
48
+ const titleId = useId();
47
49
  const [comments, setComments] = useState(initial);
48
50
  const [replyingTo, setReplyingTo] = useState(null);
49
51
  const add = (comment) => {
@@ -51,10 +53,12 @@ export function Comments({ postId, initial, words: given }) {
51
53
  setReplyingTo(null);
52
54
  };
53
55
  const topLevel = comments.filter((comment) => !comment.parent);
54
- return (_jsxs("section", { className: "bl-comments", "aria-labelledby": "bl-comments-title", children: [_jsx("h2", { id: "bl-comments-title", children: t("blog.comments") }), topLevel.length === 0 && _jsx("p", { className: "bl-muted", children: t("blog.noComments") }), _jsx("ol", { className: "bl-thread", children: topLevel.map((comment) => {
56
+ const title = heading ?? t("blog.comments");
57
+ const formTitle = formHeading ?? t("blog.leaveComment");
58
+ return (_jsxs("section", { className: "bl-comments", ...(title === false ? { "aria-label": t("blog.comments") } : { "aria-labelledby": titleId }), children: [title !== false && _jsx(Heading, { level: headingLevel, id: titleId, className: "bl-comments-title", children: title }), topLevel.length === 0 && _jsx("p", { className: "bl-muted bl-comments-empty", children: t("blog.noComments") }), _jsx("ol", { className: "bl-thread", children: topLevel.map((comment) => {
55
59
  const replies = comments.filter((reply) => reply.parent === comment.id);
56
- return (_jsxs(Entry, { comment: comment, words: words, children: [replies.length > 0 && _jsx("ol", { className: "bl-thread", children: replies.map((reply) => _jsx(Entry, { comment: reply, words: words }, reply.id)) }), !comment.pending && (replyingTo === comment.id
60
+ return (_jsxs(Entry, { comment: comment, words: words, children: [replies.length > 0 && _jsx("ol", { className: "bl-thread bl-replies", children: replies.map((reply) => _jsx(Entry, { comment: reply, words: words }, reply.id)) }), !comment.pending && (replyingTo === comment.id
57
61
  ? _jsx(CommentForm, { postId: postId, parent: comment.id, onPosted: add, onCancel: () => setReplyingTo(null), words: words })
58
62
  : _jsx("button", { type: "button", className: "bl-link", onClick: () => setReplyingTo(comment.id), children: t("blog.reply") }))] }, comment.id));
59
- }) }), _jsx("h3", { children: t("blog.leaveComment") }), _jsx(CommentForm, { postId: postId, parent: null, onPosted: add, words: words })] }));
63
+ }) }), formTitle !== false && _jsx(Heading, { level: headingLevel + 1, className: "bl-form-title", children: formTitle }), _jsx(CommentForm, { postId: postId, parent: null, onPosted: add, words: words })] }));
60
64
  }
package/heading.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ /** A heading at `level`, kept between h2 and h6, for the parts whose level the theme sets. No hooks, so server and client parts share it. */
3
+ export declare function Heading({ level, id, className, children }: {
4
+ level?: number;
5
+ id?: string;
6
+ className: string;
7
+ children: ReactNode;
8
+ }): import("react").DetailedReactHTMLElement<{
9
+ id: string | undefined;
10
+ className: string;
11
+ }, HTMLElement>;
package/heading.js ADDED
@@ -0,0 +1,6 @@
1
+ import { createElement } from "react";
2
+ import { headingTag } from "./text";
3
+ /** A heading at `level`, kept between h2 and h6, for the parts whose level the theme sets. No hooks, so server and client parts share it. */
4
+ export function Heading({ level, id, className, children }) {
5
+ return createElement(headingTag(level), { id, className }, children);
6
+ }
package/index.js CHANGED
@@ -188,9 +188,9 @@ export function blog(options) {
188
188
  });
189
189
  return definePlugin({
190
190
  name: "blog",
191
- version: "0.1.0",
191
+ version: "0.1.2",
192
192
  apiVersion: 1,
193
- requires: { cms: "^0.1.0" },
193
+ requires: { cms: "^0.1.1" },
194
194
  admin: { server: "@tansy/blog/admin", client: "@tansy/blog/client", render: "@tansy/blog/render" },
195
195
  csp: { frame: ["https://www.youtube-nocookie.com", "https://player.vimeo.com"] },
196
196
  options: { schema: optionsSchema, value },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tansy/blog",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Turns tansy into a blog: posts, categories, tags, authors, comments and feeds.",
5
5
  "keywords": [
6
6
  "tansy",
@@ -38,7 +38,7 @@
38
38
  "peerDependencies": {
39
39
  "next": "^16.4.6",
40
40
  "react": "^19.3.0",
41
- "tansy": "^0.1.0"
41
+ "tansy": "^0.1.1"
42
42
  },
43
43
  "dependencies": {
44
44
  "zod": "^4.6.7"
package/render.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { type SiteWords } from "tansy/react";
2
2
  import type { SiteRecord, TemplateProps } from "tansy/theme";
3
+ import { type CommentsHeadings } from "./comments";
4
+ import { type HeadingLevel } from "./text";
3
5
  import "./blog.css";
4
6
  /**
5
7
  * The parts of the blog's pages, for a theme that designs its own. Give them the template's
@@ -7,6 +9,11 @@ import "./blog.css";
7
9
  * plugin's own, so each part finds what it needs there.
8
10
  *
9
11
  * import { PostMeta, MorePosts, PostComments } from "@tansy/blog/render";
12
+ *
13
+ * Parts carry no outer margin or border; the template places them. The plugin's own pages do
14
+ * that inside `.bl-main`, so a theme that embeds a part gets only its inner spacing and styles
15
+ * it with the part's `bl-` classes, each a single class it can override with one of its own.
16
+ * Parts that title themselves take `heading` and `headingLevel`, so the theme sets the outline.
10
17
  */
11
18
  type PartProps = {
12
19
  post: SiteRecord;
@@ -15,22 +22,40 @@ type PartProps = {
15
22
  };
16
23
  /** Byline, date and reading time. */
17
24
  export declare function PostMeta({ post, words }: PartProps): import("react").JSX.Element;
18
- /** Posts as a list of titles, meta and excerpts, with featured posts marked. */
19
- export declare function PostList({ posts, data, empty, words }: {
25
+ /**
26
+ * Posts as a list of titles, meta and excerpts, with featured posts marked.
27
+ * `headingLevel` (2 to 6, default 2) is the level of each post's title.
28
+ */
29
+ export declare function PostList({ posts, data, empty, words, headingLevel }: {
20
30
  posts: SiteRecord[];
21
31
  data: TemplateProps["data"];
22
32
  empty: string;
23
33
  words?: SiteWords;
34
+ headingLevel?: HeadingLevel;
24
35
  }): import("react").JSX.Element;
25
36
  /** The post's categories, as links. */
26
37
  export declare function PostCategories({ post, data, words }: PartProps): import("react").JSX.Element | null;
27
38
  /** The post's tags, as links. */
28
39
  export declare function PostTags({ post, data, words }: PartProps): import("react").JSX.Element | null;
29
- /** Up to three posts sharing a tag with this one, or the latest when none do. */
30
- export declare function MorePosts({ post, data, words, heading }: PartProps & {
31
- heading?: string;
32
- }): import("react").JSX.Element | null;
33
- /** Approved comments and the form, unless the post has comments turned off. Shows replies one level deep. */
34
- export declare function PostComments({ post, data, words }: PartProps): import("react").JSX.Element | null;
40
+ /** How a part that titles itself is titled. */
41
+ type Headed = {
42
+ /** A string replaces the default heading; `false` shows none, and the section keeps the default as its `aria-label`. */
43
+ heading?: string | false;
44
+ /** The heading's level, 2 to 6, default 2. */
45
+ headingLevel?: HeadingLevel;
46
+ };
47
+ /**
48
+ * Up to three posts sharing a tag with this one, or the latest when none do, under "More posts"
49
+ * or `heading`. Given a `headingLevel`, the post titles are one level below it; without one they
50
+ * are h2, as they have always been.
51
+ */
52
+ export declare function MorePosts({ post, data, words, heading, headingLevel }: PartProps & Headed): import("react").JSX.Element | null;
53
+ /**
54
+ * Approved comments and the form, unless the post has comments turned off. Shows replies one level deep.
55
+ * `heading` replaces "Comments" or, as `false`, hides it while the section keeps "Comments" as its
56
+ * `aria-label`; `formHeading` does the same for "Leave a comment"; `headingLevel` (2 to 6, default 2)
57
+ * sets the section heading's level, with the form heading one below.
58
+ */
59
+ export declare function PostComments({ post, data, words, heading, formHeading, headingLevel }: PartProps & CommentsHeadings): import("react").JSX.Element | null;
35
60
  declare const _default: import("tansy/react").Renderers;
36
61
  export default _default;
package/render.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
2
3
  import { apiPath, defineRenderers, pickWords, Pager, sitePath, RichText, StreamField } from "tansy/react";
3
4
  import { Comments } from "./comments";
4
5
  import { blogWords, siteMessages } from "./site-messages";
6
+ import { Heading } from "./heading";
5
7
  import { embedUrl } from "./text";
6
8
  import "./blog.css";
7
9
  const text = (value) => (typeof value === "string" ? value : "");
@@ -25,11 +27,14 @@ export function PostMeta({ post, words }) {
25
27
  const byline = text(post.byline);
26
28
  return (_jsxs("p", { className: "bl-meta", children: [byline && _jsxs(_Fragment, { children: [_jsx("span", { className: "bl-byline", children: byline }), _jsx("span", { "aria-hidden": true, children: " \u00B7 " })] }), date && _jsx("time", { dateTime: date, children: formatDate(date, "long") }), minutes !== null && _jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, children: " \u00B7 " }), t("blog.minutes", { count: minutes })] })] }));
27
29
  }
28
- /** Posts as a list of titles, meta and excerpts, with featured posts marked. */
29
- export function PostList({ posts, data, empty, words }) {
30
+ /**
31
+ * Posts as a list of titles, meta and excerpts, with featured posts marked.
32
+ * `headingLevel` (2 to 6, default 2) is the level of each post's title.
33
+ */
34
+ export function PostList({ posts, data, empty, words, headingLevel = 2 }) {
30
35
  if (!posts.length)
31
36
  return _jsx("p", { className: "bl-muted", children: empty });
32
- return (_jsx("ul", { className: "bl-list", children: posts.map((post) => (_jsxs("li", { className: post.featured === true ? "bl-item bl-featured" : "bl-item", children: [_jsx("h2", { className: "bl-item-title", children: _jsx(Linked, { record: post, label: post.title, words: words }) }), _jsx(PostMeta, { post: post, data: data, words: words }), text(post.excerpt) && _jsx("p", { children: text(post.excerpt) })] }, post.id))) }));
37
+ return (_jsx("ul", { className: "bl-list", children: posts.map((post) => (_jsxs("li", { className: post.featured === true ? "bl-item bl-featured" : "bl-item", children: [_jsx(Heading, { level: headingLevel, className: "bl-item-title", children: _jsx(Linked, { record: post, label: post.title, words: words }) }), _jsx(PostMeta, { post: post, data: data, words: words }), text(post.excerpt) && _jsx("p", { children: text(post.excerpt) })] }, post.id))) }));
33
38
  }
34
39
  /** The post's categories, as links. */
35
40
  export function PostCategories({ post, data, words }) {
@@ -45,19 +50,31 @@ export function PostTags({ post, data, words }) {
45
50
  return null;
46
51
  return _jsx("ul", { className: "bl-tags", "aria-label": blogWords(words).t("blog.tags"), children: ids(post.tags).map((id) => _jsx("li", { children: _jsx(Linked, { record: tags.get(id), label: tags.get(id)?.name, words: words }) }, id)) });
47
52
  }
48
- /** Up to three posts sharing a tag with this one, or the latest when none do. */
49
- export function MorePosts({ post, data, words, heading = blogWords(words).t("blog.morePosts") }) {
53
+ /**
54
+ * Up to three posts sharing a tag with this one, or the latest when none do, under "More posts"
55
+ * or `heading`. Given a `headingLevel`, the post titles are one level below it; without one they
56
+ * are h2, as they have always been.
57
+ */
58
+ export function MorePosts({ post, data, words, heading, headingLevel }) {
59
+ const titleId = useId();
50
60
  const related = items(data.related);
51
61
  const more = (related.length ? related : items(data.recent)).filter((other) => other.id !== post.id).slice(0, 3);
52
62
  if (!more.length)
53
63
  return null;
54
- return (_jsxs("section", { className: "bl-more", "aria-labelledby": "bl-more-title", children: [_jsx("h2", { id: "bl-more-title", children: heading }), _jsx(PostList, { posts: more, data: data, empty: "", words: words })] }));
64
+ const fallback = blogWords(words).t("blog.morePosts");
65
+ const title = heading ?? fallback;
66
+ return (_jsxs("section", { className: "bl-more", ...(title === false ? { "aria-label": fallback } : { "aria-labelledby": titleId }), children: [title !== false && _jsx(Heading, { level: headingLevel, id: titleId, className: "bl-more-title", children: title }), _jsx(PostList, { posts: more, data: data, empty: "", words: words, headingLevel: headingLevel ? Math.min(6, headingLevel + 1) : 2 })] }));
55
67
  }
56
- /** Approved comments and the form, unless the post has comments turned off. Shows replies one level deep. */
57
- export function PostComments({ post, data, words }) {
68
+ /**
69
+ * Approved comments and the form, unless the post has comments turned off. Shows replies one level deep.
70
+ * `heading` replaces "Comments" or, as `false`, hides it while the section keeps "Comments" as its
71
+ * `aria-label`; `formHeading` does the same for "Leave a comment"; `headingLevel` (2 to 6, default 2)
72
+ * sets the section heading's level, with the form heading one below.
73
+ */
74
+ export function PostComments({ post, data, words, heading, formHeading, headingLevel }) {
58
75
  if (post.allowComments === false)
59
76
  return null;
60
- return _jsx(Comments, { postId: post.id, initial: items(data.comments), words: words ? pickWords(words, "blog") : undefined });
77
+ return _jsx(Comments, { postId: post.id, initial: items(data.comments), words: words ? pickWords(words, "blog") : undefined, heading: heading, formHeading: formHeading, headingLevel: headingLevel });
61
78
  }
62
79
  function Home({ record, data, stream, path, words, t }) {
63
80
  const posts = items(data.posts);
package/text.d.ts CHANGED
@@ -26,3 +26,7 @@ export interface Feed {
26
26
  }
27
27
  export declare function rss({ title, siteUrl, feedUrl, items }: Feed): string;
28
28
  export declare function atom({ title, siteUrl, feedUrl, items }: Feed): string;
29
+ /** The levels a theme can give a part's heading. The page's own h1 is the theme's. */
30
+ export type HeadingLevel = 2 | 3 | 4 | 5 | 6;
31
+ /** The tag for a heading at `level`, kept between h2 and h6. */
32
+ export declare function headingTag(level?: number): `h${HeadingLevel}`;
package/text.js CHANGED
@@ -92,3 +92,7 @@ export function atom({ title, siteUrl, feedUrl, items }) {
92
92
  const entries = items.map((item) => `<entry><title>${escapeXml(item.title)}</title><link href="${escapeXml(item.url)}"/><id>${escapeXml(item.url)}</id><published>${escapeXml(item.publishedAt)}</published><updated>${escapeXml(item.updatedAt)}</updated>${item.summary ? `<summary>${escapeXml(item.summary)}</summary>` : ""}</entry>`);
93
93
  return `<?xml version="1.0" encoding="UTF-8"?>\n<feed xmlns="http://www.w3.org/2005/Atom"><title>${escapeXml(title)}</title><link href="${escapeXml(siteUrl)}"/><link rel="self" href="${escapeXml(feedUrl)}"/><id>${escapeXml(feedUrl)}</id><updated>${escapeXml(updated)}</updated>${entries.join("")}</feed>\n`;
94
94
  }
95
+ /** The tag for a heading at `level`, kept between h2 and h6. */
96
+ export function headingTag(level = 2) {
97
+ return `h${Math.min(6, Math.max(2, Math.round(Number.isFinite(level) ? level : 2)))}`;
98
+ }