pug - 您如何使用 Jade 构建 RSS 提要?

标签 pug

我正在用 Jade 构建我自己的前端框架,我想知道是否有一种方法可以构建一个 RSS 提要文件,该文件将在每次编译时自动更新。

有没有办法自动创建类似 JSON 文件的对象,其中包含可以在 Jade 循环中获取的页面信息?

最佳答案

是的,是的,所有人!!!你可以这样做。我将举一个例子。

在 nodejs 中

app.all('/myCool.:name(rss|xml)', function(req, res){
    res.type('xml'); // <-- Type of the file
    // myFeeds is a Array!!
    res.render(req.params.name, { myFeeds : myFeeds, url : req.originalUrl });
});

在 RSS rss
doctype xml
rss( version="2.0", xmlns:content="http://purl.org/rss/1.0/modules/content/", xmlns:atom='http://www.w3.org/2005/Atom' )
    channel
        title My Cool feed
        link= url
        //- I use momentjs
        lastBuildDate= moment().toUTCString()

        docs http://blogs.law.harvard.edu/tech/rs
        generator My Nodejs Generator Feeds for RSS
        each feed, i in myFeeds
            item
                title= feed.title
                guid( isPermaLink="true" )= feed.id

                updated= feed.date.toUTCString()

在原子中 xml
doctype xml
feed( xmlns='http://www.w3.org/2005/Atom', xml:lang='es')

    link( href= url, rel='self' )
    //- I use momentjs
    updated= moment().format("YYYY-MM-DDTHH:mm:ssZ")
    title My Cool feed
    author
        name AlejoNext
        uri https://alejonext.co
    generator My Nodejs Generator Feeds for Atom

    each feed, i in myFeeds
        entry
            title!= feed.title
            id= feed.id
            updated= moment(feed.date).format("YYYY-MM-DDTHH:mm:ssZ")

这是生成内容的绝佳方式,您可以渲染任何类型的 xml在 Jade 。

关于pug - 您如何使用 Jade 构建 RSS 提要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28148435/

相关文章:

pug - pug 中预期出现意外 token `tag`

javascript - Node js + jade 打印在 jade 文件中传递变量

node.js - 选择 'onchange' 不适用于 Jade Node JS

json - Pug - 与条件 .json 对象混合

javascript - 如何从jade文件中的javascript文件访问变量的值?

reactjs - React 类似(Jade 或 Slim)的语法?

javascript - 如何在 Jade 中分配变量?

javascript - Jade : text box change the value = "..."

javascript - Node JS + Express JS : What is routes/index. js 及其用途?

node.js - 引用错误 : jade is not defined