DEV Community

Camilo
Camilo

Posted on

2

Liquor Tags - Fetch OpenGraph data and Render the output

Liquor Tags. Inspired by dev.to embed tags (liquid tags),
takes Open Graph data from URLs and generate output using pseudo EEx templates.
Useful when creating previews of websites using Open Graph data.

Installation

Mix.install([
  {:liquor, "~> 1.0.0"},
  {:req, "~> 0.4.14"}, # Just for demostration
  {:kino, "~> 0.12.3"} # Just for demostration
])
Enter fullscreen mode Exit fullscreen mode
alias Liquor.Tags.Tag

content = """
{% github ElixirCL %}
{% embed https://ninjas.cl %}
"""

tags = [
  Tag.new("github", "Github: <%= og.url %>", "https://github.com"),
  Tag.new("embed", "Website: <%= og.title %>")
]

# Fetch only needs to return the HTML string
fetch = fn url -> Req.get!(url) |> then(& &1.body) end

Liquor.render(content, tags, fetch)
|> Kino.Text.new()
Enter fullscreen mode Exit fullscreen mode

Renders

Github: https://github.com/ElixirCL
Website: Ninja Software Chile (Ninjas.cl)
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay