Skip to content

Commit

Permalink
Merge pull request #3995 from thematters/feat/truncate-link
Browse files Browse the repository at this point in the history
feat(editor): truncate long link text on publish or edit article
  • Loading branch information
robertu7 authored Jun 14, 2024
2 parents fd47716 + e71bcaf commit 448f48b
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 266 deletions.
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

0 comments on commit 448f48b

Please sign in to comment.