diff --git a/app.py b/app.py index 93c2466..2aad106 100644 --- a/app.py +++ b/app.py @@ -265,6 +265,34 @@ def delete_post(id): else: return jsonify(success=False, message='Could not delete the post'), 500 +@app.route('/list') +@app.route('/list/') +def list(cate=None): + params = () + cate_condition = "" + + if cate: + cate_condition = "AND `category` = %s" + params = (cate,) + + if 'user_info' in session: # 로그인된 사용자 + query = f"""SELECT `id`, `title`, `category`, `thumbnail_img`, `contents`, `add_date` + FROM `blog` + WHERE `use_yn` = 'Y' {cate_condition} + ORDER BY `add_date` DESC;""" + else: + query = f"""SELECT `id`, `title`, `category`, `thumbnail_img`, `contents`, `add_date` + FROM `blog` + WHERE `use_yn` = 'Y' AND `public_yn` = 'Y' {cate_condition} + ORDER BY `add_date` DESC;""" + + r, posts = sql_execute(query, params, is_data=True) + + # 태그 제거 후 150자로 제한 + for post in posts: + post['contents'] = remove_html_tags(post['contents'])[:150] + + return render_template('list.html', posts=posts) # ============================================ # 관리자 페이지 diff --git a/static/css/style.css b/static/css/style.css index 2b262f0..cc42c7d 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -273,3 +273,10 @@ /* login */ .uk-form-stacked{min-width:640px;width:30%;margin:0 auto;} .login__btn{width:100%;} + + /* list css */ + .list__posts{float:left;width:30%;padding-right:3%;} + .list__posts li{width:100%;height:auto;} + .list__posts li a{display:block;width:100%;height:100%;} + .list__posts li:hover{text-shadow:1px 0px 1px RGBA(0,0,0,0.3);} + .list__posts li:hover .lists__img{box-shadow:1px 1px 5px RGBA(144,20,68,0.2);} diff --git a/templates/base.html b/templates/base.html index 4893600..93970f9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -28,11 +28,11 @@