我想知道如何使用jade-lang 和express 将清单文件添加到node.js 站点。我在 github 中发现这是一个问题 239 。我的问题是如何在等待问题解决的情况下将一些数据添加到缓冲区中。
谢谢!
我想知道如何使用jade-lang 和express 将清单文件添加到node.js 站点。我在 github 中发现这是一个问题 239 。我的问题是如何在等待问题解决的情况下将一些数据添加到缓冲区中。
谢谢!
在翡翠中有一个简单的方法:试试这个
html(manifest=_condition_ ? "cache.manifest" : undefined)
此代码检查条件是否为真。如果是,则清单设置为“cache.manifest”。否则它将被设置为undefined
并丢弃。
我很快就会在我的一个项目中需要这个,所以我很想试一试。如果您尝试在单个文件中执行此操作,则实际上存在问题:
!!! 5
if useManifest
html(lang="en", manifest="cache.manifest")
else
html(lang="en")
head
title sample title
body
p some content...
这会呈现一个混乱的 HTML。但是,以下似乎工作得很好(这绝对是一种解决方法):
在routes\index.js
:
exports.index = function(req, res){
res.render('testJade', { layout: false, useManifest: true })
};
在views\testJadeInclude.jade
:
!!!5
if useManifest
html(lang="en", manifest="cache.manifest")
block content
else
html(lang="en")
block content
最后,在views\testJade.jade
:
include testJadeInclude
block append content
head
title sample title
body
p some content
然后根据您的需要(例如,如果客户端是移动浏览器等),您将 useManifest 设置为 true 或 false。
我刚刚测试了另一种可能性,这是另一种方式。不是在内容文件中包含 doctype 和 html 标记(通过块追加),而是在 doctype-html 文件中包含内容文件,所以它看起来像这样:
!!! 5
if useManifest
html(lang="en", manifest="cache.manifest")
include contentFile
else
html(lang="en")
include contentFile