+
+
diff --git a/blog/index.html b/blog/index.html
index d7993a1..4b6941c 100644
--- a/blog/index.html
+++ b/blog/index.html
@@ -1,58 +1,54 @@
-
+
+
+
+
+
+
Blog
-
-
-
-
Blog
+
-
-
-
-
-
-
+
diff --git a/build-blogs/Manifest.toml b/build-blogs/Manifest.toml
deleted file mode 100644
index 46834a3..0000000
--- a/build-blogs/Manifest.toml
+++ /dev/null
@@ -1,45 +0,0 @@
-# This file is machine-generated - editing it directly is not advised
-
-julia_version = "1.10.2"
-manifest_format = "2.0"
-project_hash = "c3d3e555ccf23b28f8fc5ea9b97581f769c31f67"
-
-[[deps.Artifacts]]
-uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
-
-[[deps.Dates]]
-deps = ["Printf"]
-uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
-
-[[deps.JLLWrappers]]
-deps = ["Artifacts", "Preferences"]
-git-tree-sha1 = "f389674c99bfcde17dc57454011aa44d5a260a40"
-uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
-version = "1.6.0"
-
-[[deps.Libdl]]
-uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
-
-[[deps.Preferences]]
-deps = ["TOML"]
-git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6"
-uuid = "21216c6a-2e73-6563-6e65-726566657250"
-version = "1.4.3"
-
-[[deps.Printf]]
-deps = ["Unicode"]
-uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
-
-[[deps.TOML]]
-deps = ["Dates"]
-uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
-version = "1.0.3"
-
-[[deps.Unicode]]
-uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
-
-[[deps.pandoc_jll]]
-deps = ["Artifacts", "JLLWrappers", "Libdl"]
-git-tree-sha1 = "d80b045127d084d60c5bc827210a7d9a5af14231"
-uuid = "c5432543-76ad-5c9d-82bf-db097047a5e2"
-version = "3.4.0+0"
diff --git a/build-blogs/Project.toml b/build-blogs/Project.toml
index 90ef5dd..6e10aec 100644
--- a/build-blogs/Project.toml
+++ b/build-blogs/Project.toml
@@ -1,2 +1,3 @@
[deps]
+Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
pandoc_jll = "c5432543-76ad-5c9d-82bf-db097047a5e2"
diff --git a/build-blogs/run.jl b/build-blogs/run.jl
index 899e541..2c09e33 100644
--- a/build-blogs/run.jl
+++ b/build-blogs/run.jl
@@ -1,14 +1,13 @@
using Pkg
Pkg.activate(@__DIR__)
using pandoc_jll
+using Dates
blog_dir = joinpath(@__DIR__, "..", "blog")
-blog_template = joinpath(blog_dir, "__template", "index.html.template")
+blog_template = joinpath(blog_dir, "__template", "blog.html.template")
+blog_index_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
@@ -100,12 +99,61 @@ function generate_all_blogposts(; overwrite_existing=true)
return nothing
end
+function get_blog_metadata(md_file)
+ delimiter = "ddddd"
+ template_str = "data:text/plain;utf8,\$title\$$delimiter\$created\$$delimiter\$for(tags)\$\$tags\$\$sep\$,\$endfor\$"
+ str = read(pipeline(`$(pandoc_jll.pandoc()) --template $(template_str) $(md_file)`), String)
+ str = replace(str, r".html$" => "", "\n" => " ")
+ (title, date_str, tags) = split(str, delimiter; limit=3)
+ return (; md_file, date_str, title, tags)
+end
+
+function generate_blog_index(; overwrite_existing=false, template=blog_index_template)
+ outfile = joinpath(blog_dir, "index.html")
+ if !overwrite_existing && isfile(outfile)
+ @warn "Output file already exists; not overwriting: $outfile"
+ return nothing
+ end
+
+ @info "Generating blog index..."
+ metadata = []
+ for dir in readdir(blog_dir; join=true)
+ isfile(dir) && continue
+ isequal(joinpath(blog_dir, "__template"), dir) && continue
+
+ md_file = joinpath(dir, "src.md")
+ m = get_blog_metadata(md_file)
+
+ push!(metadata, (; url="./" * basename(dir), m...))
+ end
+ metadata = sort(metadata; by=(m) -> m.date_str, rev=true)
+
+ blog_strs = map(metadata) do m
+ date_pretty = Dates.format(Date(m.date_str), dateformat"d u yyyy")
+ return """
$(date_pretty) \n$(m.title)\n\n"""
+ end
+
+ str = read(template, String)
+ str = replace(str, "" => join(blog_strs, "\n"))
+ write(outfile, str)
+
+ try
+ run(`prettier $(outfile) --write --print-width 360`)
+ catch
+ @warn "Prettier not installed OR current html errors"
+ end
+
+ return nothing
+end
+
# Run from commandline?
if abspath(PROGRAM_FILE) == @__FILE__
if isempty(ARGS)
generate_all_blogposts(; overwrite_existing=true)
+ generate_blog_index(; overwrite_existing=true)
elseif isfile(ARGS[1])
generate_blog_html(ARGS[1]; overwrite_existing=true)
+ generate_blog_index(; overwrite_existing=true)
else
@warn "Unknown argument $(ARGS[1])"
end