Skip to content

Commit

Permalink
开发版本
Browse files Browse the repository at this point in the history
  • Loading branch information
1164812866 committed Jun 27, 2020
1 parent 9e6f160 commit 326aa29
Show file tree
Hide file tree
Showing 15 changed files with 10 additions and 46 deletions.
Binary file modified blog/__pycache__/views.cpython-36.pyc
Binary file not shown.
3 changes: 0 additions & 3 deletions blog/templates/blog/archive.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends "blog/base.html" %}
{% load static %}
{% load blog_tags %}
{% load cache %}

{% block head_title %}博客归档{% endblock %}
{% block metas %}
Expand All @@ -20,7 +19,6 @@
{% block base_content %}
<div class="container">
<div class="row">
{% cache 3600 'cache_archive_html_tag' %}
<div class="col-lg-8">
<div class="card border-0 rounded-0 mb-3">
<div class="card-body f-16 archive">
Expand All @@ -47,7 +45,6 @@
</div>
{% if is_paginated %}{% load_pages %}{% endif %}
</div>
{% endcache %}
<div class="col-lg-4 d-none d-lg-block">
{% include 'blog/tags/base_right.html' %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion blog/templates/blog/tag.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "blog/base.html" %}
{% load static %}
{% load blog_tags %}
{% load blog_tags %}

{% block head_title %}{{ search_instance.name }}_{{ search_tag }}{% endblock %}
{% block metas %}
Expand Down
5 changes: 1 addition & 4 deletions blog/templates/blog/tags/base_right.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% load blog_tags static %}
{% load cache %}

<!--个人空间-->
{% cache 1800 'cache_baseright_html_tag' %}
<div class="card border-0 rounded-0 px-3 mb-2 mb-md-3 d-none d-lg-block" id="home-card">
<div class="card-header bg-white px-0">
<strong><i class="fa fa-paper-plane mr-2 f-17"></i>个人空间</strong>
Expand Down Expand Up @@ -128,5 +126,4 @@
</div>
</div>
</div>
</div>
{% endcache %}
</div>
4 changes: 1 addition & 3 deletions blog/templates/blog/timeline.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'blog/base.html' %}
{% load static %}
{% load blog_tags %}
{% load cache %}


{% block top-file %}
<link href="{% static 'blog/css/timeline.css'%}?v=1.07" rel="stylesheet">
Expand All @@ -15,7 +15,6 @@
{% endblock %}

{% block base_content %}
{% cache 7200 'cache_timeline_tag' %}
<div class="container">
<div class="page-header mt-0">
<h1 id="timeline"><i class="fa fa-hourglass-half mr-2"></i>建站日志</h1>
Expand Down Expand Up @@ -45,7 +44,6 @@ <h2 class="timeline-title text-info">{{ timeline.title_to_emoji }}</h2>
{% endfor %}
</ul>
</div>
{% endcache %}
{% endblock %}

{% block js-file %}
Expand Down
39 changes: 7 additions & 32 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.views import generic
from .models import Article,Category,Tag,Timeline
from django.conf import settings
from django.core.cache import cache# redis缓存

import markdown
import time, datetime
Expand Down Expand Up @@ -43,37 +42,13 @@ class DetailView(generic.DetailView):

def get_object(self):
obj = super(DetailView, self).get_object()
# 设置浏览量增加时间判断,同一篇文章两次浏览超过半小时才重新统计阅览量,作者浏览忽略
u = self.request.user
ses = self.request.session
the_key = 'is_read_{}'.format(obj.id)
is_read_time = ses.get(the_key)
if u != obj.author:
if not is_read_time:
obj.update_views()
ses[the_key] = time.time()
else:
now_time = time.time()
t = now_time - is_read_time
if t > 60 * 30:
obj.update_views()
ses[the_key] = time.time()
# 获取文章更新的时间,判断是否从缓存中取文章的markdown,可以避免每次都转换
ud = obj.update_date.strftime("%Y%m%d%H%M%S")
md_key = '{}_md_{}'.format(obj.id, ud)
cache_md = cache.get(md_key)
if cache_md:
md = cache_md
else:
md = markdown.Markdown(extensions=[
'markdown.extensions.extra',
'markdown.extensions.codehilite',
'markdown.extensions.toc',
])
obj.body = md.convert(obj.body)
obj.toc = md.toc
# 关键在这个地方,不能直接把 md 存进去
cache.set(md_key, (obj.body, obj.toc), 60 * 60 * 12)
md = markdown.Markdown(extensions=[
'markdown.extensions.extra',
'markdown.extensions.codehilite',
'markdown.extensions.toc',
])
obj.body = md.convert(obj.body)
obj.toc = md.toc
return obj

# 分类
Expand Down
Binary file added db.sqlite3
Binary file not shown.
Binary file modified izone/__pycache__/settings.cpython-36.pyc
Binary file not shown.
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ django-crispy-forms==1.9.1
django-haystack==2.8.1
django-imagekit==4.0.2
django-js-asset==1.2.2
django-redis==4.12.1
django-simpleui==4.0.3
emoji==0.5.4
idna==2.8
importlib-metadata==1.6.1
jieba==0.42.1
Markdown==3.2.2
mysqlclient==1.4.6
oauthlib==3.1.0
pilkit==2.0
Pillow==7.1.2
Pygments==2.6.1
python3-openid==3.1.0
pytz==2020.1
redis==3.5.3
requests==2.22.0
requests-oauthlib==1.3.0
six==1.15.0
Expand Down
Binary file added whoosh_index/MAIN_ccyuqhjwdo432dzt.seg
Binary file not shown.
Binary file removed whoosh_index/MAIN_i3v1t7omsux0zra1.seg
Binary file not shown.
Binary file not shown.
Binary file removed whoosh_index/MAIN_oztxj91bj8aih9qd.seg
Binary file not shown.
Binary file added whoosh_index/MAIN_qwwd26ynzf5wr54n.seg
Binary file not shown.
Binary file not shown.

0 comments on commit 326aa29

Please sign in to comment.