[WordPress] 外掛分享: Block Metadata

WordPress 外掛 Block Metadata 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Block Metadata」是 2019-08-21 上架。
  • 目前有 10 個安裝啟用數。
  • 上一次更新是 2020-04-15,距離現在已有 1845 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 5.0 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 5.6 以上。
  • 有 1 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

leoloso |

外掛標籤

api | block | content | metadata | gutenberg |

內容簡介

這個外掛程式協助將 WordPress 轉變為數位內容管理員,以便在不同的媒介或平台 (不僅是網站,還包括電子郵件、iOS/Android 應用程式、家庭助理 (例如 Amazon Alexa) 等) 上發佈內容。

它透過萃取網誌文章中所有 Gutenberg 區塊的 metadata 來達成這個目的。由於每個 Gutenberg 區塊都儲存自己的內容和屬性,因此可以將這些屬性提取為 metadata 並導出為 JSON 物件。透過 REST API 端點存取此 JSON 物件,即可饋入任何平台上的任何應用程式。

這個外掛程式提供以下 REST API 端點:

/wp-json/block-metadata/v1/metadata/{POST_ID}:從 id 為 {POST_ID} 的網誌文章中,萃取所有 Gutenberg 區塊的 metadata,轉換為中立於媒體之上的格式 (例如刪除所有非語義 HTML 標籤)
/wp-json/block-metadata/v1/data/{POST_ID}:從 id 為 {POST_ID} 的網誌文章中,萃取所有 Gutenberg 區塊中原始存放於區塊中的內容資料 (例如包含 HTML code)

示範如下:

網誌文章
網誌文章的 Gutenberg 區塊
網誌文章的中立於媒體之上的 metadata

它是如何運作的?

此外掛程式是基於「創建一次,多處發佈訊息」(稱為 COPE) 的策略,由建立一個單一的內容真相來降低在不同媒體中發佈內容所需的工作量。

讓內容能夠在各處順利顯示並不是一件簡單的事,因為每個媒體都有自己的需求。例如,HTML 可以用於將內容列印在網站上,但是這種語言則不適用於 iOS/Android 應用程式;同樣的,我們可以為網站的 HTML 增加 class,但是這些必須轉換成 email 的樣式。

解決方案是將表格和內容分離:表現形式和內容本身的意義必須解耦只有以意義為單一認識點。而表現形式可以在另一層特定於所選取的媒體中加入。例如,對於下列的 HTML code,

是一個 HTML 標籤,對於網站而言,它主要應用於此;而屬性 class=”align-center” 則是表演(將元素置中對於基於屏幕的媒體是有意義的,但是對於 Amazon Alexa 這樣的聲音媒體則不是):

Hello world!

因此,這一段內容不能被當做單一認識點;它必須轉換為另一種格式,將表現形式與內容分離,像下面的 JSON code 片斷:

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

此片段程式碼可作為內容的單一認識點使用,因為只需此位於其中的資訊即可重新建立 HTML 代碼用於網站,並為其他媒體提供適當的格式。

支持的 Gutenberg 區塊

此外掛程式嘗試提取 WordPress 核心中所有附帶的 Gutenberg 區塊的 metadata;可以透過 hooks 增加其他區塊的支援,例如某些區塊只能應用於網站中,或者僅在基於屏幕的媒體上使用,等等。

目前未支援以下 WordPress 核心區塊:

原文外掛簡介

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

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):

Hello world!

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

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Block Metadata」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0.0 | 1.0.1 | 1.0.2 | 1.0.3 | 1.0.4 | 1.0.5 | 1.0.6 | 1.0.7 | trunk |

延伸相關外掛(你可能也想知道)

  • One Click Demo Import 》這個外掛的最佳功能在於主題作者可以在他們的主題中定義導入文件,所以所有使用該主題的用戶只需點擊「導入演示數據」按鈕即可。, , 你是主題作者嗎?, 為你...。
  • Advanced Excerpt 》這個外掛可以改進 WordPress 原有的摘錄文章功能。, , 保留摘錄中的 HTML 標記,並可自選需要保留的標記, 按字元數或字數截斷摘錄, 只計算「真正的」文字(HT...。
  • Rara One Click Demo Import 》您喜歡 Rara Theme 製作的主題展示嗎?還是需要設定主題的指南?, 那麼,您只需要這個外掛!, Rara One Click Demo Import 外掛可以幫助您一鍵匯入演示內容,...。
  • Advanced WP Columns 》Advanced WP Columns 外掛提供了簡單易用的介面,讓您可以在部落格中使用多欄位顯示內容,而無需使用任何簡碼。此外,也支援回應式排版。, , 基本資訊, 外掛...。
  • WP Subtitle 》WP Subtitle 外掛能讓你的頁面和文章擁有副標題。這個短小的文字通常出現在文章(或頁面)標題之下,也可以在你選擇的任何地方插入你的樣板。, 你可以使用以...。
  • WP-ShowHide 》預設情況下,內容是隱藏的,使用者必須點擊「顯示內容」連結來切換內容。與 Engadget 為他們的新聞稿所做的方式相似。範例用法:[showhide type="pressreleas...。
  • TutorMate 》TutorMate 是一款專為 Tutor Starter 主題設計的外掛程式,可將預先設計好的時尚示範頁面匯入由 Tutor LMS 外掛提供的 eLearning 網站。如果您想讓使用 Tutor...。
  • Themebeez Toolkit 》這是我們開發的一個適用於 WordPress 主題 的基本工具包,Themebeez Toolkit 可以幫助您導入虛擬演示內容,還為我們的主題添加了額外的功能和功能。, ✨ 包括...。
  • RSSImport 》這款外掛可使用 PHP、小工具或短代碼在您的部落格中顯示 RSS 資訊。此外掛僅使用 WordPress 標準功能,因此不需要外部庫。對於較舊版本的 WordPress,使用內...。
  • Custom Content Shortcode 》停用通知, , 此外掛已不再維護。, 請改使用下一代範本系統:Loops & Logic。, 概述, , 從單一欄位到整個頁面,Custom Content Shortcode 是一套指令,可...。
  • Blaze Demo Importer 》首頁 | 所有主題 | 部落格 | 支援, , Blaze Demo Importer 可在所有 BlazeThemes 開發的官方主題中使用。此外掛可以用於將任意可用的起始網站設置匯入到您的...。
  • AI Assistant by 10Web – SEO Pack 》EO errors in the paragraph., Content Generator, The AI Assistant by 10Web – SEO Pack can generate long-form content such as articles and blog posts...。
  • 10Web AI Assistant – AI content writing assistant 》10Web AI Assistant for WordPress是專門為WordPress開發的AI內容編輯和AI內容創作工具。透過10Web AI助手,您可以在不離開WordPress環境的情況下比傳統方式...。
  • AF Companion – Build Stylish WordPress Websites in Minutes – No Coding, Just Click and Go! Starter Sites Importer for WordPress 》m/products/newsever-pro/" rel="nofollow ugc">Newsever Pro, Shopical Pro, Elegant Magazine Pro, And More.., , __ Check all of our Plugins __, , News...。
  • Access Demo Importer 》這個外掛會為現行主題匯入與此外掛相容的示範內容。預設下外掛會從我們的伺服器取得設定檔案。, 若您想要使用外掛設定自己的主題,只需指向您的 config.json ...。

文章
Filter
Apply Filters
Mastodon