Skip to content

Commit

Permalink
Migrate to Hexo 3.0 API #4
Browse files Browse the repository at this point in the history
  • Loading branch information
akfish committed Mar 21, 2015
1 parent b82e655 commit 5c79344
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
25 changes: 16 additions & 9 deletions src/Command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ log = new Log()

# Hexo
file = require 'hexo-fs'
themeDir = hexo.theme_dir # hexo is undefined here. I just hard-coded to pass here. You should modify here properly.
layoutDir = path.resolve themeDir, "layout"
assetDir = path.resolve __dirname, "../asset"
mathJaxLayoutName = "math-jax.ejs"
mathJaxLayoutAsset = path.resolve assetDir, mathJaxLayoutName
mathJaxLayoutFile = path.resolve layoutDir, "_partial", mathJaxLayoutName
# Ugly fix, initialized in Command#constructor when Hexo object is avaliable
themeDir = null#hexo.theme_dir
layoutDir = null#path.resolve themeDir, "layout"
assetDir = null#path.resolve __dirname, "../asset"
mathJaxLayoutName = null#"math-jax.ejs"
mathJaxLayoutAsset = null#path.resolve assetDir, mathJaxLayoutName
mathJaxLayoutFile = null#path.resolve layoutDir, "_partial", mathJaxLayoutName

pad = (val, length, padChar = '.') ->
val += ''
Expand Down Expand Up @@ -53,7 +54,7 @@ load = (files, callback) ->

list = (next) ->
log.info "Layout folder: #{layoutDir}"
file.list layoutDir, null, (err, files) ->
file.listDir layoutDir, null, (err, files) ->
if err?
next? err
files = files.filter (f) -> f.match ".*?\.ejs$"
Expand Down Expand Up @@ -141,15 +142,21 @@ remove = (payload, next) ->


module.exports = class Command
constructor: (@callback) ->
constructor: (@hexo, @callback) ->
themeDir = @hexo.theme_dir
layoutDir = path.resolve themeDir, "layout"
assetDir = path.resolve __dirname, "../asset"
mathJaxLayoutName = "math-jax.ejs"
mathJaxLayoutAsset = path.resolve assetDir, mathJaxLayoutName
mathJaxLayoutFile = path.resolve layoutDir, "_partial", mathJaxLayoutName

execute: (opt) ->
handler = @[opt]
if handler?
handler()
else
log.error "Unknown command: #{opt}"
hexo.call 'help', {_: ['math']}, @callback
@hexo.call 'help', {_: ['math']}, @callback



Expand Down
8 changes: 4 additions & 4 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extend = hexo.extend
util = require 'hexo-util'
file = require 'hexo-fs'
htmlTag = hexo.util.html_tag
htmlTag = util.html_tag

# Modules
async = require 'async'
Expand All @@ -24,7 +24,7 @@ mathOptions =

# The console
hexo.extend.console.register "math", packageInfo.description, mathOptions, (args, callback) ->
cmd = new Command callback
cmd = new Command hexo, callback
cmd.execute args._[0]

# Single Tag
Expand All @@ -34,7 +34,7 @@ hexo.extend.tag.register "math", (args, content) ->
return result

# Block Tag
hexo.extend.tag.register "math-block", ((args, content) ->
hexo.extend.tag.register "math_block", ((args, content) ->
result = "<span>$$#{content}$$</span>"
return result
), true
), ends: true

0 comments on commit 5c79344

Please sign in to comment.