Skip to content

Commit df3218f

Browse files
committed
修改代码高亮,增加谷歌广告
1 parent 8c9c504 commit df3218f

37 files changed

+2965
-29
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ target/
6767
migrations/
6868
!migrations/__init__.py
6969
collectedstatic/
70-
DjangoBlog/whoosh_index/
70+
DjangoBlog/whoosh_index/
71+
google93fd32dbd906620a.html

DjangoBlog/common_markdown.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
4+
5+
"""
6+
@version: ??
7+
@author: liangliangyy
8+
@license: MIT Licence
9+
@contact: liangliangyy@gmail.com
10+
@site: https://www.lylinux.org/
11+
@software: PyCharm
12+
@file: common_markdown.py
13+
@time: 2017/1/14 上午2:30
14+
"""
15+
16+
import mistune
17+
from pygments import highlight
18+
from pygments.lexers import get_lexer_by_name
19+
from pygments.formatters import html
20+
21+
22+
def block_code(text, lang, inlinestyles=False, linenos=False):
23+
if not lang:
24+
text = text.strip()
25+
return u'<pre><code>%s</code></pre>\n' % mistune.escape(text)
26+
27+
try:
28+
lexer = get_lexer_by_name(lang, stripall=True)
29+
formatter = html.HtmlFormatter(
30+
noclasses=inlinestyles, linenos=linenos
31+
)
32+
code = highlight(text, lexer, formatter)
33+
if linenos:
34+
return '<div class="highlight">%s</div>\n' % code
35+
return code
36+
except:
37+
return '<pre class="%s"><code>%s</code></pre>\n' % (
38+
lang, mistune.escape(text)
39+
)
40+
41+
42+
class BlogMarkDownRenderer(mistune.Renderer):
43+
def block_code(self, text, lang):
44+
# renderer has an options
45+
inlinestyles = self.options.get('inlinestyles')
46+
linenos = self.options.get('linenos')
47+
return block_code(text, lang, inlinestyles, linenos)
48+
49+
50+
class common_markdown():
51+
@staticmethod
52+
def get_markdown(value):
53+
renderer = BlogMarkDownRenderer(inlinestyles=False)
54+
55+
mdp = mistune.Markdown(escape=True, renderer=renderer)
56+
return mdp(value)

DjangoBlog/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
SITE_SEO_DESCRIPTION = '小站主要用来分享和记录学习经验,教程,记录个人生活的点滴以及一些随笔.欢迎大家访问小站'
159159
SITE_SEO_KEYWORDS = 'linux,apache,mysql,服务器,ubuntu,shell,web,csharp,.net,asp,mac,swift'
160160
ARTICLE_SUB_LENGTH = 300
161-
161+
SHOW_GOOGLE_ADSENSE = True
162162
# bootstrap颜色样式
163163
BOOTSTRAP_COLOR_TYPES = [
164164
'default', 'primary', 'success', 'info', 'warning', 'danger'

blog/context_processors.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
def seo_processor(requests):
2020
return {
2121
'SITE_NAME': settings.SITE_NAME,
22+
'SHOW_GOOGLE_ADSENSE': settings.SHOW_GOOGLE_ADSENSE,
2223
'SITE_SEO_DESCRIPTION': settings.SITE_SEO_DESCRIPTION,
2324
'SITE_DESCRIPTION': settings.SITE_DESCRIPTION,
2425
'SITE_KEYWORDS': settings.SITE_SEO_KEYWORDS,

blog/static/blog/css/style.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ article.sticky .featured-post {
923923
font-size: 12px;
924924
font-size: 0.857142857rem;
925925
line-height: 2;
926+
background-color: rgba(0,0,0,0.04);
926927
}
927928

928929
.entry-content pre,
@@ -2356,4 +2357,4 @@ li #reply-title {
23562357
border: 0;
23572358
font: inherit;
23582359
vertical-align: baseline;
2359-
}
2360+
}

