跳至主要內容
WordPress.org

Taiwan 正體中文

  • 佈景主題目錄
  • 外掛目錄
  • 最新消息
  • 技術支援
  • 關於我們
  • 團隊
  • 取得 WordPress
取得 WordPress
WordPress.org

Plugin Directory

Block Metadata

  • 提交外掛
  • 我的最愛
  • 登入
  • 提交外掛
  • 我的最愛
  • 登入

這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

Block Metadata

由 leoloso 開發
下載
  • 詳細資料
  • 使用者評論
  • 安裝方式
  • 開發資訊
技術支援

外掛說明

This plugin helps convert WordPress into a manager of our digital content, to publish it in different mediums or platforms: not just the website, but also email, iOS/Android apps, home-assistants (like Amazon Alexa) and others.

It does this by extracting the metadata from all Gutenberg blocks inside of a blog post. Because each Gutenberg block stores its own content and properties, these ones can be extracted as metadata and exported through a JSON object, accessible through a REST API endpoint, to feed any application on any platform.

The plugin makes the following REST API endpoints available:

  • /wp-json/block-metadata/v1/metadata/{POST_ID}: Extract all metadata from all Gutenberg blocks in a blog post with id {POST_ID}, converted to medium-agnostic (eg: removing all non-semantic HTML tags)
  • /wp-json/block-metadata/v1/data/{POST_ID}: Extract all data from all Gutenberg blocks in a blog post with id {POST_ID}, as originally stored in the block by Gutenberg (eg: containing HTML code)

Demonstration:

  • Blog post
  • Blog post’s Gutenberg blocks
  • Blog post’s medium-agnostic metadata

How does it work?

This plugin is based on the strategy called “Create Once, Publish Everywhere” (also called “COPE”), which reduces the amount of work needed to publish our content into different mediums by establishing a single source of truth for all content.

Having content that works everywhere is not a trivial task, since each medium will have its own requirements. For instance, whereas HTML is valid for printing content for the web, this language is not valid for an iOS/Android app; similarly, we can add classes to our HTML for the web, but these must be converted to styles for email.

The solution is to separate form from content: The presentation and the meaning of the content must be decoupled, and only the meaning is used as the single source of truth. The presentation can then be added in another layer, specific to the selected medium. For instance, given the following piece of HTML code, the <p> is an HTML tag which applies mostly for the web, and attribute class=”align-center” is presentation (placing an element “on the center” makes sense for a screen-based medium, but not for an audio-based one such as Amazon Alexa):

<p class="align-center">Hello world!</p>

Hence, this piece of content cannot be used as a single source of truth, and it must be converted into a format which separates the meaning from the presentation, such as the following piece of JSON code:

{
  content: "Hello world!",
  placement: "center",
  type: "paragraph"
}

This piece of code can be used as a single source of truth for content, since from it we can recreate once again the HTML code to use for the web, and procure an appropriate format for other mediums.

Supported Gutenberg blocks

This plugin attempts to extract the metadata for all Gutenberg blocks shipped in WordPress core; support for additional blocks, such as from plugins, can be added through hooks. Not all Gutenberg blocks can be supported (for instance, because they may only work for the web, or only make sense when applied to screen-based mediums, among other reasons).

The following WordPress core blocks are currently not supported:

  • "core/columns"
  • "core/column"
  • "core/cover"
  • "core/html"
  • "core/table"
  • "core/button"
  • "core/media-text"

The following Gutenberg blocks are supported, and this plugin extracts their metadata:

  • "core/paragraph"
  • "core/image"
  • "core-embed/youtube" (all other "core-embed" blocks can also be extracted, but must be implemented through a hook)
  • "core/heading"
  • "core/gallery"
  • "core/list"
  • "core/audio"
  • "core/file"
  • "core/video"
  • "core/code"
  • "core/preformatted"
  • "core/quote"
  • "core/pullquote"
  • "core/verse"

Extracting metadata for additional blocks

We can extend this plugin to extract the metadata for additional blocks, such as those shipped through plugins. To do this, simply add a hook for filter "Leoloso\BlockMetadata\Metadata::blockMeta" (located in function get_block_metadata($block_data) from class Metadata in file block-metadata/src/Metadata.php). The attributes that must be extracted must be decided on a block type by block type basis:

add_filter("Leoloso\BlockMetadata\Metadata::blockMeta", "extract_additional_block_metadata", 10, 3);
function extract_additional_block_metadata($blockMeta, $blockName, $block)
{
  if ($blockName == "my-plugin/my-block-name") {
    return array(
      "property1" => $block["property1"],
      "property2" => $block["property2"]
    );
  }

  return $blockMeta;
}

Further references

  • Inspiration for the plugin
  • Slides from presentation “COPE with WordPress” (from WordCamp Singapore 2019), explaining how the plugin works

Contributing / Reporting issues

Please head over to the project’s GitHub repo for contributing, reporting issues or making suggestions, and others.

Banner image designed by Freepik

安裝方式

  1. Make sure pretty permalinks are enabled (eg: “/%postname%/”)
  2. Install and activate this plugin

使用者評論

useful plugin

ivan so 2019 年 11 月 2 日
This plugin is useful to give my Gutenberg content into meta data so i could use it to integrate with other system as this plugin already parse the attribute.
閱讀全部 1 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈Block Metadata〉的開發相關工作。

參與者
  • leoloso

將〈Block Metadata〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄。

中繼資料

  • 版本 1.0.7
  • 最後更新 6 年前
  • 啟用安裝數 10+
  • WordPress 版本需求 5.0 或更新版本
  • 已測試相容的 WordPress 版本 5.4.18
  • PHP 版本需求 5.6 或更新版本
  • 語言
    English (US)
  • 標籤
    apiblockcontentgutenbergmetadata
  • 進階檢視

評分

5 星,滿分為 5 星
  • 1 個 5 星使用者評論 5 星 1
  • 0 個 4 星使用者評論 4 星 0
  • 0 個 3 星使用者評論 3 星 0
  • 0 個 2 星使用者評論 2 星 0
  • 0 個 1 星使用者評論 1 星 0

新增使用者評論

查看全部使用者評論

參與者

  • leoloso

技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

檢視技術支援論壇

  • 關於我們
  • 最新消息
  • 主機代管
  • 隱私權
  • 展示網站
  • 佈景主題目錄
  • 外掛目錄
  • 區塊版面配置目錄
  • Learn
  • 技術支援
  • 開發者資源
  • WordPress.tv ↗
  • 共同參與
  • 活動
  • 贊助基金會 ↗
  • Five for the Future
  • WordPress.com ↗
  • Matt ↗
  • bbPress ↗
  • BuddyPress ↗
WordPress.org
WordPress.org

Taiwan 正體中文

  • 查看我們的 X (之前的 Twitter) 帳號
  • 造訪我們的 Bluesky 帳號
  • 造訪我們的 Mastodon 帳號
  • 造訪我們的 Threads 帳號
  • 造訪我們的 Facebook 粉絲專頁
  • Visit our Instagram account
  • Visit our LinkedIn account
  • 造訪我們的 TikTok 帳號
  • Visit our YouTube channel
  • 造訪我們的 Tumblr 帳號
程式碼,如詩
The WordPress® trademark is the intellectual property of the WordPress Foundation.