Skip to content

Commit 6f214a9

Browse files
committed
Update pelican
1 parent bef946f commit 6f214a9

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

website/make_website.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CURDIR = Path(__file__).resolve().parent
1010
COVER_IMAGE = ('https://raw.githubusercontent.com/ipython-books/'
1111
'cookbook-2nd/master/cover-cookbook-2nd.png')
12+
URLIZE_RE = r'(?<!"|\(|\+)(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))'
1213

1314

1415
def get_readme():
@@ -21,7 +22,7 @@ def process_header(contents, metadata=''):
2122
title = contents[i + 2:j]
2223
contents = contents[:i] + contents[j:]
2324
contents = f'title: {title}\n' + metadata + '\n' + contents
24-
return contents
25+
return contents
2526

2627

2728
def process_urls(contents):
@@ -45,25 +46,40 @@ def process_ad(contents):
4546
'*This is one of the 100+ free recipes of the [IPython Cookbook, '
4647
'Second Edition](/)',
4748
)
48-
49-
contents = re.sub(r'\[\*Chapter [^\]]+\*\]\(\.\/\)', '', contents)
49+
50+
contents = re.sub(r'\[(\*Chapter [^\]]+\*)\]\((\.\/)\)',
51+
r"[\1]({filename}index.md)",
52+
contents)
5053

5154
return contents
5255

5356

5457
def process_code(contents):
5558

5659
contents = re.sub(r'\{output:[^\}]+\}', 'output', contents)
57-
5860
contents = re.sub(r'!\[([^\]]+)\]\(([^\)\{]+)\)', r'![\1]({filename}\2)', contents)
61+
contents = re.sub(r'^([0-9]+)\. ', r'**\1.&nbsp;** ', contents, flags=re.M)
62+
contents = re.sub(URLIZE_RE, r'[\1](\1)', contents)
63+
64+
# lines = []
65+
# to_indent = False
66+
# for line in contents.splitlines():
67+
# if re.match(r'^[1-9]{1,}\. ', line):
68+
# to_indent = True
69+
# elif re.match(r'^[\#]{1,} ', line):
70+
# to_indent = False
71+
# if to_indent and not re.match(r'^[1-9]{1,}\. ', line):
72+
# line = ' ' + line
73+
# lines.append(line)
74+
# return '\n'.join(lines)
5975

6076
return contents
6177

6278

6379
def create_index():
6480
readme = get_readme()
6581
readme = process_header(readme, 'save_as: index.html')
66-
82+
6783
readme = readme.replace('This repository contains the sources of the book (in Markdown, ',
6884
'Most of the book is freely available on this website (')
6985

@@ -98,7 +114,7 @@ def create_chapter(chapter):
98114

99115
write_file(index_in, index_out)
100116
for file in sorted(chapter.glob('*.md')):
101-
if file.name == 'README.md':
117+
if file.name in ('README.md', '00_intro.md'):
102118
continue
103119
fin = CURDIR / f'../{chapter.name}/{file.name}'
104120
fout = CURDIR / f'content/pages/{chapter.name}/{file.name}'
@@ -122,4 +138,3 @@ def create_chapter(chapter):
122138
chapters = sorted((CURDIR / '../').glob('chapter*'))
123139
for chapter in chapters:
124140
create_chapter(chapter)
125-
exit()

website/pelicanconf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
DEFAULT_LANG = 'en'
2020

21+
PLUGIN_PATHS = ['../../pelican-plugins']
22+
2123

2224
MARKDOWN = {
2325
'extension_configs': {
@@ -28,11 +30,11 @@
2830
},
2931
'markdown.extensions.extra': {},
3032
'markdown.extensions.meta': {},
31-
# 'markdown.extensions.headerid': {},
3233
},
3334
}
3435

3536

37+
3638
MENUITEMS = (('home', '/'),
3739
('Jupyter notebooks', CODE),
3840
('minibook', MINIBOOK),

website/themes/pure/static/css/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ code {
184184

185185
#post img, .post img, .page img, #page img {
186186
max-width: 100%;
187+
max-height: 400px;
187188
margin: 0 auto;
188189
text-align: center;
189190
display: block;

0 commit comments

Comments
 (0)