Queries-Bibliothek
Queries-BibliothekAlle Links in allen Beiträgen anzeigen

Alle Links in allen Beiträgen anzeigen

Diese query zeigt alle Links an, die in allen Beiträgen hinzugefügt wurden.

Sie findet alle <a href="(...)">(...)</a>-Strings in allen Beiträgen und listet sie in der Antwort als { href: (...), text: (...) } auf.

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
        )
  }
}