Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions scripts/build_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,23 @@ def mark_drop_cap(paragraph):
raise ValueError("editorial opening paragraph has no visible letter")


def mark_inline_phi(body):
"""Identify backticked Phi in prose without styling paths or labels."""
def mark_code(match):
code = html_module.unescape(match.group(1)).strip()
if not re.fullmatch(r"[a-z]+(?: [a-z]+)*[.]?", code):
return match.group(0)
words = code.removesuffix(".").split()
if not words or any(word not in ALL_WORDS for word in words):
return match.group(0)
return f'<code class="phi-inline">{match.group(1)}</code>'

def mark_paragraph(match):
return re.sub(r"<code>([^<]+)</code>", mark_code, match.group(0))

return re.sub(r"<p(?: [^>]*)?>.*?</p>", mark_paragraph, body, flags=re.S)


def apply_book_editorial(body, source, repo_path, treatment):
"""Generate the chapter furniture named in site/editorial.json."""
chapter_match = re.match(r"book/([0-9]+)_", repo_path)
Expand All @@ -612,6 +629,7 @@ def apply_book_editorial(body, source, repo_path, treatment):
+ f'<p class="chapter-lede">{marked_lede}</p>'
+ body[lede_match.end():]
)
body = mark_inline_phi(body)

paragraph_matches = list(re.finditer(r"<p>.*?</p>", body, flags=re.S))
insertions = {}
Expand All @@ -630,10 +648,10 @@ def apply_book_editorial(body, source, repo_path, treatment):
f"editorial pull quote did not survive rendering in {repo_path}: {quote!r}"
)
aside = (
'\n<aside class="chapter-pullquote" aria-hidden="true">'
f"<p>{escaped_quote}</p></aside>"
'<aside class="chapter-pullquote" aria-hidden="true">'
f"<p>{escaped_quote}</p></aside>\n"
)
insertions.setdefault(containing[0].end(), []).append(aside)
insertions.setdefault(containing[0].start(), []).append(aside)
for position in sorted(insertions, reverse=True):
body = body[:position] + "".join(insertions[position]) + body[position:]
return body
Expand Down
32 changes: 22 additions & 10 deletions site/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
--sage: #7a8b6f;
--gold: #b0975b;
--hairline: #ddd6c6;
--phi-inline-bg: #e1e6db;
--serif: "Fraunces", georgia, serif;
--sans: "Source Sans 3", system-ui, sans-serif;
--ipa: "Gentium Plus", "Charis SIL", serif;
Expand Down Expand Up @@ -404,26 +405,36 @@ footer a { color: var(--sage); }
font-family: var(--serif);
font-size: 1.3rem;
line-height: 1.42;
margin: .55rem -12.5rem 1.5rem 2rem;
margin: .55rem 0 1.2rem 1.6rem;
padding: .8rem 0;
width: 10.5rem;
width: 14rem;
}
.book-editorial .chapter-pullquote p { margin: 0; }
.book-editorial .chapnav { clear: both; }

@media (max-width: 62rem) {
.book-editorial main { max-width: 38rem; }
.book-editorial .chapter-pullquote {
float: none;
margin: 1.8rem 0;
width: auto;
}
.book-editorial code.phi-inline {
-webkit-box-decoration-break: clone;
background: var(--phi-inline-bg);
border-radius: 5px;
box-decoration-break: clone;
color: var(--ink);
font-family: ui-monospace, "SFMono-Regular", consolas, monospace;
font-size: 1em;
letter-spacing: 0;
line-height: 1;
padding: .12em .34em .16em;
white-space: normal;
}
.book-editorial p code:not(.phi-inline) { overflow-wrap: anywhere; }

@media (max-width: 560px) {
.book-editorial h1 { font-size: 2.15rem; }
.book-editorial .chapter-lede { font-size: 1.08rem; }
.book-editorial .drop-cap { font-size: 3.55rem; }
.book-editorial .chapter-pullquote {
float: none;
margin: 1.6rem 0 1rem;
width: auto;
}
}

@media print {
Expand Down Expand Up @@ -483,6 +494,7 @@ html[data-theme="dark"] {
--sage: #a3b795;
--gold: #c9b078;
--hairline: #3a443a;
--phi-inline-bg: #3a443a;
}
html[data-theme="dark"] body { background: var(--paper); color: var(--ink); }

Expand Down
Loading