writer / writer-framework

No-code in the front, Python in the back. An open-source framework for creating data apps.
https://dev.writer.com/framework/introduction
Apache License 2.0
1.32k stars 77 forks source link

Add Metadata for social media sharing #547

Open RianBrand opened 1 month ago

RianBrand commented 1 month ago

When posting a link to social media, the Title is shown as "Writer Framework" and not the AppName. It would be great to be able add opengraph metadata to an app.

FabienArcellier commented 2 weeks ago

Here is a design proposal.

# usage in server_setup.py
writer.serve.configure_page_meta(title='Hello world', opengraph_tags={
  "title": "Hello world"
})

# usage in server_setup.py, call before serving index.html to fetch dynamic data
writer.serve.configure_page_meta(title=generate_title, opengraph_tags=lambda: generate_opengraph)

def configure_page_meta(title: Union[str, Callable[[], str]] = "Writer Framework", opengraph_tags: Union[Dict[str, str], Callable[[], Dict[str, str]] = None) -> None:
    """
    Configure Open Graph metadata for a web page.
    """
    ...

Declaration of Opengraph metadata

<html prefix="og: http://ogp.me/ns#">
<head>
  <meta property="og:title" content="Title of your page">
  <meta property="og:description" content="Description of the page">
  <meta property="og:type" content="website">
  <meta property="og:url" content="https://www.yoursite.com/your-page">
  <meta property="og:image" content="https://www.yoursite.com/image.jpg">
  <meta property="og:locale" content="en_EN">
  <meta property="og:site_name" content="Writer Framework">
</head>

The file index.html will contains the tag <!-- {{ opengraph_tags}} -->. The tag will be replaced when serving the index.html.

image