Skip to content

Commit b04478b

Browse files
committed
Initial commit
0 parents  commit b04478b

26 files changed

+1444
-0
lines changed

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__
2+
output
3+
content/
4+
venv

Diff for: Makefile

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
PY?=
2+
PELICAN?=pelican
3+
PELICANOPTS=
4+
5+
BASEDIR=$(CURDIR)
6+
INPUTDIR=$(BASEDIR)/content
7+
OUTPUTDIR=$(BASEDIR)/output
8+
CONFFILE=$(BASEDIR)/pelicanconf.py
9+
PUBLISHCONF=$(BASEDIR)/publishconf.py
10+
11+
12+
DEBUG ?= 0
13+
ifeq ($(DEBUG), 1)
14+
PELICANOPTS += -D
15+
endif
16+
17+
RELATIVE ?= 0
18+
ifeq ($(RELATIVE), 1)
19+
PELICANOPTS += --relative-urls
20+
endif
21+
22+
SERVER ?= "0.0.0.0"
23+
24+
PORT ?= 0
25+
ifneq ($(PORT), 0)
26+
PELICANOPTS += -p $(PORT)
27+
endif
28+
29+
30+
help:
31+
@echo 'Makefile for a pelican Web site '
32+
@echo ' '
33+
@echo 'Usage: '
34+
@echo ' make html (re)generate the web site '
35+
@echo ' make clean remove the generated files '
36+
@echo ' make regenerate regenerate files upon modification '
37+
@echo ' make publish generate using production settings '
38+
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
39+
@echo ' make devserver [PORT=8000] serve and regenerate together '
40+
@echo ' '
41+
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
42+
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
43+
@echo ' '
44+
45+
html:
46+
"$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
47+
48+
clean:
49+
[ ! -d "$(OUTPUTDIR)" ] || rm -rf "$(OUTPUTDIR)"
50+
51+
regenerate:
52+
"$(PELICAN)" -r "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
53+
54+
serve:
55+
"$(PELICAN)" -l "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
56+
57+
devserver:
58+
"$(PELICAN)" -lr "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(CONFFILE)" $(PELICANOPTS)
59+
60+
publish:
61+
"$(PELICAN)" "$(INPUTDIR)" -o "$(OUTPUTDIR)" -s "$(PUBLISHCONF)" $(PELICANOPTS)
62+
63+
install_venv:
64+
pip-sync requirements.txt requirements_dev.txt
65+
66+
.PHONY: html help clean regenerate serve serve-global devserver publish

