搜尋套件、儲存庫與 APP 分類

seo_renderer 封面
套件詳情v0.6.0

seo_renderer

一個 Flutter 外掛程式,用於將文字小部件渲染為 HTML,以達成 SEO 目的。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2080
喜歡數
281
Pub 分數
130

安裝套件

flutter pub add seo_renderer

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

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]

Pub

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.

<body>
  ...
  <script>
    const regExp = new RegExp("bot|google|baidu|bing|msn|teoma|slurp|yandex", "i");
    if (regExp.test(navigator.userAgent)) {
      window.flutterWebRenderer = "html";
    }
  </script>
  ...
</body>
TextRenderer

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.

LinkRenderer(
  text: 'Try Flutter',
  href: 'https://www.flutter.dev',
  child: ...,
)
ImageRenderer

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.

ImageRenderer(
  alt: 'Network Image',
  child: Image.network('https://fakeimg.pl/300x300/?text=Network'),
)

ImageRenderer(
  alt: 'Network Image',
  src: 'https://fakeimg.pl/300x300/?text=Network',
  child: CustomWidget(),
)

ScreenShot & Example

Live example https://seo-renderer.netlify.app/

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.

Author & support

This project is created by Sahdeep Singh

If you appreciate my work you can connect and endorse me on LinkedIn to keep me motivated :)

Don't forget to check out these AWESOME contributors

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。