Apostrophecms使用
地址
- github: https://github.com/apostrophecms/apostrophe
 - 官网:https://apostrophecms.com/
 - 官方文档: https://a3.docs.apos.dev/
 
系统要求
版本
| Software | Minimum Version | 
| Node.js | 12.x+ | 
| MongoDB | 3.6+ | 
| ImageMagick(optional) | Any | 
查看版本命令
node -v && npm -v
# This will display your Node.js version and npm version (installed with Node),
# if installed.
mongod --version
# This will display your MongoDB version, if installed.
which convert && which identify
# This will display the location of the ImageMagick utilities, if installed.
使用
全局安装Apostrophe CLI tool
npm install -g @apostrophecms/cli
# Or `yarn global add @apostrophecms/cli`, if you prefer. We'll stick to npm commands.
cli创建项目
apos create apos-app
设置管理员密码
node app @apostrophecms/user:add my-user admin
# Replace `my-user` with the name you want for your first user.
启动
- 启动命令
npm run dev - 地址
http://localhost:3000/login 
二次开发
目录结构
| app.js | 应用程序的核心。这是您告诉 Apostrophe 项目中有哪些模块并设置一些顶级参数的地方。 | 
| /modules | 所有项目级模块和已安装模块的配置。 | 
| /public | 公共、静态文件(不通过 CMS 管理)。撇号会在里面生成特定的目录,但你也可以根据需要使用它。 | 
| /views | 不属于任何一个模块的模板文件。Apostrophe 在此处查找站点包装模板,包括layout.html. | 
核心模块配置全部在 : 的子目录中modules完成modules/@apostrophecms。
新建模块
js内容
// modules/task/index.js
module.exports = {
  extend: '@apostrophecms/piece-type',
  options: {
    label: 'Task',
  },
  fields: {
    add: {
      main: {
        label: 'Detail',
        type: 'area',
        options: {
          widgets: {
            '@apostrophecms/rich-text': {},
            '@apostrophecms/image': {},
            '@apostrophecms/video': {}
          }
        }
      },
      contribution: {
        label: 'Contribution Value',
        type: 'float'
      },
      taskImage: {
        label: 'Task Image',
        type: 'area',
        options: {
          widgets: {
            '@apostrophecms/image': {}
          }
        }
      },
    },
    group: {
      config: { 
        label: 'Config', 
        fields: [ 'title', 'contribution', 'taskImage', 'main' ] 
      },
      utility: { 
        fields: [ 'slug', 'visibility' ] 
      }
    }
  }
};
说明
- extend 表示继承
 - option 显示标签
 - fields 设置内容,其中type为area 中可以挂载工件widgets
 - group 用于分组展示,basics和utility是两个内置的分组,可以通过重新来改变
 
app.js中引用
// app.js
require('apostrophe')({
  shortName: 'my-website',
  modules: {
    'task': {}
  }
});
引用后界面上就可以看到这个模块渲染出来
REST API
配置
当需要将接口提供给其他平台使用时,需要配置apikey
// modules/@apostrophecms/express/index.js 
  module.exports = {
  options: {
    session: {
      // If this still says `undefined`, set a real secret!
      secret: 'myapikey'
    }
  }
};
  // app.js
    '@apostrophecms/express': {
      options: {
        apiKeys: {
          'myapikey': {
            role: 'admin'
          }
        }
      }
    },
请求
通过如下地址即可访问到上方task模块对应的数据
GET http://localhost:3000/api/v1/task?apikey=myapikey