modified server code and added project template. partially tested and appears to work so far

This commit is contained in:
len0rd 2018-07-31 16:09:51 -04:00
parent 74588d1c60
commit d77ca583ea
4 changed files with 38 additions and 7 deletions

View file

@ -11,14 +11,26 @@ app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/assets')); app.use(express.static(__dirname + '/assets'));
app.get(/\/.*/, function(req, res) { app.get(/\/.*/, function(req, res) {
console.log('Request for page: ' + req.path);
let pathname = 'pages' + req.path; let pathname = 'pages' + req.path;
let page = pathname.substr(pathname.lastIndexOf('/') + 1);
if ((pathname)[pathname.length - 1] === '/') {
pathname += 'index'; if (pathname !== null && pathname !== undefined) {
if ((pathname)[pathname.length - 1] === '/') {
pathname += 'index';
page = 'index';
}
if (pathname.includes('projects') && page !== 'index') {
// projects has a custom template that is used for all projects
// so we need to change the pathname that the renderer is using
// to that template:
pathname = pathname.substr(0, pathname.lastIndexOf(page));
pathname += 'project_template'
page = 'partials/md/' + page;
}
} }
console.log('request for path: ' + pathname + ', and page: ' + page);
res.render(pathname); res.render(pathname, {"page": this.page});
}); });
app.listen(PORT); app.listen(PORT);

View file

@ -21,5 +21,4 @@
<% include ../partials/footer %> <% include ../partials/footer %>
<% include ../partials/post_html_include %> <% include ../partials/post_html_include %>
</body> </body>
</html> </html>

View file

@ -17,7 +17,7 @@
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h1 class="display-1">welcome to lenordsNet</h1> <h1 class="display-1">welcome to lenordsNet</h1>
<h3 class="text-white">fake it til you make it</h3> <h3 class="text-white">i dont know what im doing</h3>
</div> </div>
</div> </div>
</div> </div>

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<% include ../../partials/include %>
</head>
<body>
<header>
<% include ../../partials/nav %>
</header>
<div class="container">
<% include(page) %>
</div>
<% include ../../partials/footer %>
<% include ../../partials/post_html_include %>
</body>
</html>