blog/static/pygments/README.rst

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pygments-css
2+
============
3+
4+
Pygments_, a Python-based code highlighting tool, comes with a set of builtin styles_ (not css files) for code highlighting. You have to generate a CSS file using the command line. I just figured I'd save someone this work in the future and generate all the CSS files based on the Pygments builtins.
5+
6+
Pretty simple stuff here. These css files were generated using pygmentize
7+
on the command line like so::
8+
9+
pygmentize -S default -f html > default.css
10+
11+
I'm using a combination of Pygments and Markdown on a django project that has a model with the following save method::
12+
13+
def save(self):
14+
self.html = markdown(self.body, 'codehilite')
15+
super(Entry, self).save()
16+
17+
That's why the CSS styles all have .codehilite in front of them. You should change the .codehilite to work with the style name that you use for your Pygments HTML output.
18+
19+
.. _Pygments: http://pygments.org
20+
.. _styles: http://dev.pocoo.org/projects/pygments/browser/pygments/styles
21+
22+
Theme previews
23+
--------------
24+
25+
To preview the various themes, check out http://richleland.github.io/pygments-css/.

blog/static/pygments/UNLICENSE.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org>

blog/static/pygments/autumn.css

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.codehilite .hll { background-color: #ffffcc }
2+
.codehilite .c { color: #aaaaaa; font-style: italic } /* Comment */
3+
.codehilite .err { color: #F00000; background-color: #F0A0A0 } /* Error */
4+
.codehilite .k { color: #0000aa } /* Keyword */
5+
.codehilite .cm { color: #aaaaaa; font-style: italic } /* Comment.Multiline */
6+
.codehilite .cp { color: #4c8317 } /* Comment.Preproc */
7+
.codehilite .c1 { color: #aaaaaa; font-style: italic } /* Comment.Single */
8+
.codehilite .cs { color: #0000aa; font-style: italic } /* Comment.Special */
9+
.codehilite .gd { color: #aa0000 } /* Generic.Deleted */
10+
.codehilite .ge { font-style: italic } /* Generic.Emph */
11+
.codehilite .gr { color: #aa0000 } /* Generic.Error */
12+
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
13+
.codehilite .gi { color: #00aa00 } /* Generic.Inserted */
14+
.codehilite .go { color: #888888 } /* Generic.Output */
15+
.codehilite .gp { color: #555555 } /* Generic.Prompt */
16+
.codehilite .gs { font-weight: bold } /* Generic.Strong */
17+
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
18+
.codehilite .gt { color: #aa0000 } /* Generic.Traceback */
19+
.codehilite .kc { color: #0000aa } /* Keyword.Constant */
20+
.codehilite .kd { color: #0000aa } /* Keyword.Declaration */
21+
.codehilite .kn { color: #0000aa } /* Keyword.Namespace */
22+
.codehilite .kp { color: #0000aa } /* Keyword.Pseudo */
23+
.codehilite .kr { color: #0000aa } /* Keyword.Reserved */
24+
.codehilite .kt { color: #00aaaa } /* Keyword.Type */
25+
.codehilite .m { color: #009999 } /* Literal.Number */
26+
.codehilite .s { color: #aa5500 } /* Literal.String */
27+
.codehilite .na { color: #1e90ff } /* Name.Attribute */
28+
.codehilite .nb { color: #00aaaa } /* Name.Builtin */
29+
.codehilite .nc { color: #00aa00; text-decoration: underline } /* Name.Class */
30+
.codehilite .no { color: #aa0000 } /* Name.Constant */
31+
.codehilite .nd { color: #888888 } /* Name.Decorator */
32+
.codehilite .ni { color: #800000; font-weight: bold } /* Name.Entity */
33+
.codehilite .nf { color: #00aa00 } /* Name.Function */
34+
.codehilite .nn { color: #00aaaa; text-decoration: underline } /* Name.Namespace */
35+
.codehilite .nt { color: #1e90ff; font-weight: bold } /* Name.Tag */
36+
.codehilite .nv { color: #aa0000 } /* Name.Variable */
37+
.codehilite .ow { color: #0000aa } /* Operator.Word */
38+
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
39+
.codehilite .mf { color: #009999 } /* Literal.Number.Float */
40+
.codehilite .mh { color: #009999 } /* Literal.Number.Hex */
41+
.codehilite .mi { color: #009999 } /* Literal.Number.Integer */
42+
.codehilite .mo { color: #009999 } /* Literal.Number.Oct */
43+
.codehilite .sb { color: #aa5500 } /* Literal.String.Backtick */
44+
.codehilite .sc { color: #aa5500 } /* Literal.String.Char */
45+
.codehilite .sd { color: #aa5500 } /* Literal.String.Doc */
46+
.codehilite .s2 { color: #aa5500 } /* Literal.String.Double */
47+
.codehilite .se { color: #aa5500 } /* Literal.String.Escape */
48+
.codehilite .sh { color: #aa5500 } /* Literal.String.Heredoc */
49+
.codehilite .si { color: #aa5500 } /* Literal.String.Interpol */
50+
.codehilite .sx { color: #aa5500 } /* Literal.String.Other */
51+
.codehilite .sr { color: #009999 } /* Literal.String.Regex */
52+
.codehilite .s1 { color: #aa5500 } /* Literal.String.Single */
53+
.codehilite .ss { color: #0000aa } /* Literal.String.Symbol */
54+
.codehilite .bp { color: #00aaaa } /* Name.Builtin.Pseudo */
55+
.codehilite .vc { color: #aa0000 } /* Name.Variable.Class */
56+
.codehilite .vg { color: #aa0000 } /* Name.Variable.Global */
57+
.codehilite .vi { color: #aa0000 } /* Name.Variable.Instance */
58+
.codehilite .il { color: #009999 } /* Literal.Number.Integer.Long */

blog/static/pygments/borland.css

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.codehilite .hll { background-color: #ffffcc }
2+
.codehilite .c { color: #008800; font-style: italic } /* Comment */
3+
.codehilite .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4+
.codehilite .k { color: #000080; font-weight: bold } /* Keyword */
5+
.codehilite .cm { color: #008800; font-style: italic } /* Comment.Multiline */
6+
.codehilite .cp { color: #008080 } /* Comment.Preproc */
7+
.codehilite .c1 { color: #008800; font-style: italic } /* Comment.Single */
8+
.codehilite .cs { color: #008800; font-weight: bold } /* Comment.Special */
9+
.codehilite .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
10+
.codehilite .ge { font-style: italic } /* Generic.Emph */
11+
.codehilite .gr { color: #aa0000 } /* Generic.Error */
12+
.codehilite .gh { color: #999999 } /* Generic.Heading */
13+
.codehilite .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
14+
.codehilite .go { color: #888888 } /* Generic.Output */
15+
.codehilite .gp { color: #555555 } /* Generic.Prompt */
16+
.codehilite .gs { font-weight: bold } /* Generic.Strong */
17+
.codehilite .gu { color: #aaaaaa } /* Generic.Subheading */
18+
.codehilite .gt { color: #aa0000 } /* Generic.Traceback */
19+
.codehilite .kc { color: #000080; font-weight: bold } /* Keyword.Constant */
20+
.codehilite .kd { color: #000080; font-weight: bold } /* Keyword.Declaration */
21+
.codehilite .kn { color: #000080; font-weight: bold } /* Keyword.Namespace */
22+
.codehilite .kp { color: #000080; font-weight: bold } /* Keyword.Pseudo */
23+
.codehilite .kr { color: #000080; font-weight: bold } /* Keyword.Reserved */
24+
.codehilite .kt { color: #000080; font-weight: bold } /* Keyword.Type */
25+
.codehilite .m { color: #0000FF } /* Literal.Number */
26+
.codehilite .s { color: #0000FF } /* Literal.String */
27+
.codehilite .na { color: #FF0000 } /* Name.Attribute */
28+
.codehilite .nt { color: #000080; font-weight: bold } /* Name.Tag */
29+
.codehilite .ow { font-weight: bold } /* Operator.Word */
30+
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
31+
.codehilite .mf { color: #0000FF } /* Literal.Number.Float */
32+
.codehilite .mh { color: #0000FF } /* Literal.Number.Hex */
33+
.codehilite .mi { color: #0000FF } /* Literal.Number.Integer */
34+
.codehilite .mo { color: #0000FF } /* Literal.Number.Oct */
35+
.codehilite .sb { color: #0000FF } /* Literal.String.Backtick */
36+
.codehilite .sc { color: #800080 } /* Literal.String.Char */
37+
.codehilite .sd { color: #0000FF } /* Literal.String.Doc */
38+
.codehilite .s2 { color: #0000FF } /* Literal.String.Double */
39+
.codehilite .se { color: #0000FF } /* Literal.String.Escape */
40+
.codehilite .sh { color: #0000FF } /* Literal.String.Heredoc */
41+
.codehilite .si { color: #0000FF } /* Literal.String.Interpol */
42+
.codehilite .sx { color: #0000FF } /* Literal.String.Other */
43+
.codehilite .sr { color: #0000FF } /* Literal.String.Regex */
44+
.codehilite .s1 { color: #0000FF } /* Literal.String.Single */
45+
.codehilite .ss { color: #0000FF } /* Literal.String.Symbol */
46+
.codehilite .il { color: #0000FF } /* Literal.Number.Integer.Long */

blog/static/pygments/bw.css

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.codehilite .hll { background-color: #ffffcc }
2+
.codehilite .c { font-style: italic } /* Comment */
3+
.codehilite .err { border: 1px solid #FF0000 } /* Error */
4+
.codehilite .k { font-weight: bold } /* Keyword */
5+
.codehilite .cm { font-style: italic } /* Comment.Multiline */
6+
.codehilite .c1 { font-style: italic } /* Comment.Single */
7+
.codehilite .cs { font-style: italic } /* Comment.Special */
8+
.codehilite .ge { font-style: italic } /* Generic.Emph */
9+
.codehilite .gh { font-weight: bold } /* Generic.Heading */
10+
.codehilite .gp { font-weight: bold } /* Generic.Prompt */
11+
.codehilite .gs { font-weight: bold } /* Generic.Strong */
12+
.codehilite .gu { font-weight: bold } /* Generic.Subheading */
13+
.codehilite .kc { font-weight: bold } /* Keyword.Constant */
14+
.codehilite .kd { font-weight: bold } /* Keyword.Declaration */
15+
.codehilite .kn { font-weight: bold } /* Keyword.Namespace */
16+
.codehilite .kr { font-weight: bold } /* Keyword.Reserved */
17+
.codehilite .s { font-style: italic } /* Literal.String */
18+
.codehilite .nc { font-weight: bold } /* Name.Class */
19+
.codehilite .ni { font-weight: bold } /* Name.Entity */
20+
.codehilite .ne { font-weight: bold } /* Name.Exception */
21+
.codehilite .nn { font-weight: bold } /* Name.Namespace */
22+
.codehilite .nt { font-weight: bold } /* Name.Tag */
23+
.codehilite .ow { font-weight: bold } /* Operator.Word */
24+
.codehilite .sb { font-style: italic } /* Literal.String.Backtick */
25+
.codehilite .sc { font-style: italic } /* Literal.String.Char */
26+
.codehilite .sd { font-style: italic } /* Literal.String.Doc */
27+
.codehilite .s2 { font-style: italic } /* Literal.String.Double */
28+
.codehilite .se { font-weight: bold; font-style: italic } /* Literal.String.Escape */
29+
.codehilite .sh { font-style: italic } /* Literal.String.Heredoc */
30+
.codehilite .si { font-weight: bold; font-style: italic } /* Literal.String.Interpol */
31+
.codehilite .sx { font-style: italic } /* Literal.String.Other */
32+
.codehilite .sr { font-style: italic } /* Literal.String.Regex */
33+
.codehilite .s1 { font-style: italic } /* Literal.String.Single */
34+
.codehilite .ss { font-style: italic } /* Literal.String.Symbol */

blog/static/pygments/colorful.css

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.codehilite .hll { background-color: #ffffcc }
2+
.codehilite .c { color: #808080 } /* Comment */
3+
.codehilite .err { color: #F00000; background-color: #F0A0A0 } /* Error */
4+
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
5+
.codehilite .o { color: #303030 } /* Operator */
6+
.codehilite .cm { color: #808080 } /* Comment.Multiline */
7+
.codehilite .cp { color: #507090 } /* Comment.Preproc */
8+
.codehilite .c1 { color: #808080 } /* Comment.Single */
9+
.codehilite .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
10+
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
11+
.codehilite .ge { font-style: italic } /* Generic.Emph */
12+
.codehilite .gr { color: #FF0000 } /* Generic.Error */
13+
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
14+
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
15+
.codehilite .go { color: #808080 } /* Generic.Output */
16+
.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
17+
.codehilite .gs { font-weight: bold } /* Generic.Strong */
18+
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
19+
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
20+
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
21+
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
22+
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
23+
.codehilite .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
24+
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
25+
.codehilite .kt { color: #303090; font-weight: bold } /* Keyword.Type */
26+
.codehilite .m { color: #6000E0; font-weight: bold } /* Literal.Number */
27+
.codehilite .s { background-color: #fff0f0 } /* Literal.String */
28+
.codehilite .na { color: #0000C0 } /* Name.Attribute */
29+
.codehilite .nb { color: #007020 } /* Name.Builtin */
30+
.codehilite .nc { color: #B00060; font-weight: bold } /* Name.Class */
31+
.codehilite .no { color: #003060; font-weight: bold } /* Name.Constant */
32+
.codehilite .nd { color: #505050; font-weight: bold } /* Name.Decorator */
33+
.codehilite .ni { color: #800000; font-weight: bold } /* Name.Entity */
34+
.codehilite .ne { color: #F00000; font-weight: bold } /* Name.Exception */
35+
.codehilite .nf { color: #0060B0; font-weight: bold } /* Name.Function */
36+
.codehilite .nl { color: #907000; font-weight: bold } /* Name.Label */
37+
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
38+
.codehilite .nt { color: #007000 } /* Name.Tag */
39+
.codehilite .nv { color: #906030 } /* Name.Variable */
40+
.codehilite .ow { color: #000000; font-weight: bold } /* Operator.Word */
41+
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
42+
.codehilite .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
43+
.codehilite .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
44+
.codehilite .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
45+
.codehilite .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
46+
.codehilite .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
47+
.codehilite .sc { color: #0040D0 } /* Literal.String.Char */
48+
.codehilite .sd { color: #D04020 } /* Literal.String.Doc */
49+
.codehilite .s2 { background-color: #fff0f0 } /* Literal.String.Double */
50+
.codehilite .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
51+
.codehilite .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
52+
.codehilite .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
53+
.codehilite .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
54+
.codehilite .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
55+
.codehilite .s1 { background-color: #fff0f0 } /* Literal.String.Single */
56+
.codehilite .ss { color: #A06000 } /* Literal.String.Symbol */
57+
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
58+
.codehilite .vc { color: #306090 } /* Name.Variable.Class */
59+
.codehilite .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
60+
.codehilite .vi { color: #3030B0 } /* Name.Variable.Instance */
61+
.codehilite .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */

0 commit comments

Comments
 (0)