浏览代码

Apply a patch from Dusan Malusev

Signed-off-by: Dušan Mitrović <dusan@dusanmitrovic.xyz>
master
Dušan Mitrović 10 个月前
父节点
当前提交
4c54db427b
找不到此签名对应的密钥 GPG 密钥 ID: 8E81D1BFCE8427E5
共有 6 个文件被更改,包括 9110 次插入4002 次删除
  1. +1
    -1
      db/connection.js
  2. +9094
    -3996
      package-lock.json
  3. +2
    -2
      routes/blog.js
  4. +11
    -1
      services/post-service.js
  5. +1
    -1
      views/blogPage.hbs
  6. +1
    -1
      views/partials/post.hbs

+ 1
- 1
db/connection.js 查看文件

@@ -13,7 +13,7 @@ const knex = Knex({
port: process.env.DB_PORT,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME
database: process.env.DB_NAME,
},
pool: {
min: 2,


+ 9094
- 3996
package-lock.json
文件差异内容过多而无法显示
查看文件


+ 2
- 2
routes/blog.js 查看文件

@@ -32,7 +32,7 @@ router.get('/new', authorizationMiddleware, (req, res) => {
router.get('/post/:id', async (req, res) => {
try {
const id = req.params.id;
const post = await PostService.getById(id);
const post = await PostService.getBySlug(id);

if (undefined === post) {
return res.render('404', {
@@ -52,7 +52,7 @@ router.get('/post/:id', async (req, res) => {
title: post.title,
css,
js: ['/static/js/prism.js'],
id: post.id,
slug: post.slug,
content: markdown2Html(post.content),
created_at: moment(post.created_at).format('MMMM Do YYYY'),
openGraph: {


+ 11
- 1
services/post-service.js 查看文件

@@ -20,6 +20,14 @@ class PostService {
.findById(id);
}

static aysnc getBySlug(slug) {
return Post.query()
.where({
slug,
})
.select('title', 'slug', 'description', 'content', 'created_at');
}

/**
* Return all posts
*
@@ -38,7 +46,8 @@ class PostService {
'user.email'
)
.leftJoinRelated('user')
.orderBy('posts.created_at', 'DESC');
.orderBy('posts.created_at', 'DESC')
.limit(100);
}

/**
@@ -61,6 +70,7 @@ class PostService {
.select(
'posts.id',
'posts.title',
'posts.slug',
'posts.description',
'posts.created_at',
'user.first_name',


+ 1
- 1
views/blogPage.hbs 查看文件

@@ -4,7 +4,7 @@
<a class="blog-post-new-link" href="/blog/new">+ New Post</a>
{{/if}}
{{#each posts}}
{{> post title=this.title created_at=this.created_at description=this.description id=this.id first_name=this.first_name last_name=this.last_name}}
{{> post title=this.title slug=this.slug created_at=this.created_at description=this.description first_name=this.first_name last_name=this.last_name}}
{{/each}}
<nav class="blog-navigation">
{{#if (compare page '>' 1)}}


+ 1
- 1
views/partials/post.hbs 查看文件

@@ -1,7 +1,7 @@
<article class="blog-post">
<div class="blog-post-heading">
<h1 class="blog-post-title">
<a class="blog-post-link" href="/blog/post/{{id}}">{{ title }}</a>
<a class="blog-post-link" href="/blog/post/{{slug}}">{{ title }}</a>
</h1>
<small class="blog-post-date">{{created_at}}</small>
</div>


正在加载...
取消
保存