Queries-BibliothekFehlende Links im Beitrag hinzufügen
Fehlende Links im Beitrag hinzufügen
Diese query führt eine Regex-Suche und -Ersetzung durch, um fehlende Links im HTML-Inhalt des Beitrags hinzuzufügen.
Alle URLs, die nicht von einem Anker-Tag umgeben sind, wie zum Beispiel:
<p>Visit my website: https://mysite.com.</p>...erhalten das entsprechende <a>-Tag darum (wobei auch die Domain aus dem Text entfernt und ein Target zum Öffnen in einem neuen Fenster hinzugefügt wird), und werden zu:
<p>Visit my website: <a href="https://mysite.com" target="_blank">mysite.com</a>.</p>query GetPostData($postId: ID!) {
post(by: { id: $postId }, status: any) {
id
rawContent
adaptedRawContent: _strRegexReplace(
searchRegex: "#\\s+((https?)://(\\S*?\\.\\S*?))([\\s)\\[\\]{},;\"\\':<]|\\.\\s|$)#i"
replaceWith: "<a href=\"$1\" target=\"_blank\">$3</a>$4"
in: $__rawContent
)
@export(as: "adaptedRawContent")
}
}
mutation AddMissingLinksInPost($postId: ID!)
@depends(on: "GetPostData")
{
updatePost(input: {
id: $postId,
contentAs: { html: $adaptedRawContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
rawContent
}
}
}