Beispiel #1
0
    describe('with one post', function() {
      var site = kerouac();
      
      var page, err;

      before(function(done) {
        chai.kerouac.handler(factory())
          .page(function(page) {
            page.canonicalURL = 'http://www.example.com/blog/feed.rdf';
            
            page.site = site;
            page.site.pages = [
              { url: '/2003/12/13/hello-world/',
                canonicalURL: 'http://www.example.com/blog/2003/12/13/hello-world/',
                meta: { post: true },
                locals: {
                  title: 'Hello, World',
                  publishedAt: new Date('2003-12-13T18:30:02Z'),
                }
              }
            ];
          })
          .end(function(p) {
            page = p;
            done();
          })
          .dispatch();
      });
  
      it('should write feed', function() {
        var expected = [
          '<?xml version="1.0" encoding="UTF-8"?>',
          '<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">',
          '  <channel rdf:about="http://www.example.com/blog/feed.rdf">',
          '    <items>',
          '      <rdf:Seq>',
          '        <rdf:li resource="http://www.example.com/blog/2003/12/13/hello-world/"/>',
          '      </rdf:Seq>',
          '    </items>',
          '  </channel>',
          '  <item rdf:about="http://www.example.com/blog/2003/12/13/hello-world/">',
          '    <title>Hello, World</title>',
          '    <link>http://www.example.com/blog/2003/12/13/hello-world/</link>',
          '    <dc:date>2003-12-13T18:30:02Z</dc:date>',
          '  </item>',
          '</rdf:RDF>',
          ''
        ].join("\n");
      
        expect(page.body).to.equal(expected);
      });
    }); // with one post
Beispiel #2
0
    describe('with one post', function() {
      var site = kerouac();
      var page, err;

      before(function(done) {
        chai.kerouac.handler(factory())
          .page(function(page) {
            page.canonicalURL = 'http://www.example.com/blog/feed.atom';
            
            page.site = site;
            page.site.pages = [
              { url: '/2003/12/13/hello-world/',
                canonicalURL: 'http://www.example.com/blog/2003/12/13/hello-world/',
                meta: { post: true },
                locals: {
                  title: 'Hello, World',
                  publishedAt: new Date('2003-12-13T18:30:02Z'),
                },
                content: 'Hello, world! How are you today?'
              }
            ];
          })
          .end(function(p) {
            page = p;
            done();
          })
          .dispatch();
      });
  
      it('should write feed', function() {
        var expected = [
          '<?xml version="1.0" encoding="UTF-8"?>',
          '<feed xmlns=\"http://www.w3.org/2005/Atom\">',
          '  <link rel="self" type="application/atom+xml" href="http://www.example.com/blog/feed.atom"/>',
          '  <entry>',
          '    <id>http://www.example.com/blog/2003/12/13/hello-world/</id>',
          '    <title>Hello, World</title>',
          '    <link href=\"http://www.example.com/blog/2003/12/13/hello-world/\"/>',
          '    <published>2003-12-13T18:30:02Z</published>',
          '    <content type="html">&lt;p&gt;Hello, world! How are you today?&lt;/p&gt;</content>',
          '  </entry>',
          '</feed>',
          ''
        ].join("\n");
      
        expect(page.body).to.equal(expected);
      });
    }); // with one post
Beispiel #3
0
var kerouac = require('kerouac');
var site = kerouac();

site.set('base url', 'https://emvc.github.io/emvc/');
site.set('output', 'emvc-guide');

site.engine('ejs', require('ejs-locals'));

site.content('content');
site.static('public');

site.plug(require('kerouac-sitemap')());
site.plug(require('kerouac-robotstxt')());


/**
 * .htaccess
 */
;(function() {
  var redirect = {
    '/guide/architecture.html': '/guide/architecture/',
    '/guide/controllers.html': '/guide/controllers/',
    '/guide/datastores.html': '/guide/datastores/',
    '/guide/directory-structure.html': '/guide/directory-structure/',
    '/guide/get-started.html': '/guide/get-started/',
    '/guide/routing.html': '/guide/routing/',
    '/guide/views.html': '/guide/views/'
  }

  site.plug(require('kerouac-htaccess')({ redirect: redirect }));
})();
Beispiel #4
0
    describe('generating a feed with basic document example from RSS 1.0 Specification', function() {
      // http://web.resource.org/rss/1.0/spec#s4.1
      
      var site = kerouac();
      site.set('title', 'XML.com');
      site.set('description', 'XML.com features a rich mix of information and services for the XML community.');
      
      var page, err;

      before(function(done) {
        chai.kerouac.handler(factory())
          .page(function(page) {
            page.canonicalURL = 'http://www.xml.com/xml/news.rss';
            
            page.site = site;
            page.site.pages = [
              { url: '/',
                canonicalURL: 'http://xml.com/pub',
                meta: { home: true },
                locals: {
                }
              },
              { url: '/2000/08/09/xslt/xslt.html',
                canonicalURL: 'http://xml.com/pub/2000/08/09/xslt/xslt.html',
                meta: { post: true },
                locals: {
                  title: 'Processing Inclusions with XSLT',
                }
              }
            ];
          })
          .end(function(p) {
            page = p;
            done();
          })
          .dispatch();
      });
  
      it('should write feed', function() {
        var expected = [
          '<?xml version="1.0" encoding="UTF-8"?>',
          '<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">',
          '  <channel rdf:about="http://www.xml.com/xml/news.rss">',
          '    <title>XML.com</title>',
          '    <description>XML.com features a rich mix of information and services for the XML community.</description>',
          '    <link>http://xml.com/pub</link>',
          '    <items>',
          '      <rdf:Seq>',
          '        <rdf:li resource="http://xml.com/pub/2000/08/09/xslt/xslt.html"/>',
          '      </rdf:Seq>',
          '    </items>',
          '  </channel>',
          '  <item rdf:about="http://xml.com/pub/2000/08/09/xslt/xslt.html">',
          '    <title>Processing Inclusions with XSLT</title>',
          '    <link>http://xml.com/pub/2000/08/09/xslt/xslt.html</link>',
          '  </item>',
          '</rdf:RDF>',
          ''
        ].join("\n");
      
        expect(page.body).to.equal(expected);
      });
    }); // generating a feed with basic document example from RSS 1.0 Specification
