From 8cf3151998bb3ff1995c5b4ad740722d7cc02035 Mon Sep 17 00:00:00 2001 From: Fabien Arcellier Date: Mon, 21 Oct 2024 17:36:24 +0200 Subject: [PATCH 1/6] feat: add metadata for social media sharing * feat: implement configure_page_head signature --- src/writer/serve.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/writer/serve.py b/src/writer/serve.py index c2b23e62d..38ad1636d 100644 --- a/src/writer/serve.py +++ b/src/writer/serve.py @@ -556,6 +556,70 @@ async def lifespan(app: FastAPI): async with _lifespan_invoke(writer_lifespans, app): yield +def configure_page_head( + title: Union[str, Callable[[], str]] = "Writer Framework", + meta: Optional[Union[Dict[str, Any], Callable[[], Dict[str, Any]]]] = None, + opengraph_tags: Optional[Union[Dict[str, Any], Callable[[], Dict[str, Any]]]] = None +): + """ + Configures the page header for SEO and social networks. + + >>> writer.serve.configure_page_head( + >>> title="my App", + >>> meta={ + >>> "description": "my amazing app", + >>> "keywords": "WF, Amazing, AI App", + >>> "author": "Amazing company" + >>> } + >>>) + + Meta will accept description, keywords, author. Other meta tags as view port won't be supported. + + Settings accept functions to adapt content based on application data. + + >>> def generated_title(): + >>> return "My App" # load title using info from database + + >>> def generated_meta_tags(): + >>> { + >>> "description": "my amazing app", + >>> "keywords": "WF, Amazing, AI App", + >>> "author": "Amazing company" + >>> } + + >>> writer.serve.configure_page_head( + >>> title=generated_title + >>> meta=generated_meta_tags + >>> ) + + OpenGraph tags are used by social networks to display information about the page. WF support them. + + >>> writer.serve.configure_page_head( + >>> title=generated_title + >>> opengraph_tags= { + >>> "og:title": "My App", + >>> "og:description": "My amazing app", + >>> "og:image": "https://myapp.com/logo.png", + >>> "og:url": "https://myapp.com" + >>> } + >>> ) + + >>> def generated_opengraph_tags(): + >>> return { + >>> "og:title": "My App", + >>> "og:description": "My amazing app", + >>> } + + >>> writer.serve.configure_page_head( + >>> title=generated_title + >>> opengraph_tags= generated_opengraph_tags + >>> ) + + :param title: The title of the page. + :param meta: A list of meta tags. + :param opengraph_tags: A dictionary of OpenGraph tags. + """ + pass @asynccontextmanager async def _lifespan_invoke(context: list, app: FastAPI): From 17ef41d7cc11eebb499ad590f724c3f987b56f1b Mon Sep 17 00:00:00 2001 From: Fabien Arcellier Date: Mon, 28 Oct 2024 10:41:31 +0100 Subject: [PATCH 2/6] feat: add metadata for social media sharing * feat: implement the settings --- src/ui/index.html | 2 ++ src/writer/serve.py | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ui/index.html b/src/ui/index.html index ba5bd9749..f9b53bc63 100644 --- a/src/ui/index.html +++ b/src/ui/index.html @@ -5,6 +5,8 @@ Writer Framework + +