Giter Site home page Giter Site logo

Comments (10)

jnordberg avatar jnordberg commented on August 10, 2024

You could do it in the render method

  render: (locals, contents, templates, callback) ->
    ### *callback* with a ReadStream/Buffer or null if the contents should not be rendered
        *locals* rendering context variables
        *contents* is the full content tree
        *templates* is a map of all templates as: {filename: templateInstance} ###

from wintersmith.

lhagan avatar lhagan commented on August 10, 2024

I'm pretty sure this will work for regular pages, but not things like the blog example's main page since it pulls in multiple articles from other markdown files.render would only be called once for the main page and not for any of the articles, right?

from wintersmith.

jnordberg avatar jnordberg commented on August 10, 2024

Ah yes, you are correct.

The problem touches upon the same underlying issue as #45 – all view logic is done in templates. And in this case you would need a templating language capable of doing async calls to avoid preloading any async content you (maybe) want to access.

I'm thinking of introducing a view layer (like contents -> view -> template) in wintersmith 2.0. But i'm not sure yet how to go about it without adding another layer of complexity :)

I think pre-rendering it in fromFile is the best option right now.

from wintersmith.

lhagan avatar lhagan commented on August 10, 2024

The issue with fromFile is that in preview mode, sometimes the page gets rendered before Pandoc is done with the content. Not sure if that's a bug.

from wintersmith.

jnordberg avatar jnordberg commented on August 10, 2024

That sounds really strange. Are you sure you are not calling any callbacks prematurely?

from wintersmith.

lhagan avatar lhagan commented on August 10, 2024

I don't think so, but I'm no async expert. The call to pandoc is near the end of the waterfall and I didn't make any other changes to the process:

PandocPage.fromFile = (filename, base, callback) ->
    async.waterfall [
      (callback) ->
        fs.readFile path.join(base, filename), callback
      (buffer, callback) ->
        extractMetadata buffer.toString(), callback
      (result, callback) =>
        {markdown, metadata} = result
        page = new this filename, markdown, metadata
        callback null, page
      (page, callback) =>
        pandocRender page, callback
      (page, callback) =>
        callback null, page
    ], callback

from wintersmith.

jnordberg avatar jnordberg commented on August 10, 2024

The waterfall looks ok, try dropping the async queue in your pandocRender method and see if that helps.

I also did a quick test and wintersmith behaves well even if a plugin takes a long time to complete

module.exports = (ws, callback) ->
  delay = 10000
  page = ws.defaultPlugins.MarkdownPage

  class Delay extends page

    render: (args...) ->
      setTimeout (=> page::render.apply(this, args)), delay

  Delay.fromFile = (args...) ->
    setTimeout (=> page.fromFile.apply(this, args)), delay

  ws.registerContentPlugin 'pages', '**/*.*(markdown|mkd|md)', Delay
  callback()

from wintersmith.

lhagan avatar lhagan commented on August 10, 2024

Unfortunately, without the queue node runs up against a limit for number of open files and crashes on larger sites. I'll try to use your example code above to see if queue is the culprit.

from wintersmith.

lhagan avatar lhagan commented on August 10, 2024

It looks like the issue must be a subtle problem with pandoc or its wrapper. Everything works fine with another converter.

from wintersmith.

jnordberg avatar jnordberg commented on August 10, 2024

Ok, closing this

from wintersmith.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.