Skip to content

Conversation

@vanbroup
Copy link
Contributor

Implement resources.FromRemote, inspired by #5686

Closes #5255
Supports #9044

@vanbroup
Copy link
Contributor Author

One example use case is the RSS/XML feed parsing as discussed in #9044 another use case could be the generation of Open Graph images (in this case using https://bruzu.com):

   {{- $image := resources.FromRemote ( print "https://img.bruzu.com/?" (querify 
        "bi" "https://example.com/img/og-background.png" "h" "627" "w" "1200"
        "a.oy" "top" "a.ox" "left" "a.x" "100" "a.y" "100" "a.w" "1000" "a.h" "68" "a.c" "#ffffff" "a.ta" "left" "a.fs" "40" "a.lh" "1" "a.fw" "900" "a.ff" "Roboto" "a.maxHeight" "120"
        "b.tp" "textbox" "b.x" "100" "b.y" "200" "b.w" "1000" "b.h" "244" "b.oy" "top" "b.ox" "left" "b.c" "#ffffff" "b.ta" "left" "b.fs" "20" "b.lh" "1.2" "b.fw" "400" "b.ff" "Roboto" "b.ox" "left" "b.oy" "top" "b.maxHeight" "250"
        "a.t" .Title
        "b.t" .Summary
    )) -}}
    <meta property="og:image" content="{{ $image.Permalink }}" />
@bep bep changed the title Implement resources.FromRemote Nov 28, 2021
@bep bep changed the title Add reemote support to resources.Get Nov 29, 2021
@vanbroup
Copy link
Contributor Author

Addressed the comments and implemented options, you can now specify the request headers in the options, optionally combined with a request method and body (see also related issue #7699).

{{ $postResponse := resources.Get "https://example.org/api"  (dict 
    "method" "post"
    "body" `{"complete": true}` 
    "headers" (dict 
        "Content-Type" "application/json"
    )
)}}
@bep
Copy link
Member

bep commented Nov 30, 2021

I will merge this once the tests go green, it looks very good, I really like how the API turned out.

@bep bep merged commit 8aa7257 into gohugoio:master Nov 30, 2021
@vanbroup vanbroup deleted the FromRemote branch November 30, 2021 12:24
@github-actions
Copy link

github-actions bot commented Dec 1, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants