fix: issues with displaying mention text (#7773)

* fix: some mention text can not display correctly

* fix: remove the image widget from bookmark if the image url is null
This commit is contained in:
Morn 2025-04-21 10:45:27 +08:00 committed by GitHub
parent 3451100b80
commit 04407fe8ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 21 deletions

View file

@ -161,25 +161,13 @@ class CustomLinkPreviewWidget extends StatelessWidget {
}
Widget buildImage(BuildContext context) {
if (imageUrl?.isEmpty ?? true) {
return SizedBox.shrink();
}
final theme = AppFlowyTheme.of(context),
fillScheme = theme.fillColorScheme,
iconScheme = theme.iconColorScheme;
final width = UniversalPlatform.isDesktopOrWeb ? 160.0 : 120.0;
Widget child;
if (imageUrl?.isNotEmpty ?? false) {
child = FlowyNetworkImage(
url: imageUrl!,
width: width,
);
} else {
child = Center(
child: FlowySvg(
FlowySvgs.toolbar_link_earth_m,
color: iconScheme.secondary,
size: Size.square(30),
),
);
}
return ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16.0),
@ -188,7 +176,17 @@ class CustomLinkPreviewWidget extends StatelessWidget {
child: Container(
width: width,
color: fillScheme.quaternary,
child: child,
child: FlowyNetworkImage(
url: imageUrl!,
width: width,
errorWidgetBuilder: (_, __, ___) => Center(
child: FlowySvg(
FlowySvgs.toolbar_link_earth_m,
color: iconScheme.secondary,
size: Size.square(30),
),
),
),
),
);
}

View file

@ -3,6 +3,7 @@ import 'package:appflowy_backend/log.dart';
// ignore: depend_on_referenced_packages
import 'package:html/parser.dart' as html_parser;
import 'package:http/http.dart' as http;
import 'dart:convert';
abstract class LinkInfoParser {
Future<LinkInfo?> parse(
@ -38,12 +39,19 @@ class DefaultParser implements LinkInfoParser {
if (code != 200 && isHome) {
throw Exception('Http request error: $code');
}
// else if (!isHome && code == 403) {
// uri = Uri.parse('${uri.scheme}://${uri.host}/');
// response = await http.get(uri).timeout(timeout);
// }
final document = html_parser.parse(response.body);
final contentType = response.headers['content-type'];
final charset = contentType?.split('charset=').lastOrNull;
String body = '';
if (charset == null ||
charset.toLowerCase() == 'latin-1' ||
charset.toLowerCase() == 'iso-8859-1') {
body = latin1.decode(response.bodyBytes);
} else {
body = utf8.decode(response.bodyBytes, allowMalformed: true);
}
final document = html_parser.parse(body);
final siteName = document
.querySelector('meta[property="og:site_name"]')