Skip to content

Instantly share code, notes, and snippets.

@22rw
Created August 26, 2025 15:55
Show Gist options
  • Select an option

  • Save 22rw/95bf685c00fe3d92a5e116f2614eada8 to your computer and use it in GitHub Desktop.

Select an option

Save 22rw/95bf685c00fe3d92a5e116f2614eada8 to your computer and use it in GitHub Desktop.

#meta

og = {}

function og.fetch(url) 
  local response = http.request(url)
  if response.ok then
    local parser = js.new(js.window.DOMParser)
    local document = parser.parseFromString(response.body, "text/html")
    local og_properties = {}
    for meta in each(document.getElementsByTagName("meta")) do
      local prop = tostring(meta.getAttribute("property"))
      if prop:startsWith("og:") then
        og_properties[prop:sub(4)] = meta.getAttribute("content")
      end
    end
    return og_properties
  else
    return { error = "Status code "..response.status }
  end
end

function og.card(url, width)
  width = width or 350
  local og = og.fetch(url)
  if og.error then return widget.markdown("==OG Error: "..og.error.."==") end
  return widget.html(dom.div {
    style = "width:"..width.."px;background-color:rgba(0,0,0,0.15);padding:3px 10px;border-radius:5px;",
    dom.sub { og.site or og.site_name }, dom.br {}, 
    dom.h3 { dom.a { href = og.url, og.title } },
    dom.p { og.description or "" },
    dom.img {
      style = "width:"..width.."px;border-radius:5px;",
      src = og.image
    }
  })
end

Example

${og.card("https://store.steampowered.com/app/3496520/MIO_Memories_in_Orbit_Demo/")}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment