Skip to content

Commit 319fa20

Browse files
committed
Add mobile and SEO improvements
1 parent 51c53e3 commit 319fa20

20 files changed

+124
-56
lines changed

blog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import requests
3-
from flask import Flask, g, render_template
3+
from flask import Flask, g, render_template, url_for
44
from werkzeug.exceptions import HTTPException
55

66
def create_app(test_config=None):

blog/articles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def get_paginated_articles(directory, page=1, per_page=10):
8282
files = files[first_entry:last_entry]
8383
return __parse_articles(directory, files)
8484

85+
def get_all_articles(directory):
86+
files = [f for f in listdir(directory) if isfile(join(directory, f))]
87+
files.sort()
88+
files.reverse()
89+
current_app.logger.debug(f"Returned {len(files)} files...")
90+
return __parse_articles(directory, files)
8591

8692
def get_pages(directory, per_page=10):
8793
files = [f for f in listdir(directory) if isfile(join(directory, f))]

blog/assets/scss/_variables.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
$tablet: 768px;
2+
$max: 1240px;
3+
14
$headingColour: #000;
25
$linkColour: #000;
36
$textColour: #000;

blog/assets/scss/default.scss

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ html, body {
1111
}
1212

1313
html {
14+
font-size: 12px;
1415
line-height: 1.15;
16+
17+
@media screen and (min-width: $tablet) {
18+
font-size: 16px;
19+
}
1520
}
1621

1722
body {
1823
color: $textColour;
1924
font-family: 'Roboto', sans-serif;
20-
font-size: 20px;
25+
font-size: 1.25rem;
2126
}
2227

