View Source z_url_metadata (zotonic_stdlib v1.23.0)

Discover metadata about an url. First follows any redirects and URL shorteners, then fetches the data at the final URL to inspect all metadata tags, content headers and first part of the HTML. The returned opaque metadata can be questioned with properties. The Slackbot user-agent is used for fetching URLs so that the URL shorteners return a location header and other sites are coerced to give correct metadata. Only the first MB of data is fetched, this prevents fetching large objects.

Summary

Functions

Fetch metadata information for the URL
Fetch properties of the fetched metadata

Types

-type metadata() ::
    #url_metadata{final_url :: binary(),
                  content_type :: binary(),
                  content_type_options :: list(),
                  content_length :: integer(),
                  metadata :: list(),
                  is_index_page :: boolean(),
                  headers :: [{binary(), binary()}],
                  partial_data :: binary()}.
-type property() ::
    mime | mime_options | site_name | content_length | url | canonical_url | short_url |
    final_url | headers | title | h1 | summary | tags | filename | mtitle | description |
    keywords | author | charset | language | image | image_nav | thumbnail | icon | icon_nav |
    icon_shortcut | icon_touch |
    binary().

Functions

-spec fetch(binary() | string()) -> {ok, metadata()} | {error, term()}.
Fetch metadata information for the URL
-spec fetch(binary() | string(), z_url_fetch:options()) -> {ok, metadata()} | {error, term()}.
-spec filename(binary() | string(), list()) -> binary() | undefined.
-spec header(binary() | string(), metadata()) -> binary() | undefined.
-spec p(Property, Metadata) -> Value
     when
         Property :: property() | [property()],
         Metadata :: metadata(),
         Value :: binary() | [binary()] | Headers | undefined,
         Headers :: [{binary(), binary()}].
Fetch properties of the fetched metadata