diff --git a/README.md b/README.md index 08860da..6c79587 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,6 @@ Personal website; can be viewed at [hannahilea.com](https://hannahilea.com). - [ ] Figure out blog situation - [ ] Set up rss feed - [ ] Remove "under construction" flags + +### Use template to add new content +Run `julia --startup-file=no add_stuff.jl ` with arg `blog` or `p5`. diff --git a/add_stuff.jl b/add_stuff.jl new file mode 100644 index 0000000..c069394 --- /dev/null +++ b/add_stuff.jl @@ -0,0 +1,101 @@ +using Pkg +Pkg.activate(; temp=true) +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 +# Will fail if dir already exists +# Future: functions to add different types of projects +# Future: validate git state isn't dirty before starting +function new_p5_project() + project_name = lstrip(rstrip(Base.prompt("Enter project name"))) + dir_name = let + default = replace(lowercase(project_name), " " => "-") + lstrip(rstrip(Base.prompt("Enter project url name"; default))) + end + dir = joinpath("projects", dir_name) + + @info "Creating new project directory" project_name dir_name + cp(joinpath("projects", "__template"), dir) + for file in readdir(dir; join=true) + @info "Updating $file..." + str = read(file, String) + str = replace(str, "{{ PROJECT_NAME }}" => project_name) + str = replace(str, "{{ DIR_NAME }}" => dir_name) + write(file, str) + end + + @info "Adding new project to project index" + let + index_path = joinpath("projects", "index.html") + new_blob = """\n
  • \n $(project_name)\n \n

    TODO-description

    \n
  • """ + str = read(index_path, String) + i = findfirst(NEW_PROJ_COMMENT, str) + isnothing(i) && throw(ArgumentError("Oh no, $(NEW_PROJ_COMMENT) not found in $(index_path)")) + str = str[1:last(i)] * new_blob * str[last(i)+1:end] + write(index_path, str) + end + @info "Do ctrl+f TODO to find regions to update for newly added project!" +end + +function new_blog_post() + blog_title = lstrip(rstrip(Base.prompt("Enter blog post title"))) + + dir_name = let + default = replace(lowercase(blog_title), " " => "-") + lstrip(rstrip(Base.prompt("Enter blog url name"; default))) + end + + 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) + for file in readdir(dir; join=true) + @info "Updating $file..." + str = read(file, String) + str = replace(str, "{{ BLOG_TITLE }}" => blog_title) + str = replace(str, "{{ DATE }}" => date) + str = replace(str, "{{ BLOG_DIR }}" => dir_name) + write(file, str) + end + + @info "Adding new project to blog index" + let + index_path = joinpath("blog", "index.html") + new_blob = """\n
  • $(date_pretty): $(blog_title)\n

    In which TODO.

    \n
  • """ + 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 + + #TODO-future: also add to rss feed + @info "Do ctrl+f TODO to find regions to update for newly added project!" +end + +function run_wizard(::Missing) + choice = lstrip(rstrip(Base.prompt("""Which type of content do you want to add? + Choices: p5, blog"""))) + return run_wizard(choice) +end + +function run_wizard(choice) + choice = rstrip(lstrip(lowercase(choice))) + choice == "blog" && return new_blog_post() + choice == "p5" && return new_p5_project() + println("Unsupported selection `$choice`") + return run_wizard(missing) +end + +# CLI entrypoint +if abspath(PROGRAM_FILE) == @__FILE__ + run_wizard(isempty(ARGS) ? missing : first(ARGS)) +end + diff --git a/blog/__template/index.html b/blog/__template/index.html new file mode 100644 index 0000000..695d618 --- /dev/null +++ b/blog/__template/index.html @@ -0,0 +1,25 @@ + + + + + Blog: {{ BLOG_TITLE }} + + + + + + +
    +

    @hannahilea > Blog > {{ BLOG_DIR }} +

    +
    + +
    + +
    + + + + + + diff --git a/blog/__template/src.md b/blog/__template/src.md new file mode 100644 index 0000000..488c08e --- /dev/null +++ b/blog/__template/src.md @@ -0,0 +1,8 @@ +### {{ BLOG_TITLE }} + +Contents! They will go here. + +--- +- created at: {{ DATE }} +- last updated: {{ DATE }} +- tags: diff --git a/blog/hello-world/index.html b/blog/hello-world/index.html new file mode 100644 index 0000000..b567d29 --- /dev/null +++ b/blog/hello-world/index.html @@ -0,0 +1,25 @@ + + + + + Blog: Hello world + + + + + + +
    +

    @hannahilea > Blog > hello-world +

    +
    + +
    + +
    + + + + + + diff --git a/blog/post0.md b/blog/hello-world/src.md similarity index 84% rename from blog/post0.md rename to blog/hello-world/src.md index c291eb5..08b5f1d 100644 --- a/blog/post0.md +++ b/blog/hello-world/src.md @@ -6,5 +6,3 @@ Thanks to [Teresa Ibarra](https://teresaibarra.com), whose site (and assistance! --- - created at: 2/23/24 - last updated: 3/1/24 - diff --git a/blog.html b/blog/index.html similarity index 57% rename from blog.html rename to blog/index.html index f6b97d7..bf23461 100644 --- a/blog.html +++ b/blog/index.html @@ -7,25 +7,25 @@ - - + + @hannahilea: blog - +
    @@ -33,16 +33,21 @@

    @hannahilea's blog

    - - +
    +
      + +
    • 23 Feb 2024: Hello world +

      In which I create a boring initial post as a placeholder while setting up this website.

      +
    • +
    +
    diff --git a/index.html b/index.html index 538ac23..db0ad48 100755 --- a/index.html +++ b/index.html @@ -25,8 +25,8 @@
    DSP ENGINEER | MAKER
    @@ -34,8 +34,8 @@
    DSP ENGINEER | MAKER
    diff --git a/projects/__template/index.html b/projects/__template/index.html index ed9b073..80bdacd 100644 --- a/projects/__template/index.html +++ b/projects/__template/index.html @@ -24,7 +24,7 @@
    -

    @hannahilea > projects > Sketch: {{ PROJECT_NAME }} +

    @hannahilea > projects > Sketch: {{ PROJECT_NAME }}

    diff --git a/projects.html b/projects/index.html similarity index 89% rename from projects.html rename to projects/index.html index 63d420c..b933f3e 100644 --- a/projects.html +++ b/projects/index.html @@ -18,12 +18,12 @@
    -

    @hannahilea's projects

    +

    @hannahilea's projects

    @@ -53,7 +53,7 @@

    @hannahilea's projects


    - + One-off creative coding projects, often small and interactive.