【问题标题】:Generate a custom preview image based on parameters根据参数生成自定义预览图
【发布时间】:2021-01-10 02:09:59
【问题描述】:

当我在 Google 地图上分享指向某个位置的链接时,该链接会附带该位置的预览图像,如下所示:

据我所知,您可以将预览图像作为标签放在网页部分中,如下所示:

<meta property="og:image" content="example.png"/>

但是这个标签是静态的,并没有办法让它动态。那么谷歌地图是如何做到的呢?

【问题讨论】:

    标签: html meta preview


    【解决方案1】:

    Google 可能会做一些特别的事情,因为他们是 Google,但绝对有可能使其成为动态服务器端。如果服务器使用模板渲染页面并且知道它正在渲染的路线,它可以将图像换成另一个图像,甚至动态生成它,例如作为this question 中的base64 图像。

    <meta property="og:image" content="{{ map_location.thumbnail }}"/> 是一个使用 Jinja 模板(用于 Python)的示例。使用 JavaScript 模板字符串的更复杂的示例可能是:

    render(
      `
      <html>
      <!-- other content -->
      <meta property="og:image" content="/images/${request.parameters.id}.png"/>
      <!-- other content -->
      </html>
      `
    )
    

    【讨论】:

      猜你喜欢
      • 2021-04-23
      • 1970-01-01
      • 2021-10-28
      • 2019-11-10
      • 2015-11-26
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      相关资源
      最近更新 更多