Beispiel #5
0
    describe('generating a feed with the extensive, single-entry example in RFC 4287', function() {
      // https://tools.ietf.org/html/rfc4287#section-1.1
      
      var site = kerouac();
      site.set('title', 'dive into mark');
      site.set('description', 'A lot of effort went into making this effortless');
      
      var page, err;

      before(function(done) {
        chai.kerouac.handler(factory())
          .page(function(page) {
            page.canonicalURL = 'http://example.org/feed.atom';
            
            page.site = site;
            page.site.pages = [
              { url: '/',
                canonicalURL: 'http://example.org/',
                meta: { home: true },
                locals: {
                }
              },
              { url: '/2005/04/02/atom',
                canonicalURL: 'http://example.org/2005/04/02/atom',
                meta: { post: true },
                locals: {
                  id: 'tag:example.org,2003:3.2397',
                  title: 'Atom draft-07 snapshot',
                  author: {
                    email: '*****@*****.**',
                    name: 'Mark Pilgrim',
                    url: 'http://example.org/'
                  },
                  contributors: [
                    { name: 'Sam Ruby' },
                    { name: 'Joe Gregorio' }
                  ],
                  publishedAt: new Date('2003-12-13T18:30:02Z'),
                  updatedAt: new Date('2005-07-31T12:29:29.000Z'),
                },
                content: '_Update: The Atom draft is finished._\n'
              }
            ];
          })
          .end(function(p) {
            page = p;
            done();
          })
          .dispatch();
      });
  
      it('should write feed', function() {
        var expected = [
          '<?xml version="1.0" encoding="UTF-8"?>',
          '<feed xmlns=\"http://www.w3.org/2005/Atom\">',
          '  <title>dive into mark</title>',
          '  <subtitle>A lot of effort went into making this effortless</subtitle>',
          '  <link rel="alternate" type="text/html" href="http://example.org/"/>',
          '  <link rel="self" type="application/atom+xml" href="http://example.org/feed.atom"/>',
          '  <entry>',
          '    <id>tag:example.org,2003:3.2397</id>',
          '    <title>Atom draft-07 snapshot</title>',
          '    <link href=\"http://example.org/2005/04/02/atom\"/>',
          '    <published>2003-12-13T18:30:02Z</published>',
          '    <updated>2005-07-31T12:29:29Z</updated>',
          '    <author>',
          '      <name>Mark Pilgrim</name>',
          '      <uri>http://example.org/</uri>',
          '      <email>f8dy@example.com</email>',
          '    </author>',
          '    <contributor>',
          '      <name>Sam Ruby</name>',
          '    </contributor>',
          '    <contributor>',
          '      <name>Joe Gregorio</name>',
          '    </contributor>',
          '    <content type="html">&lt;p&gt;&lt;em&gt;Update: The Atom draft is finished.&lt;/em&gt;&lt;/p&gt;</content>',
          '  </entry>',
          '</feed>',
          ''
        ].join("\n");
      
        expect(page.body).to.equal(expected);
      });
    }); // generating a feed with the extensive, single-entry example in RFC 4287
Beispiel #6
0
exports = module.exports = function(
  feedHandler, postHandler,
  atomFeed, rssFeed, rdfFeed, jsonFeed,
  postsDB) {
  
  var dir, options;
  
  if (typeof dir == 'object') {
    options = dir;
    dir = options.dir;
  }
  dir = dir || 'blog';
  options = options || {};
  
  
  var site = kerouac();
  
  site.on('mount', function onmount(parent) {
    // inherit settings
    this.set('layout engine', parent.get('layout engine'));
    
    this.locals.pretty = parent.locals.pretty;
  });
  
  
  // HTML pages
  site.page('/:year/:month/:day/:slug.html', postHandler);
  site.page('/index.html', feedHandler);
  // FIXME: pretty URL isn't catching this
  //site.page('/index.html', require('./handlers/index')(options.layout));
  
  // https://github.com/jshttp/mime-db
  // https://help.github.com/articles/mime-types-on-github-pages/
  // Feeds
  site.page('/feed.atom', atomFeed);
  site.page('/feed.rss', rssFeed);
  site.page('/feed.rdf', rdfFeed);
  site.page('/feed.json', jsonFeed);
  
  // TODO: implement a news-specific sitemap:
  //       https://support.google.com/webmasters/answer/74288
  // include it as a separate sitemap-news.xml
  
  site.page('/sitemap.xml', require('kerouac-sitemap')());
  
  site.bind(function(done) {
    var self = this;
    
    postsDB.list(function(err, posts) {
      if (err) { return done(err); }
      
      var el, i, len
        , url, year, month, day, slug;
      
      for (i = 0, len = posts.length; i < len; ++i) {
        el = posts[i];
        year = el.publishedAt.getUTCFullYear()
        month = (el.publishedAt.getUTCMonth() + 1)
        day = el.publishedAt.getUTCDate()
        slug = el.slug;
        
        month = (month < 10) ? ('0' + month) : month;
        day = (day < 10) ? ('0' + day) : day;
        
        // TODO: make sure these are in right timezone
        url = '/' + [ year, month, day, slug + '.html' ].join('/');
        self.add(url, el.context);
      }
      
      done();
    });
  });
  
  return site;
}