Jade-lang add manifest file

I would like to know how to add the manifest file to node.js
site with jade-lang and express. I found this as an issue 239
in github. My question is how can I add some data into the buffer without while we wait for the resolution of the issue.

Thank’s!

Problem courtesy of: enedebe

Solution

I’m going to need this in one of my projects soon, so I was curious to give it a try. There is effectively a problem if you try to do it in a single file:

!!! 5
if useManifest
    html(lang="en", manifest="cache.manifest")
else
    html(lang="en")

    head
        title sample title
    body
        p some content...

This renders a messed up HTML. However, the following seems to work just fine (it’s definitely a workaround):

In routesindex.js
:

exports.index = function(req, res){
  res.render('testJade', { layout: false, useManifest: true })
};

In viewstestJadeInclude.jade
:

!!!5
if useManifest
    html(lang="en", manifest="cache.manifest")
        block content
else
    html(lang="en")
        block content

And finally, in viewstestJade.jade
:

include testJadeInclude
    block append content
        head
            title sample title
        body
            p some content

Then based on whatever you wish (such as if the client is a mobile browser, or whatever), you set useManifest to true or false.

And I just tested another possibility, which is kind of the other way around. Instead of including the doctype and html tag in your content file (via a block append), you include the content file in the doctype-html file, so it looks like this:

!!! 5
if useManifest
    html(lang="en", manifest="cache.manifest")
        include contentFile
else
    html(lang="en")
        include contentFile

Solution courtesy of: mna

Node.js Recipes责编内容来自:Node.js Recipes (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Jade-lang add manifest file

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录