fix: includeTitle option does not work with collection input (#11185)

* fix: includeTitle option does not work with collection input

* test
This commit is contained in:
Tom Moor authored and GitHub committed 2026-01-14 23:48:06 -05:00
1 parent ec87cb0308
commit 4d3f9bf0b4
3 files changed
+71 -13

No files matched your search

+59 -1
View File
@@ -1,5 +1,5 @@
import Revision from "@server/models/Revision";
import { buildDocument } from "@server/test/factories";
import { buildCollection, buildDocument } from "@server/test/factories";
import { ChangesetHelper } from "@shared/editor/lib/ChangesetHelper";
import { EditorStyleHelper } from "@shared/editor/styles/EditorStyleHelper";
import { DocumentHelper } from "./DocumentHelper";
@@ -608,6 +608,64 @@ This is a [test paragraph](https://example.net)`,
expect(result).toContain("[ ] todo");
expect(result).toContain("[x] done");
});
it("should include collection title by default", async () => {
const collection = await buildCollection({
name: "Test Collection",
content: {
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "text", text: "Collection description" }],
},
],
},
});
const result = await DocumentHelper.toMarkdown(collection);
expect(result).toContain("# Test Collection");
expect(result).toContain("Collection description");
});
it("should include collection emoji icon in title", async () => {
const collection = await buildCollection({
name: "Test Collection",
icon: "📚",
content: {
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "text", text: "Collection description" }],
},
],
},
});
const result = await DocumentHelper.toMarkdown(collection);
expect(result).toContain("# 📚 Test Collection");
});
it("should not include collection title when includeTitle is false", async () => {
const collection = await buildCollection({
name: "Test Collection",
icon: "📚",
content: {
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "text", text: "Collection description" }],
},
],
},
});
const result = await DocumentHelper.toMarkdown(collection, {
includeTitle: false,
});
expect(result).not.toContain("# ");
expect(result).not.toContain("Test Collection");
expect(result).toContain("Collection description");
});
});
describe("toPlainText", () => {
+6 -10
View File
@@ -188,20 +188,16 @@ export class DocumentHelper {
.replace(/’/g, "'")
.trim();
if (document instanceof Collection) {
return text;
}
if (
(document instanceof Document || document instanceof Revision) &&
(document instanceof Collection ||
document instanceof Document ||
document instanceof Revision) &&
options?.includeTitle !== false
) {
const iconType = determineIconType(document.icon);
const title = `${iconType === IconType.Emoji ? document.icon + " " : ""}${
document.title
}`;
const name =
document instanceof Collection ? document.name : document.title;
const title = `${iconType === IconType.Emoji ? document.icon + " " : ""}${name}`;
return `# ${title}\n\n${text}`;
}
+6 -2
View File
@@ -86,7 +86,9 @@ router.post(
});
if (data) {
collection.description = await DocumentHelper.toMarkdown(collection);
collection.description = await DocumentHelper.toMarkdown(collection, {
includeTitle: false,
});
}
await collection.saveWithCtx(ctx);
@@ -641,7 +643,9 @@ router.post(
if (data !== undefined) {
collection.content = data;
collection.description = await DocumentHelper.toMarkdown(collection);
collection.description = await DocumentHelper.toMarkdown(collection, {
includeTitle: false,
});
}
if (icon !== undefined) {