AMP- Toolbox 校验规则
查询公布了AMP验证器规则并摘录了所需信息 所有 AMP 格式的标记和属性.
使用量
通过 :
$ npm install @ampproject/toolbox-validator-rules
包括模块
ES 模块(浏览器)
import validatorRules from '@ampproject/toolbox-validator-rules';
常见Js( 节点)
const validatorRules = require('@ampproject/toolbox-validator-rules');
使用模块
// Loads the validator rules remotely with default options
const rules = await validatorRules.fetch();
// The raw unprocessed rules
console.log(rules.raw);
// All tags, combined with their respective attribute lists
console.log(rules.tags);
// All extensions
console.log(rules.extensions);
// Get all tag names used in AMP for Email
// The supported formats are AMP, AMP4EMAIL, AMP4ADS and ACTIONS
const tags = rules.getTagsForFormat('AMP4EMAIL');
// Display their names
console.log(tags.map(tag => tag.tagName));
// Get information about an extension
const ext = rules.getExtension('AMP4EMAIL', 'amp-carousel');
// Display supported versions
console.log(ext.versions);
规则的格式
这些规则严格遵循了原型定义: 校验器. proto。 。 。 .
具体而言:
- 这个
raw属性未处理 验证规则,使用的格式与https://cdn.ampproject.org/v0/validator.json - 结果是:
getTagsForFormat编辑tags属性是列表 标记Spec - 结果是:
getExtension实值 扩展Spec 与htmlFormat从字段TagSpec - 这个
extensions属性列表 扩展Spec 与htmlFormat从字段TagSpec - 这个
errors属性组合 错误格式 财务报告和审定财务报表 特定错误
选项
fetch 可选择接受选项对象,允许您自定义其
行为.
支持以下选项:
noCache: 真实到总是获取最新规则(默认情况下,后续调用到fetch重复使用同样的结果).rules:反对使用本地指定的规则,而不是从 AMP CDN 中获取这些规则.url: 覆盖获取验证器规则的 URL .source: 一个'local'(从本地文件中装入规则名为"validator.json"),'remote'(比照CDN的规则)或'auto'默认值(先查找本地文件,然后尝试从 CDN 获取).
示例
validatorRules.fetch({
noCache: true,
source: 'remote'
});