Skip to content

cnbloglabs/core

Repository files navigation

acnb-core

API for creating cnblog theme.

Install

npm i @acnb/core

API

createTheme

Returns a theme instance that provides a theme context.

import { createTheme } from '@acnb/core'

const theme = createTheme()

defineOptions

Returns a generic configuration object.

import { defineOptions } from '@acnb/core'

const useBackgroundOptions = defineOptions('bodyBackground', {
  enable: false,
  value: '',
  opacity: 0.85,
  repeat: false,
})

Cnblog theme users can add the following configuration:

const opts = {
  bodyBackground: {
    enable: false,
    value: '',
    opacity: 0.85,
    repeat: false,
  },
}

Using configuration aliases:

import { defineOptions } from '@acnb/core'

const useBackgroundOptions = defineOptions(['bodyBackground', 'background'], {
  enable: false,
  value: '',
  opacity: 0.85,
  repeat: false,
})

Plugin System

// plugin.js
import { defineOptions } from '@acnb/core'

export const backgroundPlugin = (theme, devOptions, pluginOptions) => {
  const useBackgroundOptions = defineOptions('bodyBackground', {
    enable: false,
    value: '',
    opacity: 0.85,
    repeat: false,
  })

  const { enable, value, opacity, repeat } = useBackgroundOptions(devOptions)

  if (!enable) return

  const { opacitySelector } = Object.assign(
    {},
    {
      opacitySelector: '#main,#navigator',
    },
    pluginOptions
  )

  setBackground(value, repeat)
  setOpacity(opacity, opacitySelector)
}
// theme/index.js
import { createTheme } from '@acnb/core'
import { backgroundPlugin } from './plugin'

const theme = createTheme()

theme.use(
  backgroundPlugin,
  {
    // Set the default configuration of the theme
    enable: true,
    value: '#ffb3cc',
    opacity: 0.85,
  },
  {
    // Set the default configuration of the plugin
    opacitySelector: '#main',
  }
)

About

🏕 API for creating cnblog theme.

Resources

Stars

Watchers

Forks