2328
h1, h2, h3, h4 {
@@ -35,42 +40,42 @@ a:hover {
3540

3641
header[role=banner] {
3742
margin: 0 auto;
38-
max-width: 1240px;
39-
padding: 1em 0;
43+
max-width: $max;
44+
padding: 1rem 0;
4045
width: 90%;
4146

47+
> a {
48+
display: inline-block;
49+
font-size: 1.125rem;
50+
font-weight: 400;
51+
margin: 0;
52+
padding: 1rem 0;
53+
vertical-align: top;
54+
}
55+
4256
p {
4357
margin: 0;
44-
padding-top: .5em;
58+
padding-top: .5rem;
4559
}
4660
}
4761

4862
main {
4963
margin: 0 auto;
50-
max-width: 1240px;
51-
padding: 1em 0;
64+
max-width: $max;
65+
padding: 1rem 0;
5266
width: 90%;
5367
}
5468

5569
footer[role=contentinfo] {
5670
color: $footerColour;
57-
font-size: .9em;
71+
font-size: .9rem;
5872
font-weight: 400;
5973
margin: 0 auto;
60-
max-width: 1240px;
61-
padding: 2em 0;
74+
max-width: $max;
75+
padding: 2rem 0;
6276
width: 90%;
6377
}
6478

65-
h1 {
66-
display: inline-block;
67-
font-size: .9em;
68-
font-weight: 400;
69-
margin: 0;
70-
padding: 1em 0;
71-
vertical-align: top;
72-
}
73-
7479
.float-right {
7580
float: right;
7681
}
@@ -86,49 +91,49 @@ h1 {
8691
}
8792

8893
article {
89-
margin-bottom: 7em;
94+
margin-bottom: 7rem;
9095
padding: 1rem 0;
9196

92-
h2 {
93-
font-size: 2em;
97+
h1 {
98+
font-size: 2.5rem;
9499
font-weight: 900;
95100
margin: 0 auto;
96101
max-width: 700px;
97-
padding: 1em 0 .75em;
102+
padding: 1.5rem 0 1.25rem;
98103

99104
a, a:link, a:visited, a:active {
100105
font-weight: 900;
101106
}
102107
}
103108

104-
h3 {
109+
p.date {
105110
color: $footerColour;
106-
font-size: .9em;
111+
font-size: 1.125rem;
107112
font-weight: 400;
108-
margin: 0 auto 2em;
113+
margin: 0 auto 2.5rem;
109114
max-width: 700px;
110-
padding: 0 0 1em;
115+
padding: 0 0 1.5rem;
111116
}
112117

113118
.summary, .content {
114119
margin: 0 auto;
115120
max-width: 700px;
116121

117122
&.content {
118-
margin-top: 2em;
123+
margin-top: 2.5rem;
119124
}
120125

121126
h3 {
122127
color: $textColour;
123-
font-size: 1.5em;
128+
font-size: 1.5rem;
124129
font-weight: 700;
125-
margin: 1.5em auto 1em;
130+
margin: 1.5rem auto 1rem;
126131
padding: 0;
127132
}
128133

129134
p, ol, ul {
130135
line-height: 1.75;
131-
margin: 0 0 1.5em;
136+
margin: 0 0 1.5rem;
132137
}
133138

134139
a, a:link, a:visited, a:active, a:hover {
@@ -149,16 +154,16 @@ article {
149154
code {
150155
background-color: $formColour;
151156
color: #fff;
152-
font-size: .75em;
153-
padding: .125em;
157+
font-size: .75rem;
158+
padding: .125rem;
154159
}
155160

156161
pre > code {
157162
display: block;
158163
line-height: 1.25;
159164
max-width: 100%;
160165
overflow: auto;
161-
padding: .5em;
166+
padding: .5rem;
162167
}
163168
}
164169

@@ -175,8 +180,8 @@ article {
175180
color: #fff;
176181
cursor: pointer;
177182
display: inline-block;
178-
font-size: 16px;
179-
padding: 0.75em 2em;
183+
font-size: 1rem;
184+
padding: 0.75rem 2rem;
180185
text-decoration: none;
181186
text-shadow: none;
182187
transition: .2s;
@@ -220,7 +225,7 @@ article {
220225
border-radius: 3px;
221226
color: $linkColour;
222227
font-weight: 300;
223-
padding: 6px 12px;
228+
padding: .375rem .75rem;
224229
transition: .3s;
225230
}
226231

@@ -243,10 +248,10 @@ article {
243248

244249
.prev-next {
245250
border-top: 2px solid $borderColour;
246-
padding: 10px 0;
251+
padding: .625rem 0;
247252
display: flex;
248253
line-height: 1.5;
249-
margin: 2em auto;
254+
margin: 2rem auto;
250255
max-width: 700px;
251256

252257
> div {
@@ -261,6 +266,6 @@ article {
261266
span {
262267
color: $footerColour;
263268
display: block;
264-
font-size: 14px;
269+
font-size: .875rem;
265270
}
266271
}

blog/blog.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
from flask import (
2-
abort, Blueprint, current_app, render_template, request
2+
abort, Blueprint, current_app, make_response, render_template, request, send_from_directory
33
)
44

55
from . import articles
66

77
bp = Blueprint('blog', __name__)
88

9+
@bp.route('/favicon.ico')
10+
@bp.route('/humans.txt')
11+
@bp.route('/robots.txt')
12+
def static_from_root():
13+
return send_from_directory(current_app.static_folder, request.path[1:])
14+
15+
@bp.route('/sitemap.xml', methods=['GET'])
16+
def sitemap():
17+
directory = current_app.config['ARTICLES_DIR']
18+
parsed_articles = articles.get_all_articles(directory)
19+
20+
template = render_template(
21+
'sitemap.xml',
22+
articles=parsed_articles,
23+
)
24+
response = make_response(template)
25+
response.headers['Content-Type'] = 'application/xml'
26+
27+
return response
28+
929
@bp.route('/', methods=['GET'])
1030
def index():
1131
directory = current_app.config['ARTICLES_DIR']
4.12 KB
Loading
14 KB
Loading

blog/static/apple-touch-icon.png

3.75 KB
Loading

blog/static/css/default.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blog/static/favicon-16x16.png

311 Bytes
Loading

0 commit comments

Comments
 (0)