[wordpress插件] Block Metadata阻止元数据

wordpress 插件 文章 2020-03-06 15:40 583 0 全屏看文

AI助手支持GPT4.0

评分
100
描述

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.

此插件有助于将WordPress转换为我们的数字内容管理器,以将其发布在不同的媒介或平台上:不仅是网站,还包括电子邮件,iOS / Android应用程序,家庭助理(例如Amazon Alexa)等。

It does this by extracting the metadata from all Gutenberg blocks inside of a blog post.

它是通过从博客文章中所有Gutenberg块中提取元数据来实现的。

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.

由于每个Gutenberg块都存储自己的内容和属性,因此可以将这些内容和属性提取为元数据,并通过JSON对象(可通过REST API端点进行访问)导出,以提供任何平台上的任何应用程序。

The plugin makes the following REST API endpoints available:

该插件可提供以下REST API端点:

    • /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

    • / wp-json / block-metadata / v1 / metadata / {POST_ID}:从ID为{POST_ID}的博客文章中的所有Gutenberg块中提取所有元数据,并转换为中等不可知(例如:删除所有非语义的)

      HTML tags)

    • HTML标签)

    • /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

    • / wp-json / block-metadata / v1 / data / {POST_ID}:提取ID为{POST_ID}的博客文章中所有Gutenberg块中的所有数据,如Gutenberg最初存储在该块中(例如:包含HTML)

      code)

    • 代码)

    Demonstration:

    演示:

      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

      此插件基于名为“一次创建,到处发布”(也称为“ COPE”)的策略,该策略通过为所有内容建立单一真相来源来减少将我们的内容发布到不同媒体中所需的工作量

      .

      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;

      例如,HTML对于打印Web内容有效,而对于iOS / Android应用则无效。

      similarly, we can add classes to our HTML for the web, but these must be converted to styles for email.

      同样,我们可以将类添加到Web的HTML中,但是必须将这些类转换为电子邮件的样式。

      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

      例如,给定以下一段HTML代码,

      是一个HTML标记,该标记主要适用于Web,并且属性class =“ align-center”是表示形式(将元素“放在

      the center” makes sense for a screen-based medium, but not for an audio-based one such as Amazon Alexa):

      中心”对于基于屏幕的媒体有意义,但对于诸如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:

      因此,这部分内容不能用作单一的事实来源,必须将其转换为一种将表示形式与含义分离开的格式,例如以下JSON代码:

      {  

        {  

      content: "Hello world!",  

      内容:“ 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.

      这段代码可以用作内容真实性的唯一来源,因为我们可以通过它再次重新创建用于Web的HTML代码,并为其他媒介获取合适的格式。

      Supported Gutenberg blocks

      受支持的古腾堡块

      This plugin attempts to extract the metadata for all Gutenberg blocks shipped in WordPress core;

      此插件尝试提取WordPress核心中随附的所有Gutenberg块的元数据;

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

      并非所有的Gutenberg块都受支持(例如,因为它们可能仅适用于Web,或者仅在应用于基于屏幕的媒体时才有意义)。

      The following WordPress core blocks are currently not supported:

      当前不支持以下WordPress核心块:

        • "core/columns"
        • “核心/列”

        • "core/column"
        • “核心/列”

        • "core/cover"
        • “核心/封面”

        • "core/html"
        • “ core / html”

        • "core/table"
        • “核心/表格”

        • "core/button"
        • “核心/按钮”

        • "core/media-text"
        • “核心/媒体文本”

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

        支持以下Gutenberg块,并且此插件提取其元数据:

          • "core/paragraph"
          • “核心/段落”

          • "core/image"
          • “核心/图片”

          • "core-embed/youtube" (all other "core-embed" blocks can also be extracted, but must be implemented through a hook)
          • “核心嵌入/ youtube” (所有其他“ core-embed” 块也可以提取,但必须通过钩子实现)

          • "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<

          为此,只需为过滤器“ Leoloso \ BlockMetadata \ Metadata :: blockMeta” (位于函数 get_block_metadata($ block_data)来自类 Metadata <

          /code> in file block-metadata/src/Metadata.php).

          / code>在文件 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);

            add_filter(“ Leoloso \ BlockMetadata \ Metadata :: blockMeta”,“ extract_additional_block_metadata”,10,3);

          function extract_additional_block_metadata($blockMeta, $blockName, $block)

          函数extract_additional_block_metadata($ blockMeta,$ blockName,$ block)

          {  

          {  

          if ($blockName == "my-plugin/my-block-name") {    

          如果($ blockName ==“ my-plugin / my-block-name”){    

          return array(      

          返回数组(      

          "property1" => $block["property1"],      

          “ property1” => $ block [“ property1”],      

          "property2" => $block["property2"]    

          “ property2” => $ block [“ property2”]    

          );  

          );  

          }  

          }  

          return $blockMeta;

          返回$ blockMeta;

          }

          }

          Further references

          更多参考

安装步骤

    1. Make sure pretty permalinks are enabled (eg: “/%postname%/”)
    2. 确保已启用漂亮的永久链接(例如:“ /%postname%/”)

    3. Install and activate this plugin
    4. 安装并激活此插件

下载地址
https://downloads.wordpress.org/plugin/block-metadata.1.0.6.zip
-EOF-

AI助手支持GPT4.0