tweb/src/components/wrappers/webPageDescription.ts
Eduard Kuzmenko 26adc2f567 Redesigned sponsored messages
Added `hide` button in sponsored context menu
2023-11-22 18:08:03 +04:00

37 lines
1.1 KiB
TypeScript

/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import limitSymbols from '../../helpers/string/limitSymbols';
import {WebPage} from '../../layer';
import wrapRichText, {WrapRichTextOptions} from '../../lib/richTextProcessor/wrapRichText';
export default function wrapWebPageDescription(
webPage: WebPage.webPage,
richTextOptions?: WrapRichTextOptions,
noLimit?: boolean
) {
if(noLimit) {
return wrapRichText(webPage.description || '', {
...richTextOptions,
entities: webPage.entities
});
}
const shortDescriptionText = limitSymbols(webPage.description || '', 150, 180);
// const siteName = webPage.site_name;
// let contextHashtag = '';
// if(siteName === 'GitHub') {
// const matches = apiWebPage.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/);
// if(matches) {
// contextHashtag = matches[0] + '/issues/{1}';
// }
// }
return wrapRichText(shortDescriptionText, richTextOptions/* , {
contextSite: siteName || 'external',
contextHashtag: contextHashtag
} */);
}