IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    修复 AMP 页面错误

    David Yin发表于 2016-06-16 06:44:11
    love 0

    在 Google Search Console 的报告了,可以看到本站有一百多个 AMP 错误。主要就是 Invalid usage of AMP tags。这么多的错误,还是需要修正的。于是就做了如下的检查和修正。

    在 Google Chrome 的开发者工具里的控制台内,查看这些 AMP 页面,只要网址加上 #development=1 就可以了。

    看到的错误主要有四部分。

    1) 在标签 a 里面,有 onclick 属性,这个是 AMP 无效属性。

    2) 在标签 p 或者 span 内,有 style 属性,这同样是无效的。

    3) 在标签 img 里面,有 style 属性,同样要去掉。

    4) 标签 iframe, 要替换成 amp-iframe 标签。

    修复的过程主要参考了这篇文章,没全部看,因为是日文的,看不懂,大概的参考了中间这一段。

    在我的 AMP 模板中的写法是这样的。

        regex_replace set the conversion list for the modifier
        /img /g
        amp-img layout="responsive" 
        /onclick=(.*)false"/g
        target="_blank"
        /span style(.*)">/g
        span>
        /p style(.*)">
        p><
        /<\/iframe>/g
        
         
        EntryBody, conversion to specify the regex_replace modifier to EntryMore
        <$mt:EntryBody regex_replace="$regex1a","$regex1b"  regex_replace="$regex2a","$regex2b" regex_replace="$regex3a","$regex3b" regex_replace="$regex4a","$regex4b" regex_replace="$regex5a","$regex5b"  replace='style="text-align: center; display: block; margin: 0 auto 20px;"',' '$>
        <$mt:EntryMore regex_replace="$regex1a","$regex1b"  regex_replace="$regex2a","$regex2b" regex_replace="$regex3a","$regex3b" regex_replace="$regex4a","$regex4b" regex_replace="$regex5a","$regex5b"  replace='style="text-align: center; display: block; margin: 0 auto 20px;"',' '$>
    

    在上面的正则表达式的写法,可能未必是最好的,可以用 RegExr 工具来调试。

    过一段时间再去看看 Google Webmaster 后台是否已经去除这些错误了。

    把网站放在Dreamhost,通过LinkWorth获取广告收益,每个链接高达$40。

    Site Meter

    延伸阅读

    • 如何验证 AMP 页面
    • 应用htaccess给网站加上防盗链机制
    • AMP (Accelerated Mobile Pages) 计划简介
    • 添加了新的AMP归档页面
    • 404错误中看到的收获
    • 使用自定按钮来做社会化分享
    • 网站经常性的出现网络连接异常
    • 两个 Plugins 在升级 MovableType 6.1 之后
    • 添加Site Meter统计
    • 采用量子恒道统计来统计Feed的访问


沪ICP备19023445号-2号
友情链接