Skip to content

Commit

Permalink
fix: generation of links won't be broken
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard2perez committed Nov 2, 2017
1 parent a47aee0 commit bbab3e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
12 changes: 5 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/support/KoatonRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export default class KoatonRouter {
// console.log(allroutes);
(secured ? this.secured : this.public)[method](url, async (ctx, next) => {
ctx.state.route = nroute;
ctx.state.fullRoute = url;
await next();
}, Action);
return this;
Expand Down
7 changes: 7 additions & 0 deletions src/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,20 @@ export async function viewsMiddleware (ctx, next) {
};
ctx.render = async function (file, locals) {
try {
console.log('----------------*****');
console.log(ctx.request.originalUrl);
console.log(ctx.request.url);
console.log(ctx.request.path);
console.log('----------------*****');
ctx.body = await template(file, Object.assign({}, locals, {
path: ctx.request.path,
route: ctx.state.route,
subdomain: ctx.state.subdomain
}));
ctx.state.nocache = false;
} catch (err) {
debug(err);
console.log(err);
ctx.status = 500;
}
};
Expand Down
14 changes: 9 additions & 5 deletions src/views/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ function nunjucks () {
}
run (context, url, body, errorBody) {
let route = KoatonRouter.AllRoutes(context.ctx.subdomain).map(exp => {
if (url.match(exp[0])) {
console.log(exp, url);
let variables = (exp[1].match(/\$/g) || []).length;
let matches = (url.match(exp[0]) || []).length - 1;
if (matches === variables && url.replace(...exp).indexOf('.') === -1) {
return url.replace(...exp);
}
}).filter(r => !!r)[0];
}).filter(r => !!r);
route = url === 'home' ? '/' : route[0];
let content;
if (context.ctx.route === url) {
console.log(context.ctx.path, context.ctx.route, url, route);
let active = context.ctx.route === url || context.ctx.path === route;
if (context.ctx.path === route) {
content = `<a class="active">${body()}</a>`;
} else {
content = `<a href="${route}" >${body()}</a>`;
content = `<a href="${route}" class="${active ? 'active' : ''}">${body()}</a>`;
}
return new nunjucks.runtime.SafeString(content);
}
Expand Down

0 comments on commit bbab3e5

Please sign in to comment.