代码之家  ›  专栏  ›  技术社区  ›  Hong

AMP validation error:“标记'head>style[AMP boilerplate]'中的强制文本丢失或不正确。”

  •  0
  • Hong  · 技术社区  · 6 年前

    我复制并粘贴了 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 回复  |  直到 6 年前
        1
  •  2
  •   Craig Scott    6 年前

    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文档的头标记中必须包含以下样板文件。验证目前是用正则表达式完成的,所以保持尽可能少的突变是很重要的。目前,允许的变异是:(1)在样式标记打开后立即插入任意空格,并在其关闭前立即插入;(2)用任意空格替换下面代码片段中的任何空格。