问题描述
我想知道如何使用 jade-lang 和 express 将清单文件添加到 node.js 站点.我发现这是 github 中的 issue 239.我的问题是如何在不等待问题解决的情况下将一些数据添加到缓冲区中.
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.
谢谢!
推荐答案
我很快就会在我的一个项目中用到它,所以我很想尝试一下.如果您尝试在单个文件中执行此操作,则实际上存在问题:
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...
这会呈现一个混乱的 HTML.但是,以下似乎工作得很好(这绝对是一种解决方法):
This renders a messed up HTML. However, the following seems to work just fine (it's definitely a workaround):
在 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.
Then based on whatever you wish (such as if the client is a mobile browser, or whatever), you set useManifest to true or false.
我刚刚测试了另一种可能性,这是一种相反的方式.不是在内容文件中包含 doctype 和 html 标签(通过块追加),而是在 doctype-html 文件中包含内容文件,所以它看起来像这样:
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
这篇关于Jade-lang 添加清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!