seo_renderer 包是一个专为 Flutter Web 应用设计的 Flutter 插件,可使文本组件以 HTML 形式渲染,从而提升搜索引擎优化效果。通过将 Flutter 的文本组件转换为静态 HTML,它在不牺牲应用动态功能的前提下增强了 SEO 可见性。该包特别适用于内容密集型的 Web 应用,其中可发现性至关重要。它支持所有主要平台,包括 Web、Android、iOS、macOS、Windows 和 Linux,确保在各种环境下的渲染一致性。
适合场景
改进Flutter网页内容的SEO
为搜索引擎渲染静态文本
提高博客或文章页面的可见性
优化文档站点
支持网络爬虫的结构化文本
启用服务器端文本渲染
主要特点
将 Flutter Text 小部件转换为 HTML
提高搜索引擎索引效果
跨平台兼容性
轻量且易于集成
保留文本格式
与 Flutter Web 无缝配合
适合对象
内容驱动的 Flutter 网页应用
博客和新闻网站
文档门户
面向搜索引擎优化的网络应用
注重网络可见性的开发者
使用建议
非SEO使用场景无需此功能
可能会略微增加包大小
最适合用于静态或半静态内容
在动态 UI 中需要谨慎处理
仅限文本渲染,不支持完整的组件转换
对大文本块的性能影响
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
SEO Renderer [Not Maintaining]
Alternative : https://pub.dev/packages/seo
A flutter plugin (under development) to render text, link, image widgets as html elements for SEO purpose.
Created specifically for issue https://github.com/flutter/flutter/issues/46789
It will automatic detect the crawler using regex and navigator userAgent and add the HtmlElement you choose to the DOM.
All PR's are welcome :)
Getting Started
Add this to your pubspec.yaml
dependencies:seo_renderer:^0.6.0
Get the package from Pub:
flutter packages get
Import it in your file
import'package:seo_renderer/seo_renderer.dart';
Usage
It's required to add a RobotDetector to detect if page is visited by a robot and add seoRouteObserver to observe when widgets change their visibility. To do this simply wrap MaterialApp within RobotDetector and add seoRouteObserver in navigatorObservers:
runApp(
RobotDetector(
debug: true, // you can set true to enable robot mode
child: MaterialApp(
home: MyApp(),
navigatorObservers: [seoRouteObserver],
),
),
);
For more complex projects it's recommended to add these lines in index.html which will force html web renderer in case robot is detected. It's because canvaskit has some stricter limits and potenitally can break.
To render html text element above a child you pass Text, RichText as the child or simply set the text.
TextRenderer(
child: Text(
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
),
)
TextRenderer(
text: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
child: CustomWidget(),
)
Optionally you can change the html element between <h1> to <h6> and <p> by setting style. Default value is TextRendererStyle.paragraph.
TextRenderer(
style: TextRendererStyle.paragraph,
child: Text(
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
),
)
TextRenderer(
style: TextRendererStyle.header1,
child: Text(
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
),
)
LinkRenderer
To render html link element above a child set text and href.
To render html image element above a child set alt and pass Image.network(...), Image.asset(...), Image.memory(...) as the child or simply set the src.
Select GoogleBot here's how as userAgent in Network Condition and refresh the page to see created Div Elements.
License
MIT License
Copyright (c) 2021 Sahdeep Singh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.