Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): truncate long link text on publish or edit article #3995

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
528 changes: 266 additions & 262 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@keyv/redis": "^2.6.1",
"@matters/apollo-response-cache": "^2.0.0-alpha.0",
"@matters/ipns-site-generator": "^0.1.6",
"@matters/matters-editor": "^0.2.5-alpha.0",
"@matters/matters-editor": "^0.2.5-alpha.6",
"@matters/passport-likecoin": "^1.0.0",
"@matters/slugify": "^0.7.3",
"@sendgrid/helpers": "^7.7.0",
Expand Down
2 changes: 2 additions & 0 deletions src/common/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ export enum ActivityType {
UserAddArticleTagActivity = 'UserAddArticleTagActivity',
}

export const MAX_CONTENT_LINK_TEXT_LENGTH = 20

export const MAX_ARTICLE_TITLE_LENGTH = 100
export const MAX_ARTICLE_SUMMARY_LENGTH = 200
export const MAX_ARTICLE_CONTENT_LENGTH = 50e3
Expand Down
9 changes: 8 additions & 1 deletion src/connectors/queue/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {

import {
ASSET_TYPE,
MAX_CONTENT_LINK_TEXT_LENGTH,
MIGRATION_DELAY,
MIGTATION_SOURCE,
QUEUE_CONCURRENCY,
Expand Down Expand Up @@ -129,7 +130,13 @@ export class MigrationQueue extends BaseQueue {
sanitizeHTML(content, {
maxHardBreaks: -1,
maxSoftBreaks: -1,
})
}),
{
truncate: {
maxLength: MAX_CONTENT_LINK_TEXT_LENGTH,
keepProtocol: false,
},
}
),
})

Expand Down
9 changes: 8 additions & 1 deletion src/mutations/article/editArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MAX_ARTICLE_REVISION_COUNT,
NODE_TYPES,
USER_STATE,
MAX_CONTENT_LINK_TEXT_LENGTH,
} from 'common/enums'
import {
ArticleNotFoundError,
Expand Down Expand Up @@ -317,7 +318,13 @@ const resolver: GQLMutationResolvers['editArticle'] = async (
const { content: lastContent } =
await atomService.articleContentIdLoader.load(articleVersion.contentId)
const processed = normalizeArticleHTML(
sanitizeHTML(content, { maxHardBreaks: -1, maxSoftBreaks: -1 })
sanitizeHTML(content, { maxHardBreaks: -1, maxSoftBreaks: -1 }),
{
truncate: {
maxLength: MAX_CONTENT_LINK_TEXT_LENGTH,
keepProtocol: false,
},
}
)
const changed = processed !== lastContent

Expand Down
20 changes: 19 additions & 1 deletion src/mutations/article/publishArticle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import type { GQLMutationResolvers } from 'definitions'

import { PUBLISH_STATE, USER_STATE } from 'common/enums'
import {
normalizeArticleHTML,
sanitizeHTML,
} from '@matters/matters-editor/transformers'

import {
MAX_CONTENT_LINK_TEXT_LENGTH,
PUBLISH_STATE,
USER_STATE,
} from 'common/enums'
import {
DraftNotFoundError,
ForbiddenByStateError,
Expand Down Expand Up @@ -58,6 +67,15 @@ const resolver: GQLMutationResolvers['publishArticle'] = async (
}

const draftPending = await draftService.baseUpdate(draft.id, {
content: normalizeArticleHTML(
sanitizeHTML(draft.content, { maxHardBreaks: -1, maxSoftBreaks: -1 }),
{
truncate: {
maxLength: MAX_CONTENT_LINK_TEXT_LENGTH,
keepProtocol: false,
},
}
),
publishState: PUBLISH_STATE.pending,
iscnPublish,
})
Expand Down
Loading