Thư viện QueriesHiển thị tất cả liên kết trong tất cả bài viết
Hiển thị tất cả liên kết trong tất cả bài viết
Query này hiển thị tất cả liên kết được thêm vào trong tất cả bài viết.
Nó tìm tất cả các chuỗi <a href="(...)">(...)</a> trong tất cả bài viết và liệt kê chúng trong phản hồi dưới dạng { href: (...), text: (...) }.
query GetPostLinks {
posts(pagination: { limit: -1 }) {
id
title
# Get the post content, and identify the links
rawContent
@remove
adaptedRawContent: _strRegexReplace(
searchRegex: "#<a.*(?=href=\"([^\"]*)\")[^>]*>([^<]*)<\/a>#i",
replaceWith: "*****|||||$1|||||$2*****",
in: $__rawContent
)
@remove
# Extract the links into an object { href: ..., text: ...}
links: _strSplit(
string: $__adaptedRawContent,
separator: "*****"
)
@underEachArrayItem(
passValueOnwardsAs: "entry"
affectDirectivesUnderPos: [1, 2, 3]
)
@applyField(
name: "_strStartsWith"
arguments: {
search: "|||||"
in: $entry
}
passOnwardsAs: "isMatch"
)
@applyField(
name: "_not"
arguments: {
value: $isMatch
}
passOnwardsAs: "isNotMatch"
)
@if(
condition: $isNotMatch
)
@setNull
@arrayFilter
@underEachArrayItem(
passValueOnwardsAs: "match"
affectDirectivesUnderPos: [1, 2, 3, 4]
)
@applyField(
name: "_strSplit"
arguments: {
separator: "|||||"
string: $match
}
passOnwardsAs: "matchSplit"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $matchSplit
position: 1
}
passOnwardsAs: "matchHref"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $matchSplit
position: 2
}
passOnwardsAs: "matchText"
)
@applyField(
name: "_echo"
arguments: {
value: {
href: $matchHref
text: $matchText
}
}
setResultInResponse: true
)
}
}