From 0d489574df4a11e0a6fc1a17b039c3c5e0fdbe10 Mon Sep 17 00:00:00 2001 From: teidesu Date: Thu, 10 Jun 2021 17:26:28 +0300 Subject: [PATCH] fix(tl-reference): fixed html in previews, fixed some links --- tl-reference/scripts/prepare-data.js | 16 +++++++++++++++- .../src/components/objects/link-to-tl.tsx | 2 +- tl-reference/src/templates/tl-object.tsx | 3 ++- tl-reference/src/types.tsx | 1 + tl-reference/tsconfig.json | 5 +++-- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tl-reference/scripts/prepare-data.js b/tl-reference/scripts/prepare-data.js index 11589cfc..5989d0c2 100644 --- a/tl-reference/scripts/prepare-data.js +++ b/tl-reference/scripts/prepare-data.js @@ -35,6 +35,7 @@ function convertToArrays(ns) { } const marked = require('marked') +const cheerio = require('cheerio') const pascalToCamel = (s) => s[0].toLowerCase() + s.substr(1) const camelToSnake = (str) => @@ -147,8 +148,21 @@ function prepareData(data) { } // render descriptions in markdown - if (item.description) + if (item.description) { item.description = renderDescription(item.description) + item.descriptionExcerpt = cheerio.load(item.description).root().text().trim() + if (item.descriptionExcerpt.length > 100) { + const words = item.descriptionExcerpt.split(' ') + let i = 0 + let result = words[i++] + + while (result.length < 90) { + result += ' ' + words[i++] + } + + item.descriptionExcerpt = result + '...' + } + } if (item.arguments) item.arguments.forEach((arg) => { if (arg.description) diff --git a/tl-reference/src/components/objects/link-to-tl.tsx b/tl-reference/src/components/objects/link-to-tl.tsx index 771a39e9..bbfd4653 100644 --- a/tl-reference/src/components/objects/link-to-tl.tsx +++ b/tl-reference/src/components/objects/link-to-tl.tsx @@ -19,10 +19,10 @@ export function LinkToTl( history?: boolean ): React.ReactElement { if (typeof prefix !== 'string') { + history = !!type type = prefix.type name = prefix.name prefix = prefix.prefix - history = !!type } // this kind of invocation is used in parameters table and for return type diff --git a/tl-reference/src/templates/tl-object.tsx b/tl-reference/src/templates/tl-object.tsx index b1b79d7b..be01262a 100644 --- a/tl-reference/src/templates/tl-object.tsx +++ b/tl-reference/src/templates/tl-object.tsx @@ -89,7 +89,7 @@ export default function TlObject({ data }: { data: GraphqlResult }) {