Skip to content

Commit

Permalink
Update .vscode settings to generate blog html on save AND fix borked …
Browse files Browse the repository at this point in the history
…CSS 😱 (#34)

* run html generation on file save

* update script to update for single file

* fix borked css
  • Loading branch information
hannahilea authored Oct 9, 2024
1 parent b027eb6 commit a477184
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"liveServer.settings.port": 5502,
"emeraldwalk.runonsave": {
"commands": [
// {
// "match": ".*",
// "isAsync": true,
// "cmd": "echo 'I run for all files.'"
// },
{
"match": "blog/.*/src.md$",
"cmd": "echo 'I am a .md file ${file}.'; julia build-blogs/run.jl ${file}"
},
{
"match": "blog/__template/.*$",
"cmd": "echo 'A __template file has been saved ${file}.'; julia build-blogs/run.jl"
},
]
}
}
20 changes: 0 additions & 20 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ body {
font-weight: bolder;
}

.blog {
.blog {
line-height: 150%;
}
Expand All @@ -94,7 +93,6 @@ h2, h3 {
margin-bottom: 3px;
}

.blog > h1 {
.blog > h1 {
line-height: 1.2em;
}
Expand All @@ -103,11 +101,6 @@ a.footnote-ref {
text-decoration: none;
}

a > sup {
a.footnote-ref {
text-decoration: none;
}

a > sup {
vertical-align: baseline;
position: relative;
Expand All @@ -121,17 +114,6 @@ a.footnote-back {
text-underline-offset: .1em;
}

.footnotes > ol {
font-size: smaller;
text-decoration: underline;
text-underline-offset: .1em;
}

a.footnote-back {
text-decoration: underline;
text-underline-offset: .1em;
}

.footnotes > ol {
font-size: smaller;
}
Expand Down Expand Up @@ -285,7 +267,6 @@ img.home-img {
margin-bottom: 1.6em;
}

pre {
pre {
background: #eeeff1;
border: 2px solid #ddd;
Expand All @@ -312,7 +293,6 @@ pre {
font-family: "Jura Bold";
}

.blog img {
.blog img {
display: block;
margin-left: auto;
Expand Down
8 changes: 4 additions & 4 deletions blog/driven-developments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,24 @@ <h4 id="service-driven-development-srvdd">Service-driven development
coming!</p>
<h2 id="faqs">FAQs</h2>
<p><strong>Q:</strong> <em>Ooh, I have a great idea for a DD! What
now?</em></br> <strong>A:</strong> Bring it to life by using it! And/or
now?</em><br> <strong>A:</strong> Bring it to life by using it! And/or
write it up in a blog post of your own (and share the link with me,
please)!</p>
<p><strong>Q:</strong> <em>Okay, but I have a job to do. What about,
like, paycheck-driven development? Or healthcare-driven
development?</em></br> <strong>A:</strong> Those are great DDs if they
development?</em><br> <strong>A:</strong> Those are great DDs if they
work for you! Personally I find that I usually need a more specific
technique to drive my efforts on an minute-by-minute basis, but it’s all
context dependent.</p>
<p><strong>Q:</strong> <em>It seems like an awful lot of these overlap,
or maybe are even exactly the same, with a different name. Or like you’d
use multiple at once.</em></br> <strong>A:</strong> That isn’t a
use multiple at once.</em><br> <strong>A:</strong> That isn’t a
question, but you’re totally right. For example, I am often powered by
both DDD and TDD, with an occasional background smattering of SDD! I
contain multitudes. You probably do too.</p>
<p><strong>Q:</strong> <em>I have a really cool idea for one:
string-theory driven development! But the acronym is…not ideal. What
gives?</em></br> <strong>A:</strong> That’s on you, friend. I have
gives?</em><br> <strong>A:</strong> That’s on you, friend. I have
confidence that you can use a trusty thesaurus to find an alternate
name. Or don’t, and own it!</p>
<section id="footnotes" class="footnotes footnotes-end-of-document"
Expand Down
60 changes: 41 additions & 19 deletions build-blogs/run.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Pkg
using Pkg
Pkg.activate(@__DIR__)
using pandoc_jll

blog_dir = joinpath( @__DIR__, "..", "blog")
blog_dir = joinpath(@__DIR__, "..", "blog")
blog_template = joinpath(blog_dir, "__template", "index.html.template")

function convert_to_html(file, outfile; template=blog_template, overwrite_existing=false)
function convert_to_html(file,
outfile;
template=blog_template,
overwrite_existing=false,)
if !overwrite_existing && isfile(outfile)
@warn "Output file already exists; not overwriting: $outfile"
return nothing
Expand All @@ -32,19 +35,22 @@ function tweak_html!!(text)
fnote_heading = """\n<h3 id="footnotes-title">Footnotes</h3>"""
text = replace(text, fnote_predecessor => fnote_predecessor * fnote_heading)

# the formatter will yell otherwise...
text = replace(text, "</br>" => "<br>")

# Strip out image captions
# This is...a truly hacky approach. ¯\_(ツ)_/¯
in_caption = false
str_start = "<figcaption aria-hidden=\"true\">"
str_start = "<figcaption aria-hidden=\"true\">"
str_stop = "</figcaption>"
lines = map(split(text, "\n")) do line
lines = map(split(text, "\n")) do line
# Making some real assumptions that there'll never be multiple of these in one line
# ...but if there are, we'll see it in git, so it'll still be okay

# Single line contains both start and stop
if !in_caption && contains(line, str_start) && contains(line, str_stop)
line = split(line, str_start; limit=2)[1]
return split(line, str_stop; limit=2)[end]
line = split(line, str_start; limit=2)[1]
return split(line, str_stop; limit=2)[end]
end

# Multiline caption
Expand All @@ -54,31 +60,47 @@ function tweak_html!!(text)
end
in_caption && return missing
if contains(line, str_start)
in_caption = true
in_caption = true
line = split(line, str_start; limit=2)[1]
end
return line
end
return line
end
lines = filter(!ismissing, lines)
return join(lines, "\n")
end

function generate_blog_html(md_file; overwrite_existing=true)
if !isfile(md_file)
@warn "Expected blog source file not found: `$(md_file)`; skipping"
return nothing
end

@info "Converting $(basename(dirname(md_file)))..."
html_outfile = replace(md_file, "src.md" => "index.html")
convert_to_html(md_file, html_outfile; overwrite_existing)
return nothing
end

function generate_all_blogposts(; overwrite_existing=true)
for dir in readdir(blog_dir; join=true)
isfile(dir) && continue
isequal(joinpath(blog_dir, "__template"), dir) && continue
# contains(dir, "list") || continue

md_file = joinpath(dir, "src.md")
if !isfile(md_file)
@warn "Expected blog source file not found: `$(md_file)`; skipping"
continue
end
@info "Converting $(basename(dirname(md_file)))..."
html_outfile = joinpath(dir, "index.html")
convert_to_html(md_file, html_outfile; overwrite_existing)
generate_blog_html(md_file; overwrite_existing)
end
return nothing
end

generate_all_blogposts(; overwrite_existing=true)
# Run from commandline?
if abspath(PROGRAM_FILE) == @__FILE__
if isempty(ARGS)
generate_all_blogposts(; overwrite_existing=true)
elseif isfile(ARGS[1])
generate_blog_html(ARGS[1]; overwrite_existing=true)
else
@warn "Unknown argument $(ARGS[1])"
end
return nothing
end

0 comments on commit a477184

Please sign in to comment.