diff --git a/.gitignore b/.gitignore index 99fd0c3..8476047 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store img/.DS_Store /McGill/ +Manifest.toml diff --git a/add_stuff.jl b/add_stuff.jl index 75b9718..6152ef7 100644 --- a/add_stuff.jl +++ b/add_stuff.jl @@ -4,7 +4,6 @@ Pkg.add("Dates") using Dates const NEW_PROJ_COMMENT = "" -const NEW_BLOG_COMMENT = "" # Some quick and brittle Julia utilities for adding new projects # Doesn't handle nested, only does new js projects @@ -53,7 +52,6 @@ function new_blog_post() dir = joinpath("blog", dir_name) date = today() - date_pretty = Dates.format(today(), dateformat"d u yyyy") @info "Creating new blog directory" blog_title dir_name cp(joinpath("blog", "__template"), dir) @@ -75,19 +73,7 @@ function new_blog_post() end mkdir(joinpath(dir, "assets")) - @info "Adding new project to blog index" - let - index_path = joinpath("blog", "index.html") - new_blob = """\n
  • $(date_pretty) $(blog_title)
  • """ - str = read(index_path, String) - i = findfirst(NEW_BLOG_COMMENT, str) - isnothing(i) && - throw(ArgumentError("Oh no, $(NEW_BLOG_COMMENT) not found in $(index_path)")) - str = str[1:last(i)] * new_blob * str[(last(i) + 1):end] - write(index_path, str) - end - - @info "Adding new project to blog index" + @info "Adding new project to rss feed" let new_blob = read(joinpath("blog", "__template", ".rss_blob.xml"), String) pub_date = Dates.format(now(Dates.UTC), dateformat"e, d U yyyy HH:MM:SS ") * "GMT" diff --git a/blog/__template/blog.html.template b/blog/__template/blog.html.template new file mode 100644 index 0000000..2f8624a --- /dev/null +++ b/blog/__template/blog.html.template @@ -0,0 +1,30 @@ + + + + + + + $if(rawtitle)$$rawtitle$$else$$title$$endif$ + + $header$ + + + +
    + +

    $title$

    +$body$ +
    + +
    + + diff --git a/blog/__template/index.html.template b/blog/__template/index.html.template index 2f8624a..967c5fe 100644 --- a/blog/__template/index.html.template +++ b/blog/__template/index.html.template @@ -1,30 +1,39 @@ - + + - - - - - $if(rawtitle)$$rawtitle$$else$$title$$endif$ - - $header$ - - -
    - -

    $title$

    -$body$ -
    + + + + + + + + @hannahilea: blog + + + +
    + +

    Blog

    + +
      -
    • created: $created$
    • -
    • last updated: $updated$
    • -
    • tags: $for(tags)$$tags$$sep$, $endfor$
    • +
    - + +
    + + + Subscribe to @hannahilea RSS feed +
    +
    + + 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 @@ - + + + + + + + + + + @hannahilea: blog + - - - - - - - - @hannahilea: 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