Skip to content

Instantly share code, notes, and snippets.

@waylan
waylan / static_site_generator_proposal.md
Created April 11, 2024 19:03
This is a brief summary of my ideas for implementing a static site generator.

My Static Site Generator Proposal

© Waylan Limberg 2024-04-11

Over the course of six years (2015-2021) I contributed regularly to MkDocs (253 commits according to GitHub's stats). In that time I learned a lot and formed some opinions about how I would like a static site generator to work. This is a brief summary of my ideas. Some of these ideas follow MkDocs closely and others are so different that I would not expect to ever find them in a future version of MkDocs; perhaps in a competing project instead. And these ideas only exist as a vague overview; the technical aspects of them have not been fleshed out. For example, my ideas make multiple references to a configuration; however, I have no idea what format that configuration should take and how the various options should be defined.

For the most part, I was happy with how we got MkDocs' page collection process working (stepping through a file structure collecting text doc

@waylan
waylan / bootstrap_alert.py
Last active March 2, 2023 14:26
A Markdown extension which adds support for bootstrap alerts and (simple) carousels using pymdownx blocks v9.10b5.
from pymdownx.blocks import BlocksExtension
from pymdownx.blocks.block import Block, type_html_attribute_dict, type_html_identifier, type_string_in, \
type_boolean, type_string, , type_multi
import xml.etree.ElementTree as etree
import uuid
class BsAlertBlock(Block):
NAME = 'alert'
ARGUMENT = None
import icalendar
def rename_events(infile, outfile, names=None):
'''
Given a path to a ics file, rename each event and write to outfile.
names should be a list of strings where each item is the new name
to assign to each event in the ics file. If an insuffient number
of names are provided, then an error will occur.
@waylan
waylan / print_label.py
Created October 19, 2021 12:56
Print labels directly to Brother QL label printer using brother_ql lib.
from PIL import Image, ImageDraw, ImageFont
from brother_ql.devicedependent import label_type_specs
from brother_ql import BrotherQLRaster, create_label
from brother_ql.backends.helpers import send
PRINTER = {
'model': 'QL-800',
'address': 'usb://0x04f9:0x209b'
}
@waylan
waylan / text2img.py
Last active September 17, 2021 13:22
Create an image of text, which is centered both ways. Useful for creating a label.
from PIL import Image, ImageDraw, ImageFont
def create_image(text, size, fp, format=None):
img = Image.new('L', size, 'white')
draw = ImageDraw.Draw(img)
# Find largest font size which fits within image size
fontsize = 20
margin = 10
@waylan
waylan / peewee_monthfield.py
Created September 10, 2021 18:53
A MonthField for the peewee ORM. Inspired by https://github.com/clearspark/django-monthfield.
from peewee import _BaseFormattedField, format_date_time, _date_part
import datetime
class MonthField(_BaseFormattedField):
field_type = 'DATE'
formats = [
'%Y-%m',
'%Y-%m-%d',
'%Y-%m-%d %H:%M:%S',
import markdown
import re
import yaml
from yaml import SafeLoader
from wp2pdf import html2pdf
BLOCK_RE = re.compile(r'^-{3}[ \t]*\n(.*?\n)(?:\.{3}|-{3})[ \t]*\n', re.UNICODE|re.DOTALL)
@waylan
waylan / wp2pdf.py
Last active June 30, 2021 17:54
An HTML to PDF script using Weasyprint.
from weasyprint import HTML, CSS
HTML_TEMPLATE = """
<html>
<head>
</head>
<body>
{body}
</body>
</html>
from weasyprint import HTML
CONTENT = """
<html>
<head>
<style>
h1 {
padding: .5em 0;
background-color: lightskyblue;
}
@waylan
waylan / textfield.py
Last active January 11, 2024 19:16
A PDF fillable textfield which flows with text on a page using Reportlab.
from reportlab.platypus import SimpleDocTemplate, Flowable, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
style = getSampleStyleSheet()['BodyText']
class TextField(Flowable):
def __init__(self, **options):
Flowable.__init__(self)