【问题标题】:how to speed up docpad rendering?如何加快 docpad 渲染?
【发布时间】:2016-01-12 12:28:56
【问题描述】:

我只更改了几页,但 docpad 似乎再次呈现所有内容。我没有使用任何花哨的插件或动态组件——只是基本的 ghost 模板。是否有一些技巧可以减少页面渲染?

可能与 docpad.coffee 中的时间戳格式有关?

moment = require('moment')
docpadConfig = {
  templateData:
    vars:
      appserver: 'http://xxx'
    site:
      title: 'Pocket Tutor'
      tagline: 'English language chat tutor'
      description: 'Learn english by chatting'
      logo: '/uploads/images/corpid/comiceng/96/logo-96.png'
      url: 'http://app:9005'
      cover: '/img/cover.jpg'
      navigation: [
        {
          name: 'Home',
          href: '/',
          section: 'home'
        },
        {
          name: 'About',
          href: '/about.html',
          section: 'about'
        },
        {
          name: 'Lessons',
          href: '/tags/lessons.html',
          section: 'tag-lessons'
        },
        {
          name: 'Grammar',
          href: '/tags/grammar.html',
          section: 'tag-grammar'
        }
        {
          name: 'Teachers',
          href: '/tags/tech.html',
          section: 'tag-tech'
        },

      ]
    author:
      name: 'Rikai Labs'
      img: ''
      url: 'http://rikai.co'
      website: 'http://RIKAI.co'
      location: 'space',
      bio: 'we build chat apps'
    getPreparedTitle: -> if @document.title then "#{@document.title} | #{@site.title}" else @site.title
    getDescription: -> if @document.description then "#{@document.description} | #{@site.description}" else @site.description
    bodyClass: -> if @document.isPost then "post-template" else "home-template"
    masthead: (d) ->
      d = d || @document
      if d.cover then d.cover else @site.cover
    isCurrent: (l) ->
      if @document.section is l.section  then ' nav-current'
      else if @document.url is l.href then ' nav-current'
      else ''
    excerpt: (p,w) ->
      w = w || 26
      if p.excerpt then p.excerpt else p.content.replace(/<%.+%>/gi, '').split(' ').slice(0, w).join(' ')
    encode: (s) -> encodeURIComponent(s)
    slug: (s) -> return s.toLowerCase().replace(' ', '-')
    currentYear: -> new Date().getFullYear()
    time: (ts, format) ->
      format = format || 'MMMM DO, YYYY'
      ts = new Date(ts) || new Date()
      moment(ts).format(format)
  collections:
    posts: ->
      @getCollection("html").findAllLive({active:true, isPost: true, isPagedAuto: {$ne: true}}, {postDate: -1}).on "add", (model) ->
        model.setMetaDefaults({layout:"post"})
  plugins:
    tags:
      extension: '.html'
      injectDocumentHelper: (doc) ->
        doc.setMeta { layout: 'tag' }
    rss:
      default:
        collection: 'posts'
        url: '/rss.xml'
    marked:
      gfm: true

  environments:  # default
    development:  # default
        # Always refresh from server
      maxAge: false  # default
      # Only do these if we are running standalone via the `docpad` executable
      checkVersion: process.argv.length >= 2 and /docpad$/.test(process.argv[1])  # default
      welcome: process.argv.length >= 2 and /docpad$/.test(process.argv[1])  # default
      prompts: process.argv.length >= 2 and /docpad$/.test(process.argv[1])  # default

      # Listen to port 9005 on the development environment
      port: 9005  # example
    production:
      port: 9005
      maxAge: false  # default

}

module.exports = docpadConfig

更新:删除日期和时间方法

time: -> 'time'
currentYear: -> 'year'

稍微加快了速度,但仍然对一个文件进行一次编辑会提供信息:

Generated 40/150 files in 7.364 seconds

update2:添加

standalone: true

到一些页面进行测试,但仍然需要 info:在 7.252 秒内生成 40/150 个文件

所以即使是一个独立的页面也会触发一堆其他的东西。

【问题讨论】:

    标签: docpad


    【解决方案1】:

    可以手动处理 Docpad 重新生成过程。为此,您需要关闭 Docpad 的手表。也就是说,使用 docpad server 命令运行 Docpad。这里会发生的是,无论您编辑多少次文档,它都不会加载到 docpad 集合中。然后,您必须手动加载任何更新。也就是说,有一些代码来加载文档。

    model = @docpad.getCollection('posts').findOne({someValue: someValue})
    model.load()
    

    触发再生。

     @docpad.action 'generate', reset: false, (err) ->
         if err
             @docpad.log "warn", "GENERATE ERROR"
    

    这就是我在posteditor plugin 中所做的事情

    我怀疑这并不是您真正想要的,但它确实让您可以完全控制再生过程。

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 2010-10-15
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2011-09-19
      • 1970-01-01
      • 2010-09-13
      相关资源
      最近更新 更多