diff --git a/src/legacy/router.js b/src/legacy/router.js index 0cbc3b7..0c595c5 100644 --- a/src/legacy/router.js +++ b/src/legacy/router.js @@ -4,10 +4,12 @@ import Article from '../models/article.js'; const app = express.Router(); app.get('/', async function (req, res) { - let page = Number.isInteger(req.query.page) && req.query.page > 0 ? req.query.page : 1; + let intPage = +req.query.page; + let page = Number.isInteger(intPage) && intPage > 0 ? intPage : 1; let offset = (page - 1) * 4; let articles = await Article.find().sort('-created_at').limit(4).skip(offset); - res.render('index', { articles, offset }); + let hasNextPage = (await Article.countDocuments()) > offset + 4; + res.render('index', { articles, offset, hasNextPage, page }); }); app.use(function (req, res) { diff --git a/src/legacy/views/404.ejs b/src/legacy/views/404.ejs index e025a89..8ad272c 100644 --- a/src/legacy/views/404.ejs +++ b/src/legacy/views/404.ejs @@ -1,10 +1,22 @@ - - - - HOWFEED.biz - - -

Error 404

-

Looks like you're barking up the wrong tree!

- - +<%- include('header') -%> + +

ERROR 404

+ + + +

+ OOPS! Looks like you're barking up the wrong tree! +

+ + + + + Sally the dog + + + + +

The file was not found. Check that the URL was spelled correctly and try again.

+ + +<%- include('footer') -%> diff --git a/src/legacy/views/article.ejs b/src/legacy/views/article.ejs new file mode 100644 index 0000000..1417021 --- /dev/null +++ b/src/legacy/views/article.ejs @@ -0,0 +1,53 @@ +
+
+ {article.title} +
+
+

{article.title}

+
+

Author: {article.author.realname} {article.author.realname}

+

Category: {article.category.name}

+

Published: {new Date(article.created_at).toLocaleString()}

+ {#if article.updated_at} +

Last Updated: {new Date(article.updated_at).toLocaleString()}

+ {/if} +

Views: {article.views}

+
+
+
+ {@html article.html} +
+
+

Comments

+
+ {#each comments as comment} +
+ {#if comment.author_user} + {comment.author_user.realname} + {/if} +

+ {#if comment.author_user} + {comment.author_user.realname} (verified) - {new Date(comment.created_at).toLocaleString()} + {:else} + {comment.author} - {new Date(comment.created_at).toLocaleString()} + {/if} +

+
{comment.content}
+
+ {:else} +

No comments.

+ {/each} +
+

Add a Comment

+
+

Name: + {#if $session.user} + + {:else} + + {/if} +

+

+

+
+
diff --git a/src/legacy/views/header.ejs b/src/legacy/views/header.ejs index 28079dc..b89133a 100644 --- a/src/legacy/views/header.ejs +++ b/src/legacy/views/header.ejs @@ -29,6 +29,9 @@ color: #000; font-weight: bold; } + a img { + border: 0; + } --> @@ -36,7 +39,11 @@ - + -<% for (var article of articles) { %> - - - - +<% for (var i = 0; i < 4; i++) { %> + + <% if (i < articles.length) { %> + + + + <% } else { %> + + <% } %> + +<% } %> +<% if (page > 1 || hasNextPage) { %> + + <% if (page > 1) { %> + + <% } %> + <% if (page > 1 && hasNextPage) { %> + + <% } %> + <% if (hasNextPage) { %> + + <% } %> <% } %> <%- include('footer') -%>
+ + + +
diff --git a/src/legacy/views/index.ejs b/src/legacy/views/index.ejs index 58507c5..213b877 100644 --- a/src/legacy/views/index.ejs +++ b/src/legacy/views/index.ejs @@ -2,13 +2,40 @@

WELCOME

- <%= article.title %> - <%= article.title %>
+ + <%= articles[i].title %> + + + + <%= articles[i].title %> + +
+ + + +