mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
a1b55509df
refs #9601 Example: ``` collections: /podcast/: permalink: /{slug}/ ``` - the name of the collection is remembered as `routerName` (in the case above: "podcast") - the name of the collection is important for two things 1. context value 2. template name - the context value is available for specific theme helpers e.g. is helper, body_class helper - we auto-lookup the collection name in your theme e.g. podcast.hbs - this logic does not apply to static routes - if you define templates on your collection, they are stronger than the collection name
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
const debug = require('ghost-ignition').debug('services:routing:static-pages-router');
|
|
const common = require('../../lib/common');
|
|
const helpers = require('./helpers');
|
|
const ParentRouter = require('./ParentRouter');
|
|
|
|
class StaticRoutesRouter extends ParentRouter {
|
|
constructor(mainRoute, object) {
|
|
super('StaticRoutesRouter');
|
|
|
|
this.route = {value: mainRoute};
|
|
this.templates = object.templates || [];
|
|
|
|
debug(this.route.value, this.templates);
|
|
|
|
this._registerRoutes();
|
|
}
|
|
|
|
_registerRoutes() {
|
|
this.router().use(this._prepareContext.bind(this));
|
|
|
|
this.mountRoute(this.route.value, this._renderStaticRoute.bind(this));
|
|
|
|
common.events.emit('router.created', this);
|
|
}
|
|
|
|
_prepareContext(req, res, next) {
|
|
// @TODO: index.hbs as fallback for static routes O_O
|
|
res._route = {
|
|
type: 'custom',
|
|
templates: this.templates,
|
|
defaultTemplate: 'index'
|
|
};
|
|
|
|
res.locals.routerOptions = {
|
|
context: []
|
|
};
|
|
|
|
next();
|
|
}
|
|
|
|
_renderStaticRoute(req, res) {
|
|
debug('StaticRoutesRouter');
|
|
helpers.renderer(req, res, {});
|
|
}
|
|
}
|
|
|
|
module.exports = StaticRoutesRouter;
|