Diff for: pelicanconf.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
AUTHOR = "Toni Mägel"
2+
SITENAME = "tonimaegel.de"
3+
SITEURL = ""
4+
5+
PATH = "content"
6+
7+
TIMEZONE = "Europe/Berlin"
8+
9+
DEFAULT_LANG = "de"
10+
11+
# Uncomment following line if you want document-relative URLs when developing
12+
# Can be useful in development, but set to False when you're ready to publish
13+
# RELATIVE_URLS = True
14+
15+
# Feed generation is usually not desired when developing
16+
FEED_ALL_ATOM = None
17+
CATEGORY_FEED_ATOM = None
18+
TRANSLATION_FEED_ATOM = None
19+
AUTHOR_FEED_ATOM = None
20+
AUTHOR_FEED_RSS = None
21+
22+
# Blogroll
23+
LINKS = ()
24+
25+
# Social widget
26+
SOCIAL = (
27+
("github", "https://github.com/tmaegel/"),
28+
("linkedin", "https://de.linkedin.com/in/toni-maegel"),
29+
("envelope-fill", "mailto:[email protected]"),
30+
)
31+
32+
GITHUB_URL = "https://github.com/tmaegel/"
33+
34+
DISPLAY_CATEGORIES_ON_MENU = False
35+
DISPLAY_PAGES_ON_MENU = True
36+
MENUITEMS = (
37+
("Posts", "/index.html"),
38+
("Themen", "/categories.html"),
39+
("Tags", "/tags.html"),
40+
)
41+
42+
DEFAULT_PAGINATION = 10
43+
44+
PLUGIN_PATH = ["plugins"]
45+
PLUGINS = ["better_codeblock_line_numbering_fork"]
46+
47+
MARKDOWN = {
48+
"extension_configs": {
49+
"markdown.extensions.codehilite": {
50+
"css_class": "highlight",
51+
"linenums": False,
52+
},
53+
"markdown.extensions.extra": {},
54+
"markdown.extensions.meta": {},
55+
},
56+
"output_format": "html5",
57+
}
58+
59+
THEME = "themes/custom"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .better_codeblock_line_numbering import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import re
2+
3+
from pelican import signals # For making this plugin work with Pelican.
4+
5+
6+
def add_line_wrappers(content: str) -> str:
7+
"""
8+
A function to read through each page and post as it comes through
9+
from Pelican to find all instances of triple-backtick (```...```) code
10+
blocks and add an html line wrapper to each line of each of those code
11+
blocks.
12+
13+
<div class="highlight">
14+
<pre>
15+
<span></span>
16+
<code>
17+
codeline1
18+
codeline2
19+
codeline3
20+
</code>
21+
</pre>
22+
</div>
23+
"""
24+
25+
pre_list = re.findall("<pre>.*?</pre>", content, re.DOTALL)
26+
27+
if not pre_list:
28+
return content
29+
30+
for pre in pre_list:
31+
pre_section = ["<pre>", "<code>"]
32+
code = re.findall(
33+
"<pre>\n?<span></span>\n?<code>(?P<code>.*?)</code>\n?</pre>",
34+
pre,
35+
re.DOTALL,
36+
)
37+
if len(code) != 1:
38+
continue
39+
40+
lines = code[0].split("\n")
41+
if not lines:
42+
continue
43+
44+
# Remove first empty code line.
45+
if len(lines) >= 1 and not lines[0]:
46+
del lines[0]
47+
# Remove last empty code line.
48+
if len(lines) >= 1 and not lines[-1]:
49+
del lines[-1]
50+
51+
for line in lines:
52+
pre_section.append(f'<span class="code-line">{line}</span>')
53+
54+
pre_section.extend(["</code>", "</pre>"])
55+
content = content.replace(pre, "\n".join(pre_section))
56+
57+
return content
58+
59+
60+
def main(input) -> None:
61+
if input._content:
62+
input._content = add_line_wrappers(input._content)
63+
else:
64+
# Exit the function, essentially passing over the (non-text) file.
65+
return
66+
67+
68+
def register():
69+
signals.content_object_init.connect(main)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import pytest
2+
from better_codeblock_line_numbering_fork import add_line_wrappers
3+
4+
5+
@pytest.mark.parametrize(
6+
"input, output",
7+
[
8+
(
9+
("<pre>\n" "<span></span>\n" "<code>\n" "echo\n" "</code>\n" "</pre>"),
10+
(
11+
"<pre>\n"
12+
"<code>\n"
13+
'<span class="code-line">echo</span>\n'
14+
"</code>\n"
15+
"</pre>"
16+
),
17+
),
18+
(
19+
("<pre>\n" "<span></span><code>\n" "echo\n" "</code>\n" "</pre>"),
20+
(
21+
"<pre>\n"
22+
"<code>\n"
23+
'<span class="code-line">echo</span>\n'
24+
"</code>\n"
25+
"</pre>"
26+
),
27+
),
28+
(
29+
("<pre><span></span><code>\n" "echo\n" "</code></pre>"),
30+
(
31+
"<pre>\n"
32+
"<code>\n"
33+
'<span class="code-line">echo</span>\n'
34+
"</code>\n"
35+
"</pre>"
36+
),
37+
),
38+
(
39+
("<pre><span></span><code>echo</code></pre>"),
40+
(
41+
"<pre>\n"
42+
"<code>\n"
43+
'<span class="code-line">echo</span>\n'
44+
"</code>\n"
45+
"</pre>"
46+
),
47+
),
48+
(
49+
("<pre><span></span><code>echo\n\necho</code></pre>"),
50+
(
51+
"<pre>\n"
52+
"<code>\n"
53+
'<span class="code-line">echo</span>\n'
54+
'<span class="code-line"></span>\n'
55+
'<span class="code-line">echo</span>\n'
56+
"</code>\n"
57+
"</pre>"
58+
),
59+
),
60+
(
61+
("<pre><span></span><code>\n\necho\n\n</code></pre>"),
62+
(
63+
"<pre>\n"
64+
"<code>\n"
65+
'<span class="code-line"></span>\n'
66+
'<span class="code-line">echo</span>\n'
67+
'<span class="code-line"></span>\n'
68+
"</code>\n"
69+
"</pre>"
70+
),
71+
),
72+
],
73+
)
74+
def test_add_line_wrappers(input, output):
75+
result = add_line_wrappers(input)
76+
assert result == output

Diff for: publishconf.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is only used if you use `make publish` or
2+
# explicitly specify it as your config file.
3+
4+
import os
5+
import sys
6+
sys.path.append(os.curdir)
7+
from pelicanconf import *
8+
9+
# If your site is available via HTTPS, make sure SITEURL begins with https://
10+
SITEURL = ''
11+
RELATIVE_URLS = False
12+
13+
FEED_ALL_ATOM = 'feeds/all.atom.xml'
14+
CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml'
15+
16+
DELETE_OUTPUT_DIRECTORY = True
17+
18+
# Following items are often useful when publishing
19+
20+
#DISQUS_SITENAME = ""
21+
#GOOGLE_ANALYTICS = ""

Diff for: requirements.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pelican[markdown]

Diff for: requirements.txt

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile requirements.in
6+
#
7+
blinker==1.7.0
8+
# via pelican
9+
docutils==0.20.1
10+
# via pelican
11+
feedgenerator==2.1.0
12+
# via pelican
13+
jinja2==3.1.2
14+
# via pelican
15+
markdown==3.5.1
16+
# via pelican
17+
markdown-it-py==3.0.0
18+
# via rich
19+
markupsafe==2.1.3
20+
# via jinja2
21+
mdurl==0.1.2
22+
# via markdown-it-py
23+
pelican[markdown]==4.8.0
24+
# via -r requirements.in
25+
pygments==2.16.1
26+
# via
27+
# pelican
28+
# rich
29+
python-dateutil==2.8.2
30+
# via pelican
31+
pytz==2023.3.post1
32+
# via
33+
# feedgenerator
34+
# pelican
35+
rich==13.6.0
36+
# via pelican
37+
six==1.16.0
38+
# via python-dateutil
39+
unidecode==1.3.7
40+
# via pelican

Diff for: requirements_dev.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-c requirements.txt
2+
pytest

Diff for: requirements_dev.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile requirements_dev.in
6+
#
7+
iniconfig==2.0.0
8+
# via pytest
9+
packaging==23.2
10+
# via pytest
11+
pluggy==1.3.0
12+
# via pytest
13+
pytest==7.4.3
14+
# via -r requirements_dev.in

0 commit comments

Comments
 (0)