Fix content link grids
This commit is contained in:
@@ -79,7 +79,6 @@ export type ParsedInvoice = {
|
|||||||
export type ParsedLinkValue = {
|
export type ParsedLinkValue = {
|
||||||
url: URL
|
url: URL
|
||||||
meta: Record<string, string>
|
meta: Record<string, string>
|
||||||
isMedia: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ParsedLinkGridValue = {
|
export type ParsedLinkGridValue = {
|
||||||
@@ -265,7 +264,7 @@ export const parseLink = (text: string, context: ParseContext): ParsedLink | voi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {type: ParsedType.Link, value: {url, meta, isMedia: urlIsMedia(url.pathname)}, raw: link}
|
return {type: ParsedType.Link, value: {url, meta}, raw: link}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseNewline = (text: string, context: ParseContext): ParsedNewline | void => {
|
export const parseNewline = (text: string, context: ParseContext): ParsedNewline | void => {
|
||||||
@@ -436,21 +435,22 @@ export const truncate = (
|
|||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reduceLinks = (content: Parsed[]) => {
|
export const reduceLinks = (content: Parsed[]): Parsed[] => {
|
||||||
let images: URL[] = []
|
let links: ParsedLinkValue[] = []
|
||||||
let newLine: ParsedNewline | null = null
|
let newLine: ParsedNewline | null = null
|
||||||
let emptyText: ParsedText | null = null
|
let emptyText: ParsedText | null = null
|
||||||
const parsedContent = []
|
const parsedContent = []
|
||||||
|
|
||||||
for (const parsed of content) {
|
for (const parsed of content) {
|
||||||
if (isImage(parsed)) {
|
if (isImage(parsed)) {
|
||||||
images.push((parsed.value as ParsedLinkValue).url)
|
links.push(parsed.value)
|
||||||
} else if (images.length && isNewline(parsed)) {
|
} else if (links.length && isNewline(parsed)) {
|
||||||
newLine = parsed
|
newLine = parsed
|
||||||
} else if (images.length && isText(parsed) && !parsed.value.trim()) {
|
} else if (links.length && isText(parsed) && !parsed.value.trim()) {
|
||||||
emptyText = parsed
|
emptyText = parsed
|
||||||
} else if (images.length) {
|
} else if (links.length) {
|
||||||
parsedContent.push({type: ParsedType.LinkGrid, value: {links: [...images]}})
|
parsedContent.push({type: ParsedType.LinkGrid, value: {links}, raw: ""} as ParsedLinkGrid)
|
||||||
|
|
||||||
if (newLine) {
|
if (newLine) {
|
||||||
parsedContent.push(newLine)
|
parsedContent.push(newLine)
|
||||||
newLine = null
|
newLine = null
|
||||||
@@ -458,14 +458,17 @@ export const reduceLinks = (content: Parsed[]) => {
|
|||||||
parsedContent.push(emptyText)
|
parsedContent.push(emptyText)
|
||||||
emptyText = null
|
emptyText = null
|
||||||
}
|
}
|
||||||
images = []
|
|
||||||
|
links = []
|
||||||
} else {
|
} else {
|
||||||
parsedContent.push(parsed)
|
parsedContent.push(parsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (images.length) {
|
|
||||||
parsedContent.push({type: ParsedType.LinkGrid, value: {links: [...images]}})
|
if (links.length) {
|
||||||
|
parsedContent.push({type: ParsedType.LinkGrid, value: {links}, raw: ""} as ParsedLinkGrid)
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedContent
|
return parsedContent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user