fix: exclude link-only text blocks from search results; refs #180

This commit is contained in:
Hossein Mehrabi 2023-09-05 22:35:09 +03:30
parent c0f584918a
commit 124e70a968
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
3 changed files with 6 additions and 2 deletions

View File

@ -22,12 +22,14 @@ export const TextBlockDataType: UnbodyDataTypeConfig<
if (text.length > 0 || html.length > 0) {
const isLink =
/^<p[^>]*><span[^>]*><a[^>]*href="(https):\/\/[^ "]+"[^>]*>.*<\/a><\/span><\/p>$/.test(
/^<p[^>]*>(<span[^>]*>[\s]*<\/span>)*<span[^>]*><a[^>]*href="(https):\/\/[^ "]+"[^>]*>.*<\/a><\/span>(<span[^>]*>(\s|(<br(\/)?>))*<\/span>)*<\/p>$/.test(
html,
)
const isIframe = /<iframe[^>]*>(?:<\/iframe>|[^]*?<\/iframe>)/.test(text)
if (isLink) {
labels.push(LPE.Post.ContentBlockLabels.LinkOnly)
const youtube = html.match(
/(https?\:\/\/)?((www\.)?youtube\.com|youtu\.?be)\/[^ "]+/gi,
)

View File

@ -62,6 +62,7 @@ export namespace LPE {
Paragraph: 'paragraph',
CoverImage: 'cover_image',
Embed: 'embed',
LinkOnly: 'link_only',
YoutubeEmbed: 'youtube_embed',
SimplecastEmbed: 'simplecast_embed',
} as const

View File

@ -13,7 +13,8 @@ export const searchBlocksBasicFilter = (
if (block.type === LPE.ContentTypes.Text) {
return (
!isTitle(block.data as LPE.Post.TextBlock) &&
isLongEnough(block.data as LPE.Post.TextBlock)
isLongEnough(block.data as LPE.Post.TextBlock) &&
!block.data.labels.includes('link_only')
)
} else {
const isPodcastImage = block.data.document.type === LPE.PostTypes.Podcast