AcyOrt provides useful APIs for new plugins, you can get that through global variable acyort in AcyOrt environment.

fs

const { fs } = acyort
const file = '/tmp/file.txt'
fs.outputFileSync(file, 'hello!')

fs is an instance of fs-extra.

version

console.log(acyort.version)
// 2.1.2

Get current AcyOrt version

fetcher

const { fetcher } = acyort
const { axios, getGithub } = fetcher

axios(...config)          // axios
getGithub(...config)      // axios width github headers, github token

// add custom headers
fetcher.setHeaders({ Accept: 'application/vnd.github.v3.full' })

You can also use the built-in axios module or axios with request headers and token

visit acyort-fetcher for more infomations

logger

const { logger } = acyort

logger.success('success')
// ✔ success
logger.info('info')
// i info
logger.error('error')
// ✖ error
logger.warn('warn')
// i warn

logger.error('error', 'tag')
// ✖ error

logger.disable(['tag'])
logger.error('error', 'tag') // log nothing

logger.enable(['tag'])
logger.error('error', 'tag')
// ✖ error

logger.disable()    // disable all log
logger.enable()     // enable all log

Print information on the console

renderer

const { renderer } = acyort

renderer.use('swig')    // default engine is swig, built-in engines are swig and yaml

renderer.render(text, data)
renderer.renderFile(file, data)

renderer
  .register('ejs', {    // register engine
    render: ejs.render
    renderFile: (file, data) => {
      const text = fs.readFileSync(file).toString()
      return ejs.render(text, data)
    }
  })
  .use('ejs')           // current engine
  .render(text, data)

Render engines, visit acyort-render for more information

config

const { config } = acyort
console.log(config)
// { title: 'acyort', post_dir: 'posts' ... }

Current website configuration

marker

const { marker } = acyort
const { headingIdFormater } = marker

// default heading id formater
headingIdFormater('Some text')

// parse option
const option = {
  line_numbers: true,
  simple_mode: false,
  headingIdFormater: fn
}

// parse markdown string
marker.parse('# H1', option)

markdown parser. visit acyort-marked for more infomation

helper

const {
  _pages,
  _posts,
  _categories,
  _tags,
  _url,
  _time,
  __,
  _n,
} = acyort.helper.methods

Helpers can be used in plugins. Visit acyort-helper for more infomation

custom helper

const fn = s => s.split('').join('.')

// add custom helper function
acyort.helper.register('_js', fn)
console.log(helper.methods._js('ab'))   // a.b

context

acyort.helper.register('_active', function () {
  console.log(this) // current `page` context
})

for i18n

acyort.helper.resetLocale() // reset the languages
acyort.helper.resetLocale('zh-cn') // use `zh-cn`

server

const { status } = acyort.server

console.log(status)      
// { e: 'change', path: 'path/to/file.html', running: true }
// current file event, file path and running status

acyort.server.start([port])

LiveReload server provides running status and serve AcyOrt service. visit acyort-server for more infomation

template

acyort.template.register(['archives']) // register custom templates
acyort.template.extension = 'ejs' // set templates extension
acyort.templat.action('head', function () { ... }) // similar wordpress `wp_head` feature, add custom content
acyort.templat.action('footer', function () { ... }) // similar wordpress `wp_footer` feature,add custom content

Template can register custom templates and set the templates extension, add custom content

builder

// use custom template, custom path and output the html file
acyort.builder.output('archives', 'path/to/file', { data }) 

Builder helps compiling custom template, render and output rendered files. Custom templates should be put in theme layout folder.