From b6ac06ecfdec390d6ab0092bc5c3650ec748b56f Mon Sep 17 00:00:00 2001 From: Lukas Vacula Date: Thu, 2 Jan 2025 11:12:49 -0500 Subject: [PATCH] find-post script --- content/posts/2023/06/_index.md | 2 +- content/posts/2023/07/_index.md | 2 +- content/posts/2023/08/_index.md | 2 +- content/posts/2023/09/_index.md | 2 +- content/posts/2023/10/_index.md | 2 +- content/posts/2023/11/_index.md | 2 +- content/posts/2023/12/_index.md | 2 +- content/posts/2023/_index.md | 2 +- content/posts/2024/01/_index.md | 2 +- content/posts/2024/02/_index.md | 2 +- content/posts/2024/03/_index.md | 2 +- content/posts/2024/04/_index.md | 2 +- content/posts/2024/09/_index.md | 2 +- content/posts/2024/11/_index.md | 2 +- content/posts/2024/_index.md | 2 +- content/posts/typography.md | 9 -------- find-post.sh | 34 ++++++++++++++++++++++++++++++ newpost.sh => new-post.sh | 31 +++++++++++++++++++++++++-- quick_config.sh => quick-config.sh | 0 19 files changed, 78 insertions(+), 26 deletions(-) delete mode 100644 content/posts/typography.md create mode 100755 find-post.sh rename newpost.sh => new-post.sh (81%) rename quick_config.sh => quick-config.sh (100%) diff --git a/content/posts/2023/06/_index.md b/content/posts/2023/06/_index.md index 3fbf406..569bde4 100644 --- a/content/posts/2023/06/_index.md +++ b/content/posts/2023/06/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-06" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/07/_index.md b/content/posts/2023/07/_index.md index 3fbf406..2c0acd3 100644 --- a/content/posts/2023/07/_index.md +++ b/content/posts/2023/07/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-07" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/08/_index.md b/content/posts/2023/08/_index.md index 3fbf406..67a2ddb 100644 --- a/content/posts/2023/08/_index.md +++ b/content/posts/2023/08/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-08" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/09/_index.md b/content/posts/2023/09/_index.md index 3fbf406..8d75bda 100644 --- a/content/posts/2023/09/_index.md +++ b/content/posts/2023/09/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-09" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/10/_index.md b/content/posts/2023/10/_index.md index 3fbf406..fd3be2a 100644 --- a/content/posts/2023/10/_index.md +++ b/content/posts/2023/10/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-10" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/11/_index.md b/content/posts/2023/11/_index.md index 3fbf406..9bf860f 100644 --- a/content/posts/2023/11/_index.md +++ b/content/posts/2023/11/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-11" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/12/_index.md b/content/posts/2023/12/_index.md index 3fbf406..2065b7b 100644 --- a/content/posts/2023/12/_index.md +++ b/content/posts/2023/12/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023-12" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2023/_index.md b/content/posts/2023/_index.md index 3fbf406..4bca60d 100644 --- a/content/posts/2023/_index.md +++ b/content/posts/2023/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2023" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/01/_index.md b/content/posts/2024/01/_index.md index 3fbf406..4b3aaeb 100644 --- a/content/posts/2024/01/_index.md +++ b/content/posts/2024/01/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024-01" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/02/_index.md b/content/posts/2024/02/_index.md index 3fbf406..eb8b1a0 100644 --- a/content/posts/2024/02/_index.md +++ b/content/posts/2024/02/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024-02" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/03/_index.md b/content/posts/2024/03/_index.md index 3fbf406..a5038c6 100644 --- a/content/posts/2024/03/_index.md +++ b/content/posts/2024/03/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024-03" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/04/_index.md b/content/posts/2024/04/_index.md index 3fbf406..f004fcd 100644 --- a/content/posts/2024/04/_index.md +++ b/content/posts/2024/04/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024-04" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/09/_index.md b/content/posts/2024/09/_index.md index 3fbf406..09ca487 100644 --- a/content/posts/2024/09/_index.md +++ b/content/posts/2024/09/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024-09" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/11/_index.md b/content/posts/2024/11/_index.md index 3fbf406..f9266f5 100644 --- a/content/posts/2024/11/_index.md +++ b/content/posts/2024/11/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024-11" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/2024/_index.md b/content/posts/2024/_index.md index 3fbf406..9fa4e85 100644 --- a/content/posts/2024/_index.md +++ b/content/posts/2024/_index.md @@ -1,5 +1,5 @@ +++ -title = "Example posts" +title = "2024" sort_by = "date" template = "posts.html" page_template = "post.html" diff --git a/content/posts/typography.md b/content/posts/typography.md deleted file mode 100644 index 8f3328c..0000000 --- a/content/posts/typography.md +++ /dev/null @@ -1,9 +0,0 @@ -+++ -title = "Zola Test" -description = "Test of Zola" -date = 2023-01-16 -[taxonomies] -tags= ["Zola", "test"] -+++ - -This is a test of Zola as a website SSG. diff --git a/find-post.sh b/find-post.sh new file mode 100755 index 0000000..c717cf5 --- /dev/null +++ b/find-post.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Generated by Google Gemini 1.5 on 2025-01-02 + +# Function to extract the title from a file +extract_title() { + grep "^title =" "$1" | sed 's/^title = "//' | sed 's/"$//' | tr -d '\r' +} + +# Check if the "content" directory exists +if [[ ! -d "content/posts" ]]; then + echo "Error: 'content/posts' directory not found." >&2 + exit 1 +fi + +# Find all .md files in the "content" directory recursively +find content -type f -name "*.md" 2>/dev/null | while read file; do + title=$(extract_title "$file") + + # Skip files with 4 or 6 character ISO date titles + if [[ ! -z "$title" ]] && [[ ! "$title" =~ ^[0-9]{4}(-[0-9]{2})?$ ]]; then + printf "%s\t%s\n" "$title" "$file" + fi +done | { + + selected=$(fzf --delimiter='\t' --layout=reverse --preview 'cat {2}' --preview-window='right:50%') + + if [[ -n "$selected" ]]; then + filepath=$(echo "$selected" | awk -F'\t' '{print $2}') + # Open the file in the editor using exec or by redirecting to /dev/tty + #exec "$EDITOR" "$filepath" # Most robust solution + #OR + "$EDITOR" "$filepath" /dev/tty 2>/dev/tty # Alternative solution + fi +} diff --git a/newpost.sh b/new-post.sh similarity index 81% rename from newpost.sh rename to new-post.sh index 84e304e..41b8b6a 100755 --- a/newpost.sh +++ b/new-post.sh @@ -51,14 +51,41 @@ if [[ $shortnote == false ]] ; then if ! [ -d $posts_root/$year ]; then # Create new year mkdir $posts_root/$year - cp $posts_root/2023/_index.md $posts_root/$year/_index.md + + read -r -d '' TEMPLATE << EOF ++++ +title = "$year" +sort_by = "date" +template = "posts.html" +page_template = "post.html" +transparent = true ++++ + +Posts + +EOF + + echo "$TEMPLATE" >> $posts_root/$year/_index.md fi # Verify month path if ! [ -d $posts_root/$year/$month ]; then # Create new year mkdir $posts_root/$year/$month - cp $posts_root/2023/_index.md $posts_root/$year/$month/_index.md + read -r -d '' TEMPLATE << EOF ++++ +title = "$year-$month" +sort_by = "date" +template = "posts.html" +page_template = "post.html" +transparent = true ++++ + +Posts + +EOF + + echo "$TEMPLATE" >> $posts_root/$year/$month/_index.md fi post_path="$posts_root/$year/$month/$post_file_name" diff --git a/quick_config.sh b/quick-config.sh similarity index 100% rename from quick_config.sh rename to quick-config.sh