feat: Update blog rendering
All checks were successful
Build Docker / BuildImage (push) Successful in 5m28s
All checks were successful
Build Docker / BuildImage (push) Successful in 5m28s
This commit is contained in:
46
blog.py
46
blog.py
@@ -4,6 +4,8 @@ from datetime import datetime
|
|||||||
import markdown
|
import markdown
|
||||||
from markdown.extensions.codehilite import CodeHiliteExtension
|
from markdown.extensions.codehilite import CodeHiliteExtension
|
||||||
from markdown.extensions.fenced_code import FencedCodeExtension
|
from markdown.extensions.fenced_code import FencedCodeExtension
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def list_blog_page_files():
|
def list_blog_page_files():
|
||||||
@@ -22,12 +24,16 @@ def render_blog_page(date,handshake_scripts=None):
|
|||||||
with open(f"data/blog/{date}.md", "r") as f:
|
with open(f"data/blog/{date}.md", "r") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
# Get the title from the file name
|
# Get the title from the file name
|
||||||
title = date.removesuffix(".md").replace("_", " ").title()
|
title = date.removesuffix(".md").replace("_", " ")
|
||||||
# Convert the md to html
|
# Convert the md to html
|
||||||
content = markdown.markdown(content, extensions=['sane_lists', 'codehilite', 'fenced_code'])
|
content = markdown.markdown(content, extensions=['sane_lists', 'codehilite', 'fenced_code'])
|
||||||
# Add target="_blank" to all links
|
# Add target="_blank" to all links
|
||||||
content = content.replace('<a href="', '<a target="_blank" href="')
|
content = content.replace('<a href="', '<a target="_blank" href="')
|
||||||
|
|
||||||
|
content = content.replace("<h4", "<h4 style='margin-bottom:0px;'")
|
||||||
|
|
||||||
|
content = fix_numbered_lists(content)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"blog/template.html",
|
"blog/template.html",
|
||||||
title=title,
|
title=title,
|
||||||
@@ -36,7 +42,43 @@ def render_blog_page(date,handshake_scripts=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def fix_numbered_lists(html):
|
||||||
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
|
||||||
|
# Find the <p> tag containing numbered steps
|
||||||
|
paragraphs = soup.find_all('p')
|
||||||
|
for p in paragraphs:
|
||||||
|
content = p.decode_contents()
|
||||||
|
|
||||||
|
# Check for likely numbered step structure
|
||||||
|
if re.search(r'1\.\s', content):
|
||||||
|
# Split into pre-list and numbered steps
|
||||||
|
# Match: <br>, optional whitespace, then a number and dot
|
||||||
|
parts = re.split(r'(?:<br\s*/?>)?\s*(\d+)\.\s', content)
|
||||||
|
|
||||||
|
# Result: [pre-text, '1', step1, '2', step2, ..., '10', step10]
|
||||||
|
pre_text = parts[0].strip()
|
||||||
|
steps = parts[1:]
|
||||||
|
|
||||||
|
# Assemble the ordered list
|
||||||
|
ol_items = []
|
||||||
|
for i in range(0, len(steps), 2):
|
||||||
|
if i+1 < len(steps):
|
||||||
|
step_html = steps[i+1].strip()
|
||||||
|
ol_items.append(f"<li style='list-style: auto;'>{step_html}</li>")
|
||||||
|
|
||||||
|
# Build the final list HTML
|
||||||
|
ol_html = "<ol>\n" + "\n".join(ol_items) + "\n</ol>"
|
||||||
|
|
||||||
|
# Rebuild paragraph with optional pre-text
|
||||||
|
new_html = f"{pre_text}<br />\n{ol_html}" if pre_text else ol_html
|
||||||
|
|
||||||
|
# Replace old <p> with parsed version
|
||||||
|
new_fragment = BeautifulSoup(new_html, 'html.parser')
|
||||||
|
p.replace_with(new_fragment)
|
||||||
|
break # Only process the first matching <p>
|
||||||
|
|
||||||
|
return str(soup)
|
||||||
|
|
||||||
|
|
||||||
def render_blog_home(handshake_scripts=None):
|
def render_blog_home(handshake_scripts=None):
|
||||||
|
|||||||
BIN
data/resume.pdf
BIN
data/resume.pdf
Binary file not shown.
@@ -13,4 +13,5 @@ solana
|
|||||||
solders
|
solders
|
||||||
weasyprint
|
weasyprint
|
||||||
markdown
|
markdown
|
||||||
pygments
|
pygments
|
||||||
|
beautifulsoup4
|
||||||
@@ -589,9 +589,9 @@ def index():
|
|||||||
print("Error getting git data")
|
print("Error getting git data")
|
||||||
|
|
||||||
# Get only repo names for the newest updates
|
# Get only repo names for the newest updates
|
||||||
if projects == [] or projectsUpdated < datetime.datetime.now() - datetime.timedelta(
|
if projects == [] or projectsUpdated < (datetime.datetime.now() - datetime.timedelta(
|
||||||
hours=2
|
hours=2
|
||||||
):
|
)).timestamp():
|
||||||
projectsreq = requests.get(
|
projectsreq = requests.get(
|
||||||
"https://git.woodburn.au/api/v1/users/nathanwoodburn/repos"
|
"https://git.woodburn.au/api/v1/users/nathanwoodburn/repos"
|
||||||
)
|
)
|
||||||
@@ -625,7 +625,7 @@ def index():
|
|||||||
projects.append(projectsList[projectNum])
|
projects.append(projectsList[projectNum])
|
||||||
projectNames.append(projectsList[projectNum]["name"])
|
projectNames.append(projectsList[projectNum]["name"])
|
||||||
projectNum += 1
|
projectNum += 1
|
||||||
projectsUpdated = datetime.datetime.now()
|
projectsUpdated = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
custom = ""
|
custom = ""
|
||||||
# Check for downtime
|
# Check for downtime
|
||||||
|
|||||||
@@ -130,9 +130,9 @@
|
|||||||
<h4 class="r-heading2">Home Educated</h4>
|
<h4 class="r-heading2">Home Educated</h4>
|
||||||
<h6 class="r-heading3">Self-Directed Learning</h6>
|
<h6 class="r-heading3">Self-Directed Learning</h6>
|
||||||
<ul class="r-body">
|
<ul class="r-body">
|
||||||
|
<li>Cultivated time management, self-discipline, and critical thinking skills crucial for success in tech and cybersecurity.</li>
|
||||||
<li>Developed a strong passion for technology, programming, and system administration through independent exploration.</li>
|
<li>Developed a strong passion for technology, programming, and system administration through independent exploration.</li>
|
||||||
<li>Built custom applications, managed servers, and solved technical challenges in a flexible learning environment.</li>
|
<li>Built custom applications, managed servers, and solved technical challenges in a flexible learning environment.</li>
|
||||||
<li>Cultivated time management, self-discipline, and critical thinking skills crucial for success in tech and cybersecurity.</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user