阅读器
创建 云冈 为任何静态的站点建立信息 现场发电机.
此工具运行在您的 SSG 构建之后, 读取您的配置以查找页面, 收藏, 以及
数据文件以创建用于自动将网站与CloudCannon集成的JSON文件. 这个
JSON 文件写入 _cloudcannon/info.json。 。 。 .
安装
你不需要安装任何东西 在CloudCannon建设时 此工具是自动的 在您的网站建成前安装。 这为您提供了最新的支持,新的功能和修正 他们被释放.
需要时,您可以手动安装工具,测试整合和诊断问题.
npm install --global @cloudcannon/reader
这让你可以访问 cloudcannon-reader 二进制.
使用量
要生成 JSON 文件
_cloudcannon/info.json数字 :$ cloudcannon-reader打印使用细节 :
$ cloudcannon-reader --help Usage $ cloudcannon-reader [options] Options --version Print the current version --config, -c Use a specific configuration file --output, -o Write to a different location than . --quiet, -q Disable logging Environment CLOUDCANNON_CONFIG_PATH Use a specific configuration file Examples $ cloudcannon-reader --config "cloudcannon.dev.config.json" $ cloudcannon-reader --output "public" $ CLOUDCANNON_CONFIG_PATH=src/cloudcannon.config.js cloudcannon-reader
配置
配置文件应在根目录中( 或您运行的同一目录)
cloudcannon-reader) (中文(简体) ). 使用此顺序中的第一个支持文件 :
cloudcannon.config.jsoncloudcannon.config.yamlcloudcannon.config.ymlcloudcannon.config.jscloudcannon.config.cjs
或者,使用与 CLOUDCANNON_CONFIG_PATH
环境变量或 --config 命令行选项 :
$ CLOUDCANNON_CONFIG_PATH=src/cloudcannon.config.js cloudcannon-reader
$ cloudcannon-reader --config "src/cloudcannon.config.js"
您的全球 CloudCannon 配置也设置在这个文件中, 因为它被用作一个基础
生成 _cloudcannon/info.json (用来整合你的网站与CloudCannon).
示例内容 cloudcannon.config.cjs数字 :
module.exports = {
// Global CloudCannon configuration
_inputs: {
title: {
type: 'text',
comment: 'The title of your page.'
}
},
_select_data: {
colors: ['Red', 'Green', 'Blue']
},
// Read from ./src instead of .
source: 'src',
// Write to ./output/_cloudcannon/info.json instead of ./_cloudcannon/info.json
output: 'output',
// Populates the sidebar navigation and provides metadata for the editor
collections_config: {
people: {
// Reads the contents of each file in this directory
path: 'content/people',
// The URL template for items in this collection
url: '/people/{department|slugify}/[slug]/',
// Tells CloudCannon this collection produces output files
output: true
// CloudCannon collection-level configuration
name: 'Personnel',
_enabled_editors: ['data']
},
posts: {
// Reads the contents of each file in this directory
path: '_posts',
// How to parse the files in this collection
parser: 'front-matter',
// The URL function for items in this collection
url: (filePath, parsed, { filters }) => {
const year = new Date(parsed.date).getFullYear();
const slug = filters.slugify(parsed.title || '');
return `/posts/${year}/${slug}/`;
},
// Tells CloudCannon this collection produces output files
output: true
},
pages: {
// Tells CloudCannon to navigate to this path for this collection
path: '',
// Limits files read to these patterns (relative to path)
glob: ['**/*.md', '*.html'],
// Tells CloudCannon to only show successfully parsed files for this collection
// Useful for excluding other collections when using '' as path
filter: 'strict',
// Tells CloudCannon this collection produces output files
output: true
},
data: {
// Reads the contents of each file in this directory
path: 'data',
// How to parse the files in this collection
parser: (filePath, raw, { parsers, filters }) => {
const parsed = parsers['front-matter'].parse(raw);
const slug = filters.slugify(parsed.title || '');
return { ...data, slug };
}
}
},
// Generates the data for select and multiselect inputs matching these names
data_config: {
authors: {
// Reads the contents of this file
path: 'data/authors.csv'
},
offices: {
// Reads the contents of each file in this directory
path: 'data/offices',
parser: 'json'
}
}
};
文档
这个 _cloudcannon/info.json 文件最初包含您的配置内容. cloudcannon-reader 然后生成用于 collections, (中文(简体) ), data, (中文(简体) ), time, (中文(简体) ), version,以及 cloudcannon。 。 。 .
来源
这个 source 设置更改从另一个文件夹读取的地方。 这个 path 收藏项的值相对 source默认为 '.'。 。 。 .
产出
这个 output 设置更改要写入的地方 _cloudcannon 文件夹中包含 info.json默认为 '.'。 。 。 .
数据
这个 data_config 定义数据文件应如何读取和解析到 JSON 代表。 默认为 {}。 。 。 .
{
"data_config": {
"locations": {
"path": "data/locations.csv"
},
"offices": {
"path": "data/offices",
"parser": "front-matter"
}
}
}
每个数据集配置中可用的密钥为:
path
这个
path是指:
- 本数据集文件存储的最顶端文件夹 .
- 包含数据的文件 .
这两种选择都与
source。 。 。 .
parser (可选)
这个
parser字段应说明 解析器 您想要在此数据集中读取文件.
收款
这个 collections_config 对象定义收藏及其文件应如何被读取和解析到 JSON 表示式。 默认为 {}。 。 。 .
{
"collections_config": {
"posts": {
"path": "content/posts",
"parser": "yaml",
"url": "/posts/{category|slugify}/[slug].html"
}
}
}
匹配 CloudCannon 的收藏级配置格式,此格式也在此设置(例如. name, (中文(简体) ), _enabled_editors, (中文(简体) ), add_options) (中文(简体) ).
每个收藏配置中可用的密钥有:
path
这个
path是存储此收藏中文件的最上层文件夹 。 这是相对source。 。 。 .
glob (可选)
这个
glob是包含图案的字符串或字符串阵列,用于过滤解析到此收藏的文件。 球是相对path。模式与 缩写。如果设置为数组,文件只需匹配一个被解析的 glob 模式.glob: ['**/*.md', '**/*.html'] // All .md and .html files用于查找文件而不是
path,但是仍然需要路径作为收集的基础路径.
'./src/*.md'匹配.md文档中src文件夹.'**/*.html'匹配.html任何文件夹或子文件夹中的文件.['**/*.md', './pages/*.html']匹配.md任何文件夹中的文件,或.html文档中pages文件夹.
url (可选)
这个
url用于构建url字段中的项目。 类似于许多 SSG 中的 permarink. 可以是字符串或函数. 默认为''。 。 。 .支持函数的有:
.js或者说.cjs文档。 给定文件路径,解析文件内容和带有过滤器的对象buildUrl函数和collection_config作为参数。 返回值应该是斜线前缀的 URL 字符串 .url: (filePath, content, { filters, buildUrl, collectionConfig }) => { if (content.permalink) { // Returns a lower case permalink front matter field return filters.lowercase(content.permalink); } // Falls back to processing a default url template // Takes filePath, content, and a collections_config entry return buildUrl(filePath, content, { ...collectionsConfig, url: '/[slug]/' }); }字符串被用作构建URL的模板. 有两种类型的占位符,即文件和数据。 支持导致空值的占位符 。 URL中的相继鞭打被收缩为一.
url: '/blog/{date|year}/[slug]/'文件占位符总是可用的,由
cloudcannon-reader数字 :
[path]是文件的全部路径,相对于source。 。 。 .[base_path]是文件的路径,不包括文件名,相对于站点source。 。 。 .[slug]是文件名,不包括扩展名。 如果结果为“ index” , 是空字符串 .[filename]是文件名,包括扩展名.[ext]是最后一个扩展,包括.。 。 。 .[relative_path]是文件的完整路径, 相对于收藏path。 。 。 .[relative_base_path]是文件的路径,不包括文件名,相对于收藏path。 。 。 .[full_slug]是用于[relative_base_path]/[slug]数据占位符是从文件的前题或数据值中被覆盖的,并支持一些过滤器:
{title}这是title从文件内部.{id}这是id从文件内部.{title|lowercase}实值title从文件内部,小写.{category|slugify}实值category从文件内部,被击出.{tag|slugify|uppercase}实值tag从文件内部,被打出,然后是大案.{date|year}实值date从文件内部, 取出4位数的年份.{date|month}实值date从文件内部取出 2 位数月.{date|day}实值date从文件内部取出 2 位数的一天.
parser (可选)
这个
parser字段应说明 解析器 您想要用来读取此收藏中的文件.parser: 'front-matter'
云冈
设定全局 云罐配置 作为您的顶级密钥 cloudcannon-reader 配置和它们会被复制到 _cloudcannon/info.json。 。 。 .
CloudCannon然后在应用程序中读取这些并应用到您的编辑界面中. 其中包括:
collection_groupseditorsource_editor_enabled_editors_inputs_editables_select_data_structures
解析器
解析器定义 cloudcannon-reader 将您的文件处理到 JSON 中 info.json中,您可以设置数据和收藏的解析器 data_config 财务报告和审定财务报表 collections_config。 。 。 .
这些是覆盖的现有解析器和默认文件扩展名 :
csv(单位:千美元).csv(中文(简体) )front-matter(单位:千美元).md, (中文(简体) ),.mkd, (中文(简体) ),.markdown, (中文(简体) ),.html, (中文(简体) ),.htm(中文(简体) )json(单位:千美元).json(中文(简体) )properties(单位:千美元).properties(中文(简体) )toml(单位:千美元).toml(中文(简体) )yaml(单位:千美元).yaml, (中文(简体) ),.yml(中文(简体) )
支持函数的有: .js 或者说 .cjs 文档。 给定文件路径、 原始文件内容和以解析器和过滤器作为参数的对象 。 返回值应为代表该文件的对象.
cloudcannon-reader 如果找不到合适的解析器, 则退出出错 .
发展
安装依赖性 :
$ npm i
运行测试 :
$ npm test
$ npm run test:watch
$ npm run test:coverage
林特代码 :
$ npm run lint
将此软件包链接到本地, 在站点文件夹中测试, 然后在您的站点文件夹中运行 :
$ npm link
$ cd ../my-ssg-site
$ cloudcannon-reader
许可证
公务员制度委员会