Query 库使用正则表达式在文章中搜索并替换多个字符串
使用正则表达式在文章中搜索并替换多个字符串
此 query 检索一篇文章,将文章内容和标题中所有匹配正则表达式字符串列表的部分替换为指定的字符串列表,然后重新保存该文章。
query GetPostData(
$postId: ID!
$searchRegex: [String!]!,
$replaceWith: [String!]!
) {
post(by: { id: $postId }, status: any) {
title
adaptedPostTitle: _strRegexReplaceMultiple(
searchRegex: $searchRegex
replaceWith: $replaceWith
in: $__title
)
@export(as: "adaptedPostTitle")
rawContent
adaptedRawContent: _strRegexReplaceMultiple(
searchRegex: $searchRegex
replaceWith: $replaceWith
in: $__rawContent
)
@export(as: "adaptedRawContent")
}
}
mutation RegexSearchAndReplaceStringsInPost($postId: ID!)
@depends(on: "GetPostData")
{
updatePost(input: {
id: $postId,
title: $adaptedPostTitle,
contentAs: { html: $adaptedRawContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
rawContent
}
}
}