2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const rewire = require('rewire');
|
|
|
|
const templates = rewire('../../../../../core/frontend/services/routing/helpers/templates');
|
2021-04-23 13:22:45 +01:00
|
|
|
const themeEngine = require('../../../../../core/frontend/services/theme-engine');
|
2015-11-24 15:12:50 +00:00
|
|
|
|
|
|
|
describe('templates', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
let getActiveThemeStub;
|
|
|
|
let hasTemplateStub;
|
|
|
|
let _private = templates.__get__('_private');
|
2017-03-13 23:15:50 +00:00
|
|
|
|
2015-11-24 15:12:50 +00:00
|
|
|
afterEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.restore();
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
2018-06-24 00:32:08 +02:00
|
|
|
describe('[private fn] getEntriesTemplateHierarchy', function () {
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should return just index for empty options', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({}).should.eql(['index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should return just index if collection name is index', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({name: 'index'}).should.eql(['index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
2018-06-21 20:18:29 +02:00
|
|
|
it('should return custom templates even if the collection is index', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({name: 'index', templates: ['something']}).should.eql(['something', 'index']);
|
2018-06-21 20:18:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return collection name', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({name: 'podcast'}).should.eql(['podcast', 'index']);
|
2018-06-21 20:18:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return custom templates', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({name: 'podcast', templates: ['mozart']}).should.eql(['mozart', 'podcast', 'index']);
|
2018-06-21 20:18:29 +02:00
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should return just index if collection name is index even if slug is set', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({name: 'index', slugTemplate: true}, {slugParam: 'test'}).should.eql(['index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should return collection, index if collection has name', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({name: 'tag'}).should.eql(['tag', 'index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should return collection-slug, collection, index if collection has name & slug + slugTemplate set', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({
|
2017-03-21 08:24:11 +00:00
|
|
|
name: 'tag',
|
2018-06-11 22:06:47 +02:00
|
|
|
slugTemplate: true
|
|
|
|
}, {slugParam: 'test'}).should.eql(['tag-test', 'tag', 'index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should return front, collection-slug, collection, index if name, slugParam+slugTemplate & frontPageTemplate+pageParam=1 is set', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({
|
2017-03-21 08:24:11 +00:00
|
|
|
name: 'tag',
|
|
|
|
slugTemplate: true,
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
frontPageTemplate: 'front-tag'
|
2018-06-11 22:06:47 +02:00
|
|
|
}, {page: 1, path: '/', slugParam: 'test'}).should.eql(['front-tag', 'tag-test', 'tag', 'index']);
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return home, index for index collection if front is set and pageParam = 1', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
name: 'index',
|
|
|
|
frontPageTemplate: 'home'
|
|
|
|
}, {path: '/'}).should.eql(['home', 'index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('should not use frontPageTemplate if not / collection', function () {
|
2018-06-24 00:32:08 +02:00
|
|
|
_private.getEntriesTemplateHierarchy({
|
2017-03-21 08:24:11 +00:00
|
|
|
name: 'index',
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
frontPageTemplate: 'home'
|
|
|
|
}, {path: '/magic/'}).should.eql(['index']);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
describe('[private fn] pickTemplate', function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
beforeEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
hasTemplateStub = sinon.stub().returns(false);
|
2017-03-13 23:15:50 +00:00
|
|
|
|
2021-04-23 13:22:45 +01:00
|
|
|
getActiveThemeStub = sinon.stub(themeEngine, 'getActive').returns({
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplate: hasTemplateStub
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-24 19:41:00 +02:00
|
|
|
it('returns fallback if there is no active_theme', function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
getActiveThemeStub.returns(undefined);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.pickTemplate(['tag-test', 'tag', 'index'], 'fallback').should.eql('fallback');
|
|
|
|
_private.pickTemplate(['page-my-post', 'page', 'post'], 'fallback').should.eql('fallback');
|
2017-03-13 23:15:50 +00:00
|
|
|
});
|
|
|
|
|
2017-04-24 19:41:00 +02:00
|
|
|
it('returns fallback if active_theme has no templates', function () {
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.pickTemplate(['tag-test', 'tag', 'index'], 'fallback').should.eql('fallback');
|
|
|
|
_private.pickTemplate(['page-about', 'page', 'post'], 'fallback').should.eql('fallback');
|
2017-03-13 23:15:50 +00:00
|
|
|
});
|
|
|
|
|
2015-11-24 15:12:50 +00:00
|
|
|
describe('with many templates', function () {
|
|
|
|
beforeEach(function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
// Set available Templates
|
|
|
|
hasTemplateStub.withArgs('default').returns(true);
|
|
|
|
hasTemplateStub.withArgs('index').returns(true);
|
|
|
|
hasTemplateStub.withArgs('page').returns(true);
|
|
|
|
hasTemplateStub.withArgs('page-about').returns(true);
|
|
|
|
hasTemplateStub.withArgs('post').returns(true);
|
|
|
|
hasTemplateStub.withArgs('amp').returns(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns first matching template', function () {
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.pickTemplate(['page-about', 'page', 'post'], 'fallback').should.eql('page-about');
|
|
|
|
_private.pickTemplate(['page-magic', 'page', 'post'], 'fallback').should.eql('page');
|
|
|
|
_private.pickTemplate(['page', 'post'], 'fallback').should.eql('page');
|
2017-03-13 23:15:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns correctly if template list is a string', function () {
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.pickTemplate('amp', 'fallback').should.eql('amp');
|
|
|
|
_private.pickTemplate('subscribe', 'fallback').should.eql('fallback');
|
|
|
|
_private.pickTemplate('post', 'fallback').should.eql('post');
|
2017-03-13 23:15:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
describe('[private fn] getTemplateForEntry', function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
beforeEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
hasTemplateStub = sinon.stub().returns(false);
|
2017-03-02 16:53:48 +00:00
|
|
|
|
2021-04-23 13:22:45 +01:00
|
|
|
getActiveThemeStub = sinon.stub(themeEngine, 'getActive').returns({
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplate: hasTemplateStub
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
it('will fall back to post even if no index.hbs', function () {
|
|
|
|
hasTemplateStub.returns(false);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({page: 1});
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('post');
|
|
|
|
});
|
|
|
|
|
2017-03-13 23:15:50 +00:00
|
|
|
describe('with many templates', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
// Set available Templates
|
|
|
|
hasTemplateStub.withArgs('default').returns(true);
|
|
|
|
hasTemplateStub.withArgs('index').returns(true);
|
|
|
|
hasTemplateStub.withArgs('page').returns(true);
|
|
|
|
hasTemplateStub.withArgs('page-about').returns(true);
|
|
|
|
hasTemplateStub.withArgs('post').returns(true);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
2017-10-10 14:36:35 +02:00
|
|
|
it('post without custom slug template', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2015-11-24 15:12:50 +00:00
|
|
|
page: 0,
|
|
|
|
slug: 'test-post'
|
|
|
|
});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('post');
|
|
|
|
});
|
|
|
|
|
2017-10-10 14:36:35 +02:00
|
|
|
it('post with custom slug template', function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplateStub.withArgs('post-welcome-to-ghost').returns(true);
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2015-11-24 15:12:50 +00:00
|
|
|
page: 0,
|
|
|
|
slug: 'welcome-to-ghost'
|
|
|
|
});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2017-10-10 14:36:35 +02:00
|
|
|
view.should.eql('post-welcome-to-ghost');
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
2017-10-10 14:36:35 +02:00
|
|
|
it('page without custom slug template', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2015-11-24 15:12:50 +00:00
|
|
|
page: 1,
|
|
|
|
slug: 'contact'
|
|
|
|
});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('page');
|
|
|
|
});
|
|
|
|
|
2017-10-10 14:36:35 +02:00
|
|
|
it('page with custom slug template', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2015-11-24 15:12:50 +00:00
|
|
|
page: 1,
|
|
|
|
slug: 'about'
|
|
|
|
});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('page-about');
|
|
|
|
});
|
2017-10-10 14:36:35 +02:00
|
|
|
|
|
|
|
it('post with custom template', function () {
|
|
|
|
hasTemplateStub.withArgs('custom-about').returns(true);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2017-10-10 14:36:35 +02:00
|
|
|
page: 0,
|
|
|
|
custom_template: 'custom-about'
|
|
|
|
});
|
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('custom-about');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('page with custom template', function () {
|
|
|
|
hasTemplateStub.withArgs('custom-about').returns(true);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2017-10-10 14:36:35 +02:00
|
|
|
page: 1,
|
|
|
|
custom_template: 'custom-about'
|
|
|
|
});
|
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('custom-about');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post with custom template configured, but the template is missing', function () {
|
|
|
|
hasTemplateStub.withArgs('custom-about').returns(false);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2017-10-10 14:36:35 +02:00
|
|
|
page: 0,
|
|
|
|
custom_template: 'custom-about'
|
|
|
|
});
|
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('post');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('page with custom template configured, but the template is missing', function () {
|
|
|
|
hasTemplateStub.withArgs('custom-about').returns(false);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2017-10-10 14:36:35 +02:00
|
|
|
page: 1,
|
|
|
|
custom_template: 'custom-about'
|
|
|
|
});
|
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('page');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post with custom template configured, but slug template exists', function () {
|
|
|
|
hasTemplateStub.withArgs('custom-about').returns(true);
|
|
|
|
hasTemplateStub.withArgs('post-about').returns(true);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2017-10-10 14:36:35 +02:00
|
|
|
page: 0,
|
|
|
|
slug: 'about',
|
|
|
|
custom_template: 'custom-about'
|
|
|
|
});
|
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('post-about');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post with custom template configured, but slug template exists, but can\'t be found', function () {
|
|
|
|
hasTemplateStub.withArgs('custom-about').returns(false);
|
|
|
|
hasTemplateStub.withArgs('post-about').returns(false);
|
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntry({
|
2017-10-10 14:36:35 +02:00
|
|
|
page: 0,
|
|
|
|
slug: 'about',
|
|
|
|
custom_template: 'custom-about'
|
|
|
|
});
|
|
|
|
should.exist(view);
|
|
|
|
view.should.eql('post');
|
|
|
|
});
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-24 00:32:08 +02:00
|
|
|
describe('[private fn] getTemplateForEntries', function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
beforeEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
hasTemplateStub = sinon.stub().returns(false);
|
2017-03-13 23:15:50 +00:00
|
|
|
|
2021-04-23 13:22:45 +01:00
|
|
|
getActiveThemeStub = sinon.stub(themeEngine, 'getActive').returns({
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplate: hasTemplateStub
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-11-24 15:12:50 +00:00
|
|
|
describe('without tag templates', function () {
|
|
|
|
beforeEach(function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplateStub.withArgs('default').returns(true);
|
|
|
|
hasTemplateStub.withArgs('index').returns(true);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('will return correct view for a tag', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntries({name: 'tag', slugTemplate: true}, {slugParam: 'development'});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('index');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with tag templates', function () {
|
|
|
|
beforeEach(function () {
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplateStub.withArgs('default').returns(true);
|
|
|
|
hasTemplateStub.withArgs('index').returns(true);
|
|
|
|
hasTemplateStub.withArgs('tag').returns(true);
|
|
|
|
hasTemplateStub.withArgs('tag-design').returns(true);
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('will return correct view for a tag', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntries({name: 'tag', slugTemplate: true}, {slugParam: 'design'});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('tag-design');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will return correct view for a tag', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntries({name: 'tag', slugTemplate: true}, {slugParam: 'development'});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('tag');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will fall back to index even if no index.hbs', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const view = _private.getTemplateForEntries({name: 'tag', slugTemplate: true}, {slugParam: 'development'});
|
2016-02-07 21:27:01 +00:00
|
|
|
should.exist(view);
|
2015-11-24 15:12:50 +00:00
|
|
|
view.should.eql('index');
|
|
|
|
});
|
|
|
|
});
|
2017-03-14 09:06:42 +00:00
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
describe('[private fn] getTemplateForError', function () {
|
2017-03-14 09:06:42 +00:00
|
|
|
beforeEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
hasTemplateStub = sinon.stub().returns(false);
|
2017-03-14 09:06:42 +00:00
|
|
|
|
2021-04-23 13:22:45 +01:00
|
|
|
getActiveThemeStub = sinon.stub(themeEngine, 'getActive').returns({
|
2017-03-14 09:06:42 +00:00
|
|
|
hasTemplate: hasTemplateStub
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-24 19:41:00 +02:00
|
|
|
it('will fall back to default if there is no active_theme', function () {
|
2017-03-14 09:06:42 +00:00
|
|
|
getActiveThemeStub.returns(undefined);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.match(/core\/server\/views\/error.hbs$/);
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('will fall back to default for all statusCodes with no custom error templates', function () {
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.match(/core\/server\/views\/error.hbs$/);
|
|
|
|
_private.getTemplateForError(503).should.match(/core\/server\/views\/error.hbs$/);
|
|
|
|
_private.getTemplateForError(422).should.match(/core\/server\/views\/error.hbs$/);
|
|
|
|
_private.getTemplateForError(404).should.match(/core\/server\/views\/error.hbs$/);
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('will use custom error.hbs for all statusCodes if there are no other templates', function () {
|
|
|
|
hasTemplateStub.withArgs('error').returns(true);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.eql('error');
|
|
|
|
_private.getTemplateForError(503).should.eql('error');
|
|
|
|
_private.getTemplateForError(422).should.eql('error');
|
|
|
|
_private.getTemplateForError(404).should.eql('error');
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('will use more specific error-4xx.hbs for all 4xx statusCodes if available', function () {
|
|
|
|
hasTemplateStub.withArgs('error').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-4xx').returns(true);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.eql('error');
|
|
|
|
_private.getTemplateForError(503).should.eql('error');
|
|
|
|
_private.getTemplateForError(422).should.eql('error-4xx');
|
|
|
|
_private.getTemplateForError(404).should.eql('error-4xx');
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('will use explicit error-404.hbs for 404 statusCode if available', function () {
|
|
|
|
hasTemplateStub.withArgs('error').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-4xx').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-404').returns(true);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.eql('error');
|
|
|
|
_private.getTemplateForError(503).should.eql('error');
|
|
|
|
_private.getTemplateForError(422).should.eql('error-4xx');
|
|
|
|
_private.getTemplateForError(404).should.eql('error-404');
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('cascade works the same for 500 errors', function () {
|
|
|
|
hasTemplateStub.withArgs('error').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-5xx').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-503').returns(true);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.eql('error-5xx');
|
|
|
|
_private.getTemplateForError(503).should.eql('error-503');
|
|
|
|
_private.getTemplateForError(422).should.eql('error');
|
|
|
|
_private.getTemplateForError(404).should.eql('error');
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('cascade works with many specific templates', function () {
|
|
|
|
hasTemplateStub.withArgs('error').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-5xx').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-503').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-4xx').returns(true);
|
|
|
|
hasTemplateStub.withArgs('error-404').returns(true);
|
|
|
|
|
2017-11-10 12:44:29 +00:00
|
|
|
_private.getTemplateForError(500).should.eql('error-5xx');
|
|
|
|
_private.getTemplateForError(503).should.eql('error-503');
|
|
|
|
_private.getTemplateForError(422).should.eql('error-4xx');
|
|
|
|
_private.getTemplateForError(404).should.eql('error-404');
|
|
|
|
_private.getTemplateForError(401).should.eql('error-4xx');
|
|
|
|
_private.getTemplateForError(501).should.eql('error-5xx');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
describe('fn: setTemplate', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const stubs = {};
|
|
|
|
let req;
|
|
|
|
let res;
|
|
|
|
let data;
|
2017-11-10 12:44:29 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
req = {};
|
|
|
|
res = {
|
2018-06-26 01:12:50 +02:00
|
|
|
routerOptions: {}
|
2017-11-10 12:44:29 +00:00
|
|
|
};
|
|
|
|
data = {};
|
|
|
|
|
2019-01-21 17:53:44 +01:00
|
|
|
stubs.pickTemplate = sinon.stub(_private, 'pickTemplate').returns('testFromPickTemplate');
|
|
|
|
stubs.getTemplateForEntry = sinon.stub(_private, 'getTemplateForEntry').returns('testFromEntry');
|
|
|
|
stubs.getTemplateForEntries = sinon.stub(_private, 'getTemplateForEntries').returns('testFromEntries');
|
|
|
|
stubs.getTemplateForError = sinon.stub(_private, 'getTemplateForError').returns('testFromError');
|
2017-11-10 12:44:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does nothing if template is already set', function () {
|
|
|
|
// Pre-set template
|
|
|
|
res._template = 'thing';
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
// It hasn't changed
|
|
|
|
res._template.should.eql('thing');
|
|
|
|
|
|
|
|
// And nothing got called
|
|
|
|
stubs.pickTemplate.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.false();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('defaults to index', function () {
|
|
|
|
// No route or template config here!!!
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
// It should be index
|
|
|
|
res._template.should.eql('index');
|
|
|
|
|
|
|
|
// And nothing got called
|
|
|
|
stubs.pickTemplate.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.false();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls pickTemplate for custom routes', function () {
|
2018-06-26 01:12:50 +02:00
|
|
|
res.routerOptions = {
|
2017-11-10 12:44:29 +00:00
|
|
|
type: 'custom',
|
2018-06-21 15:46:42 +02:00
|
|
|
templates: 'test',
|
2017-11-10 12:44:29 +00:00
|
|
|
defaultTemplate: 'path/to/local/test.hbs'
|
|
|
|
};
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
// should be testFromPickTemplate
|
|
|
|
res._template.should.eql('testFromPickTemplate');
|
|
|
|
|
|
|
|
// Only pickTemplate got called
|
|
|
|
stubs.pickTemplate.called.should.be.true();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.false();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
|
|
|
|
stubs.pickTemplate.calledWith('test', 'path/to/local/test.hbs').should.be.true();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls pickTemplate for custom routes', function () {
|
2018-06-26 01:12:50 +02:00
|
|
|
res.routerOptions = {
|
2017-11-10 12:44:29 +00:00
|
|
|
type: 'custom',
|
2018-06-21 15:46:42 +02:00
|
|
|
templates: 'test',
|
2017-11-10 12:44:29 +00:00
|
|
|
defaultTemplate: 'path/to/local/test.hbs'
|
|
|
|
};
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
// should be testFromPickTemplate
|
|
|
|
res._template.should.eql('testFromPickTemplate');
|
|
|
|
|
|
|
|
// Only pickTemplate got called
|
|
|
|
stubs.pickTemplate.called.should.be.true();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.false();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
|
|
|
|
stubs.pickTemplate.calledWith('test', 'path/to/local/test.hbs').should.be.true();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getTemplateForEntry for entry routes', function () {
|
2018-06-26 01:12:50 +02:00
|
|
|
res.routerOptions = {
|
2017-11-10 12:44:29 +00:00
|
|
|
type: 'entry'
|
|
|
|
};
|
|
|
|
|
|
|
|
// Requires a post to be set
|
|
|
|
data = {post: {slug: 'test'}};
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
// should be getTemplateForEntry
|
|
|
|
res._template.should.eql('testFromEntry');
|
|
|
|
|
|
|
|
// Only pickTemplate got called
|
|
|
|
stubs.pickTemplate.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.true();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.false();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
|
|
|
|
stubs.getTemplateForEntry.calledWith({slug: 'test'}).should.be.true();
|
|
|
|
});
|
|
|
|
|
2018-06-24 00:32:08 +02:00
|
|
|
it('calls getTemplateForEntries for type collection', function () {
|
✨Dynamic Routing Beta (#9596)
refs #9601
### Dynamic Routing
This is the beta version of dynamic routing.
- we had a initial implementation of "channels" available in the codebase
- we have removed and moved this implementation
- there is now a centralised place for dynamic routing - server/services/routing
- each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts
- keep as much as possible logic of routing helpers, middlewares and controllers
- ensure test coverage
- connect all the things together
- yaml file + validation
- routing + routers
- url service
- sitemaps
- url access
- deeper implementation of yaml validations
- e.g. hard require slashes
- ensure routing hierarchy/order
- e.g. you enable the subscriber app
- you have a custom static page, which lives under the same slug /subscribe
- static pages are stronger than apps
- e.g. the first collection owns the post it has filtered
- a post cannot live in two collections
- ensure apps are still working and hook into the routers layer (or better said: and register in the routing service)
- put as much as possible comments to the code base for better understanding
- ensure a clean debug log
- ensure we can unmount routes
- e.g. you have a collection permalink of /:slug/ represented by {globals.permalink}
- and you change the permalink in the admin to dated permalink
- the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/
- unmount without server restart, yey
- ensure we are backwards compatible
- e.g. render home.hbs for collection index if collection route is /
- ensure you can access your configured permalink from the settings table with {globals.permalink}
### Render 503 if url service did not finish
- return 503 if the url service has not finished generating the resource urls
### Rewrite sitemaps
- we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime
- we generate all urls on bootstrap
- the sitemaps service will consume created resource and router urls
- these urls will be shown on the xml pages
- we listen on url events
- we listen on router events
- we no longer have to fetch the resources, which is nice
- the urlservice pre-fetches resources and emits their urls
- the urlservice is the only component who knows which urls are valid
- i made some ES6 adaptions
- we keep the caching logic -> only regenerate xml if there is a change
- updated tests
- checked test coverage (100%)
### Re-work usage of Url utility
- replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId`
- only for resources e.g. post, author, tag
- this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime
- adapt url utility
- adapt tests
2018-06-05 19:02:20 +02:00
|
|
|
req.url = '/';
|
|
|
|
req.params = {};
|
|
|
|
|
2018-06-26 01:12:50 +02:00
|
|
|
res.routerOptions = {
|
|
|
|
type: 'collection',
|
|
|
|
testCollection: 'test'
|
2017-11-10 12:44:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
2018-06-24 00:32:08 +02:00
|
|
|
res._template.should.eql('testFromEntries');
|
2017-11-10 12:44:29 +00:00
|
|
|
|
|
|
|
// Only pickTemplate got called
|
|
|
|
stubs.pickTemplate.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.true();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
|
2018-06-26 01:12:50 +02:00
|
|
|
stubs.getTemplateForEntries.calledWith({testCollection: 'test', type: 'collection'}).should.be.true();
|
2018-06-24 00:32:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getTemplateForEntries for type channel', function () {
|
|
|
|
req.url = '/';
|
|
|
|
req.params = {};
|
|
|
|
|
2018-06-26 01:12:50 +02:00
|
|
|
res.routerOptions = {
|
|
|
|
type: 'channel',
|
|
|
|
testChannel: 'test'
|
2018-06-24 00:32:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
res._template.should.eql('testFromEntries');
|
|
|
|
|
|
|
|
// Only pickTemplate got called
|
|
|
|
stubs.pickTemplate.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntries.called.should.be.true();
|
|
|
|
stubs.getTemplateForError.called.should.be.false();
|
|
|
|
|
2018-06-26 01:12:50 +02:00
|
|
|
stubs.getTemplateForEntries.calledWith({testChannel: 'test', type: 'channel'}).should.be.true();
|
2017-11-10 12:44:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getTemplateForError if there is an error', function () {
|
|
|
|
// Make the config look like a custom route
|
2018-06-26 01:12:50 +02:00
|
|
|
res.routerOptions = {
|
2017-11-10 12:44:29 +00:00
|
|
|
type: 'custom',
|
|
|
|
templateName: 'test',
|
|
|
|
defaultTemplate: 'path/to/local/test.hbs'
|
|
|
|
};
|
|
|
|
|
|
|
|
// Setup an error
|
|
|
|
res.statusCode = 404;
|
|
|
|
req.err = new Error();
|
|
|
|
|
|
|
|
// Call setTemplate
|
|
|
|
templates.setTemplate(req, res, data);
|
|
|
|
|
|
|
|
// should be testFromError
|
|
|
|
res._template.should.eql('testFromError');
|
|
|
|
|
|
|
|
// Only pickTemplate got called
|
|
|
|
stubs.pickTemplate.called.should.be.false();
|
|
|
|
stubs.getTemplateForEntry.called.should.be.false();
|
2018-06-24 00:32:08 +02:00
|
|
|
stubs.getTemplateForEntries.called.should.be.false();
|
2017-11-10 12:44:29 +00:00
|
|
|
stubs.getTemplateForError.called.should.be.true();
|
|
|
|
|
|
|
|
stubs.getTemplateForError.calledWith(404).should.be.true();
|
2017-03-14 09:06:42 +00:00
|
|
|
});
|
|
|
|
});
|
2015-11-24 15:12:50 +00:00
|
|
|
});
|