This should be simple, but I cannot make it work.
1) I have a plugin that updates a database and then ideally wants to regenerate just those pages that include data from the database, rather than everything as currently programmed. I first tried to use the action
method of the docpad
instance already available and then tried to follow the documentation and an example with docpadInstance
, but I'm not getting any joy (and the generate collection line that is commented out is not working)
2) The following code regenerates twice(!) and yet the pages are not ultimately changed. I also get exceptions to do with re-setting header information. This post suggests not calling next() as I am initiating the body and next() will invoke other functions that try to set headers, but the server hangs on the auto-refresh and I do NOT see the following in the server logs:
info: Watching setup starting...
info: Watching setup
serverExtend: (opts) ->
{server, serverExpress} = opts
plugin = @
docpad = @docpad
server.get '/remove', (req, res, next) ->
console.log 'Processing removal of '+req.query._id
plugin.removeData { data:req.query, cb : (err) ->
if (err)
console.log ("removal error="+err)
res.send(500, err?.message or err)
else
console.log "Database removal succeeded"
docpad.action 'generate', reset: true, (err,result) ->
# docpad.action 'generate', {collection:docpad.getCollection("database")}, (err,result) ->
if err
console.log "regeneration failed"
res.send(500, err?.message or err)
return next(err)
else
console.log "regeneration success"
res.send(200, 'regeneration succeeded')
return next()
}
# chain??
@
Related question: - how can I use the console of node-inspector to run docpad.action commands so that I can see what they do. I tried copying them into the console in node-inspector but it could not find the variables. (full code)