Finished building blog overview page.

This commit is contained in:
2018-11-25 18:38:42 +11:00
parent 8ab9f09287
commit 83369773cd
15 changed files with 312 additions and 40 deletions

View File

@ -94,7 +94,6 @@ class App {
}
this.log('App ready');
console.log(await this.articles.getArticlesByPage(2, 20));
}
// Common Functions //

View File

@ -46,6 +46,12 @@ module.exports = class Articles extends DatabaseInterface {
);
}
async getArticlesPageCount(perPage) {
if(!perPage) perPage = 10;
let count = await this.getArticlesCount(perPage);
return Math.ceil(count/perPage);
}
async getArticlesByPage(page, perPage) {
if(!page) page = 1;
if(!perPage) perPage = 10;

View File

@ -1,5 +1,5 @@
INSERT INTO "BlogArticles" (
"handle", "image", "shortDescription", "description", "date"
"handle", "title", "image", "shortDescription", "description", "date"
) VALUES (
${handle}, ${image}, ${shortDescription}, ${description}, ${date}
${handle}, ${title}, ${image}, ${shortDescription}, ${description}, ${date}
) RETURNING *;

View File

@ -44,7 +44,10 @@ module.exports = class GetBlogArticles extends APIHandler {
return {
ok: true,
data: await request.getApp().getArticles().getArticlesByPage(page, perPage)
data: {
pages: await request.getApp().getArticles().getArticlesPageCount(perPage),
articles: await request.getApp().getArticles().getArticlesByPage(page, perPage)
}
};
}
}

View File

@ -29,7 +29,7 @@ const
SharpLoader = require('responsive-loader/sharp'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
CompressionPlugin = require("compression-webpack-plugin"),
UglifyJsPlugin = require('uglifyjs-webpack-plugin'),
TerserPlugin = require('terser-webpack-plugin'),
MiniCssExtractPlugin = require("mini-css-extract-plugin"),
OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin")
;
@ -44,7 +44,7 @@ module.exports = (isDev) => {
let config = {
devtool: 'source-map',
entry: [ `${base}/public/index.jsx` ],
output: { path: `${base}/dist`, filename: "app.js" },
output: { path: `${base}/dist`, filename: "app.js", publicPath: '/' },
mode: isDev ? 'development' : 'production',
resolve: {
modules: [`${base}/node_modules`, `${base}/public`],
@ -153,7 +153,7 @@ module.exports = (isDev) => {
]
};
} else {
let UglifyPluginConfig = new UglifyJsPlugin({
let TerserPluginConfig = new TerserPlugin({
test: /\.js($|\?)/i
});
@ -172,7 +172,7 @@ module.exports = (isDev) => {
optimization: {
minimize: true,
minimizer: [
UglifyPluginConfig,
TerserPluginConfig,
MiniCssExtractConfig,
new OptimizeCSSAssetsPlugin({}),
]