From fe15003665cae90ec23784a325f9f376f7530b82 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 10 Oct 2019 11:35:48 +0200 Subject: [PATCH] Remove html from tweet preview --- src/formatters.nim | 7 ++++++- src/views/general.nim | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index f40de94..09d4111 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -1,4 +1,5 @@ -import strutils, strformat, sequtils, htmlgen, xmltree, times, uri, tables +import strutils, strformat, sequtils, times, uri, tables +import xmltree, htmlparser, htmlgen import regex import types, utils, query @@ -92,3 +93,7 @@ proc getTwitterLink*(path: string; params: Table[string, string]): string = result = $(parseUri("https://twitter.com") / path ? p) if username.len > 0: result = result.replace("/" & username, "") + +proc getTweetPreview*(text: string): string = + let html = parseHtml(text) + html.innerText() diff --git a/src/views/general.nim b/src/views/general.nim index 0cd70db..dbb4bac 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -57,7 +57,7 @@ proc renderMain*(body: VNode; req: Request; title="Nitter"; titleText=""; desc=" meta(name="viewport", content="width=device-width, initial-scale=1.0") meta(property="og:type", content=`type`) meta(property="og:title", content=titleText) - meta(property="og:description", content=desc) + meta(property="og:description", content=getTweetPreview(desc)) meta(property="og:site_name", content="Nitter") for url in images: