Libreria di queriesAggiungi i link mancanti nel post
Aggiungi i link mancanti nel post
Questa query esegue una ricerca e sostituzione tramite espressione regolare per aggiungere i link mancanti nel contenuto HTML del post.
Tutti gli URL che non sono circondati da un tag di ancoraggio, come:
<p>Visit my website: https://mysite.com.</p>...ricevono il tag <a> corrispondente attorno ad essi (rimuovendo anche il dominio dal testo e aggiungendo un target per aprirsi in una nuova finestra), diventando:
<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
}
}
}