AMP验证错误:“标签'head> style [amp-boilerplate]'中的必需文本丢失或不正确。”

时间:2018-08-08 21:24:30

标签: amp-html

我从here复制并粘贴了授权代码。 这是来自页面源的:

  <style amp-boilerplate>
        body {
            -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;
            -moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;
            -ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;
            animation: -amp-start 8s steps(1,end) 0s 1 normal both
        }

        @-webkit-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-moz-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-ms-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-o-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }
    </style>
    <noscript>
        <style amp-boilerplate>
            body {
                -webkit-animation: none;
                -moz-animation: none;
                -ms-animation: none;
                animation: none
            }
        </style>
    </noscript>

我仍然收到以下验证错误:

  

标记“ head> style [amp-boilerplate]”内的强制文本为   丢失或不正确。 (看到   https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md

任何提示将不胜感激。

1 个答案:

答案 0 :(得分:2)

AMP希望样板保持最小。我只是将您的样板代码粘贴到AMP Playground文档中,却得到了与您完全相同的错误。

只是为了确认这是缩小内容,我从您的帖子中缩小了样板,它就起作用了。

<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

编辑:

我玩得更多。您可以在开始和结束标记之前和之后添加收益。禁止在CSS本身中添加任何返回或空格。

<style amp-boilerplate> 
    body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}
 </style>
 <noscript>
   <style amp-boilerplate>
     body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}
   </style>
 </noscript>

Here is a link解释了AMP样板代码和允许的更改。基本上,您只能在标签后立即添加空白,并且可以在已经存在的空白处添加更多空白。

  

AMP HTML文档的head标签中必须包含以下样板。目前,验证是通过正则表达式完成的,因此,保持突变尽可能少很重要。当前,允许的突变是:(1)在样式标签打开之后立即在其关闭之前插入任意空格; (2)将以下代码段中的任何空格替换为任意空格。