add articles
This commit is contained in:
parent
8d29d4d395
commit
eb4e25e1ae
|
@ -37,6 +37,8 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async down(queryInterface, Sequelize) {
|
async down(queryInterface, Sequelize) {
|
||||||
await queryInterface.dropTable('Guestbooks');
|
if (await queryInterface.tableExists('guestbook')) {
|
||||||
|
await queryInterface.dropTable('guestbook');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -0,0 +1,47 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('sequelize-cli').Migration} */
|
||||||
|
module.exports = {
|
||||||
|
/** @param {import('sequelize').QueryInterface} queryInterface */
|
||||||
|
async up (queryInterface, DataTypes) {
|
||||||
|
queryInterface.createTable('articles', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.BIGINT(11),
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
shortText: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
submitted: {
|
||||||
|
type: DataTypes.BIGINT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
edited: {
|
||||||
|
type: DataTypes.BIGINT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
submitter: {
|
||||||
|
type: DataTypes.BIGINT,
|
||||||
|
allowNull: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** @param {import('sequelize').QueryInterface} queryInterface */
|
||||||
|
async down (queryInterface, DataTypes) {
|
||||||
|
if (await queryInterface.tableExists('articles')) {
|
||||||
|
await queryInterface.dropTable('articles');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,17 @@
|
||||||
|
const handler = require('express-async-handler');
|
||||||
|
const Helpers = require('../helpers');
|
||||||
|
const Sequelize = require('../models');
|
||||||
|
|
||||||
|
async function articles(req, res) {
|
||||||
|
|
||||||
|
const articles = await Sequelize.Article.findAll();
|
||||||
|
|
||||||
|
res.send(await Helpers.ViewLoader.load('articles/articles.pug', {
|
||||||
|
current_route: res.originalUrl,
|
||||||
|
articles
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (router) => {
|
||||||
|
router.get('/articles', handler(articles));
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
extends ../layout/main.pug
|
||||||
|
block root
|
||||||
|
- var title = 'Articles'
|
||||||
|
|
||||||
|
block content
|
||||||
|
h2 Articles
|
||||||
|
p.
|
||||||
|
This is a bunch of articles written by me (like a tech blog of some sort)
|
||||||
|
if articles
|
||||||
|
table(style='max-width:600px;min-width:600px;border-collapse:collapse;border:0')
|
||||||
|
each article of articles
|
||||||
|
tr
|
||||||
|
td(style='border:1px solid #c2c4c2;box-shadow:0 2px 2px #c2c4c280;border-radius:8px;padding:4px 24px')
|
||||||
|
h4(style='margin:8px 0;padding:0')
|
||||||
|
span(style='font-family:monospace') [<a style='font-family:monospace' href='/article/#{article.id}'>##{article.id}</a>]
|
||||||
|
= article.title
|
||||||
|
hr
|
||||||
|
p= article.shortText
|
||||||
|
p
|
||||||
|
a(href='/article/' + article.id) Open full article
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
div(style='min-height:12px;max-height:12px')
|
||||||
|
else
|
||||||
|
p Error while loading articles: data is not present
|
|
@ -5,8 +5,10 @@ block root
|
||||||
"Main page": '/',
|
"Main page": '/',
|
||||||
"Projects": "/project",
|
"Projects": "/project",
|
||||||
"About me": "/about",
|
"About me": "/about",
|
||||||
"hr": "hr",
|
"hr_1": "hr",
|
||||||
"Guestbook": "/guestbook"
|
"Guestbook": "/guestbook",
|
||||||
|
"hr_2": "hr",
|
||||||
|
"Articles": "/articles"
|
||||||
}
|
}
|
||||||
|
|
||||||
doctype html
|
doctype html
|
||||||
|
|
Loading…
Reference in New Issue