diff --git a/DjangoBlog/settings.py b/DjangoBlog/settings.py index 0209bf0..be83540 100644 --- a/DjangoBlog/settings.py +++ b/DjangoBlog/settings.py @@ -65,6 +65,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'blog.context_processors.seo_processor', ], }, }, @@ -129,5 +130,5 @@ TIME_FORMAT = '%Y-%m-%d %H:%M:%S' DATE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S' SITE_NAME = 'Django Blog' -SITE_DESCRIPTION = 'The Simple blog creating by Django and Bootstrap.' +SITE_DESCRIPTION = '大巧无工,重剑无锋.' ARTICLE_SUB_LENGTH = 300 diff --git a/blog/context_processors.py b/blog/context_processors.py new file mode 100644 index 0000000..4f1f030 --- /dev/null +++ b/blog/context_processors.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: ?? +@author: liangliangyy +@license: MIT Licence +@contact: liangliangyy@gmail.com +@site: https://www.lylinux.org/ +@software: PyCharm +@file: context_processors.py +@time: 2016/11/6 下午4:23 +""" +from .models import Category, Article, Tag +from django.conf import settings + + +def seo_processor(requests): + return { + 'SITE_NAME': settings.SITE_NAME, + 'SITE_DESCRIPTION': settings.SITE_DESCRIPTION + } diff --git a/blog/models.py b/blog/models.py index d2e9c47..2231eda 100644 --- a/blog/models.py +++ b/blog/models.py @@ -36,7 +36,7 @@ class Article(models.Model): def getCategoryNameTree(self): names = [] - names.append((settings.SITE_NAME, 'http://127.0.0.1:8000')) + def parse(category): names.append((category.name,category.get_absolute_url())) diff --git a/blog/static/blog/css/blog.css b/blog/static/blog/css/blog.css index f9106eb..e840bac 100644 --- a/blog/static/blog/css/blog.css +++ b/blog/static/blog/css/blog.css @@ -3,8 +3,8 @@ */ body { - font-family: Georgia, "Times New Roman", Times, serif; - color: #555; + font-family: Georgia, "Times New Roman", Times, serif; + color: #555; } h1, .h1, @@ -13,154 +13,164 @@ h3, .h3, h4, .h4, h5, .h5, h6, .h6 { - margin-top: 0; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-weight: normal; - color: #333; + margin-top: 0; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; + color: #333; } - /* * Override Bootstrap's default container. */ @media (min-width: 1200px) { - .container { - width: 970px; - } + .container { + width: 970px; + } } - /* * Masthead for nav */ .blog-masthead { - background-color: #428bca; - -webkit-box-shadow: inset 0 -2px 5px rgba(0,0,0,.1); - box-shadow: inset 0 -2px 5px rgba(0,0,0,.1); + background-color: #428bca; + -webkit-box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1); + box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1); } /* Nav links */ .blog-nav-item { - position: relative; - display: inline-block; - padding: 10px; - font-weight: 500; - color: #cdddeb; + position: relative; + display: inline-block; + padding: 10px; + font-weight: 500; + color: #cdddeb; } + .blog-nav-item:hover, .blog-nav-item:focus { - color: #fff; - text-decoration: none; + color: #fff; + text-decoration: none; } /* Active state gets a caret at the bottom */ .blog-nav .active { - color: #fff; + color: #fff; } + .blog-nav .active:after { - position: absolute; - bottom: 0; - left: 50%; - width: 0; - height: 0; - margin-left: -5px; - vertical-align: middle; - content: " "; - border-right: 5px solid transparent; - border-bottom: 5px solid; - border-left: 5px solid transparent; + position: absolute; + bottom: 0; + left: 50%; + width: 0; + height: 0; + margin-left: -5px; + vertical-align: middle; + content: " "; + border-right: 5px solid transparent; + border-bottom: 5px solid; + border-left: 5px solid transparent; } - /* * Blog name and description */ .blog-header { - padding-top: 20px; - padding-bottom: 20px; + padding-top: 20px; + padding-bottom: 20px; } + .blog-title { - margin-top: 30px; - margin-bottom: 0; - font-size: 60px; - font-weight: normal; + margin-top: 30px; + margin-bottom: 0; + font-size: 60px; + font-weight: normal; } + .blog-description { - font-size: 20px; - color: #999; + font-size: 20px; + color: #999; } - /* * Main column and sidebar layout */ .blog-main { - font-size: 18px; - line-height: 1.5; + font-size: 18px; + line-height: 1.5; } /* Sidebar modules for boxing content */ .sidebar-module { - padding: 15px; - margin: 0 -15px 15px; + padding: 15px; + margin: 0 -15px 15px; } + .sidebar-module-inset { - padding: 15px; - background-color: #f5f5f5; - border-radius: 4px; + padding: 15px; + background-color: #f5f5f5; + border-radius: 4px; } + .sidebar-module-inset p:last-child, .sidebar-module-inset ul:last-child, .sidebar-module-inset ol:last-child { - margin-bottom: 0; + margin-bottom: 0; } - /* Pagination */ .pager { - margin-bottom: 60px; - text-align: left; + margin-bottom: 60px; + text-align: left; } + .pager > li > a { - width: 140px; - padding: 10px 20px; - text-align: center; - border-radius: 30px; + width: 140px; + padding: 10px 20px; + text-align: center; + border-radius: 30px; } - /* * Blog posts */ .blog-post { - margin-bottom: 60px; + margin-bottom: 60px; } + .blog-post-title { - margin-bottom: 5px; - font-size: 40px; + margin-bottom: 5px; + font-size: 40px; } + .blog-post-meta { - margin-bottom: 20px; - color: #999; + margin-bottom: 20px; + color: #999; } - /* * Footer */ .blog-footer { - padding: 40px 0; - color: #999; - text-align: center; - background-color: #f9f9f9; - border-top: 1px solid #e5e5e5; + padding: 40px 0; + color: #999; + text-align: center; + background-color: #f9f9f9; + border-top: 1px solid #e5e5e5; } + .blog-footer p:last-child { - margin-bottom: 0; + margin-bottom: 0; } + +.blog-read-more { + margin-top: 40px; + margin-bottom: auto; + color: #00CCFF; + border-bottom: 4px double #ededed; +} \ No newline at end of file diff --git a/blog/templatetags/blog_tags.py b/blog/templatetags/blog_tags.py index 49f2476..e5ae32b 100644 --- a/blog/templatetags/blog_tags.py +++ b/blog/templatetags/blog_tags.py @@ -43,6 +43,9 @@ def custom_markdown(content): @register.inclusion_tag('categorytree.html') def parseCategoryName(article): names = article.getCategoryNameTree() + + names.append((settings.SITE_NAME, 'http://127.0.0.1:8000')) + names = names[::-1] print(names) return {'names': names} diff --git a/blog/views.py b/blog/views.py index 760e49e..b5e6328 100644 --- a/blog/views.py +++ b/blog/views.py @@ -36,11 +36,6 @@ class IndexView(ArticleListView): return article_list - def get_context_data(self, **kwargs): - # 增加额外的数据,这里返回一个文章分类,以字典的形式 - kwargs['category_list'] = Category.objects.all().order_by('name') - return super(IndexView, self).get_context_data(**kwargs) - class ArticleDetailView(DetailView): template_name = 'articledetail.html' @@ -67,11 +62,20 @@ class CategoryDetailView(ArticleListView): article_list = Article.objects.filter(category__name=categoryname, status='p') return article_list + def get_context_data(self, **kwargs): + # 增加额外的数据,这里返回一个文章分类,以字典的形式 + kwargs['page_description'] = self.page_description + return super(CategoryDetailView, self).get_context_data(**kwargs) + class AuthorDetailView(ArticleListView): def get_queryset(self): author_name = self.kwargs['author_name'] - self.page_description = '分类目录归档: %s ' % author_name + self.page_description = '作者文章归档: %s ' % author_name article_list = Article.objects.filter(author__username=author_name) return article_list + + def get_context_data(self, **kwargs): + kwargs['page_description'] = self.page_description + return super(AuthorDetailView, self).get_context_data(**kwargs) diff --git a/templates/base.html b/templates/base.html index de58fbb..778c3be 100644 --- a/templates/base.html +++ b/templates/base.html @@ -51,10 +51,12 @@

- The Django Blog + {{ SITE_NAME }}

-

The Simple blog creating by Django and Bootstrap.

+

+ {{ SITE_DESCRIPTION }} +

{% block content %} {% endblock %} diff --git a/templates/index.html b/templates/index.html index 4f6ffc3..a94b129 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,7 @@
{% for article in article_list %} +
{{ article.title }} @@ -20,6 +21,11 @@ by {{ article.author }}

{{ article.body|custom_markdown }} +

+ + Read more + +

{% endfor %}