1
0
mirror of https://github.com/outline/outline.git synced 2025-03-15 19:18:00 +00:00

Add summary column to documents

This commit is contained in:
Tom Moor
2024-02-16 13:25:17 -05:00
parent 0219885548
commit 7555240413
4 changed files with 25 additions and 5 deletions

@ -470,11 +470,6 @@ export default class Document extends ParanoidModel {
duplicate = (options?: { title?: string; recursive?: boolean }) =>
this.store.duplicate(this, options);
getSummary = (paragraphs = 4) => {
const result = this.text.trim().split("\n").slice(0, paragraphs).join("\n");
return result;
};
@computed
get pinned(): boolean {
return !!this.store.rootStore.pins.orderedData.find(

@ -0,0 +1,11 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn("documents", "summary", {
type: Sequelize.TEXT,
allowNull: true,
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn("documents", "summary");
},
};

@ -217,6 +217,13 @@ class Document extends ParanoidModel<
@Column
title: string;
@Length({
max: DocumentValidation.maxSummaryLength,
msg: `Document summary must be ${DocumentValidation.maxSummaryLength} characters or less`,
})
@Column
summary: string;
@Column(DataType.ARRAY(DataType.STRING))
previousTitles: string[] = [];
@ -985,6 +992,10 @@ class Document extends ParanoidModel<
getTimestamp = () => Math.round(new Date(this.updatedAt).getTime() / 1000);
getSummary = () => {
if (this.summary) {
return this.summary;
}
const plainText = DocumentHelper.toPlainText(this);
const lines = compact(plainText.split("\n"));
const notEmpty = lines.length >= 1;

@ -36,6 +36,9 @@ export const DocumentValidation = {
/** The maximum length of the document title */
maxTitleLength: 100,
/** The maximum length of the document summary */
maxSummaryLength: 1000,
/** The maximum size of the collaborative document state */
maxStateLength: 1500 * 1024,
};