125 lines
6.0 KiB
Fish
125 lines
6.0 KiB
Fish
# UNFINISHED
|
|
# requires, pandoc, obsidian-export, sitemap-generator-cli, & yq
|
|
# assumes markdown file has yaml elements titled
|
|
# "aliases" "type", "tags", "date-created", & "date-modified" (no double quotes)
|
|
# generates a (mostly) compliant atom feed
|
|
function obsidian-ssg
|
|
set vault_path $argv[1] # ~/path/to/obsidian-vault/
|
|
set site_path $argv[2] # ~/path/to/final-site/
|
|
# must be compliant with pandoc's html template language
|
|
set blog_template $argv[3] # /path/to/pandoc-template.html
|
|
set note_template $argv[4] # /path/to/pandoc-template.html
|
|
set recipe_template $note_template # /path/to/pandoc-template.html
|
|
set
|
|
mkdir $site_path"rss"
|
|
# Atom file and header creation (creates a blog feed and a notes feed)
|
|
set feeds $site_path"rss/blog.xml" $site_path"rss/notes.xml" $site_path"rss/recipes.xml"
|
|
|
|
for feed_file in $feeds
|
|
switch $feed_file
|
|
case $site_path"rss/notes.xml"
|
|
set title notes
|
|
case $site_path"rss/blog.xml"
|
|
set title blog
|
|
case $site_path"rss/recipes.xml"
|
|
set title recipes
|
|
end
|
|
rm $feed_file
|
|
touch $feed_file
|
|
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >>"$feed_file"
|
|
echo '<?xml-stylesheet href="style.xsl" type="text/xsl"?>' >>"$feed_file"
|
|
echo "<feed xmlns=\"http://www.w3.org/2005/Atom\">" >>"$feed_file"
|
|
echo " <title>proto's $title</title>" >>"$feed_file"
|
|
echo " <author>" >>"$feed_file"
|
|
echo " <name>proto</name>" >>"$feed_file"
|
|
echo " <email>proto@proto.garden</email>" >>"$feed_file"
|
|
echo " </author>" >>"$feed_file"
|
|
echo " <id>tag:proto.garden,2024-01-01:$title</id>" >>"$feed_file"
|
|
echo " <link href=\"https://proto.garden/$title/\"/>" >>"$feed_file"
|
|
echo " <link href=\"https://proto.garden/rss/$title.xml\" rel=\"self\"/>" >>"$feed_file"
|
|
echo " <updated>$(date -u +%Y-%m-%dT%H:%M:%S)Z</updated>" >>"$feed_file"
|
|
end
|
|
|
|
# this is a rust program that just turns all my obsidian stuff like [[wikilinks]] into normal HTML which makes it easier for pandoc
|
|
obsidian-export $vault_path $site_path
|
|
# remove templates I use for note creation in obsidian
|
|
rm $site_path"/lib/templates/recipe.md" $site_path"/lib/templates/journal.md"
|
|
|
|
cd $site_path
|
|
for file in **/*.md
|
|
|
|
set page_name (path change-extension 'html' $file)
|
|
set tempfile (string trim $file)
|
|
set file $tempfile
|
|
|
|
# store body HTML for rss content
|
|
set content (pandoc $file)
|
|
set path (path change-extension '' $file)
|
|
# store YAML elements from wiki entry
|
|
set created (yq -e -N --front-matter=extract '.date-created' $file) # frontmatter 'date-created' YYYY-MM-DDTHH:MM:SS
|
|
set modified (yq -e -N --front-matter=extract '.date-modified' $file) # frontmatter 'date-modified' YYYY-MM-DDTHH:MM:SS
|
|
set title (string sub -s 4 -e -1 \"(yq -e -N --front-matter=extract '.aliases' $file)[1]\") # frontmatter 'first alias'
|
|
set type (yq -e -N --front-matter=extract '.type' $file) # frontmatter 'type'
|
|
set page_tags (string sub -s 2 \"(string trim --chars=\"- \" \"(yq -e -N --front-matter=extract '.tags' $file )\")\") # frontmatter 'tags'
|
|
set date_created (string sub -l 10 $created) # frontmatter 'date-created' YYYY-MM-DD
|
|
set date_modified (string sub -l 10 $modified) # frontmatter 'date-modified' YYYY-MM-DD
|
|
|
|
# populate both rss feeds
|
|
if not string match -rq 'index|old|draft' $type
|
|
# set destination file
|
|
set html_template $note_template
|
|
switch $type
|
|
case blog
|
|
set html_template $blog_template
|
|
set atom_file $feeds[1] # sets active feed to blog if the input file is of type: blog
|
|
case note
|
|
set html_template $note_template
|
|
set atom_file $feeds[2] # sets active feed to notes if the is of type: note
|
|
case recipe
|
|
set html_template $recipe_template
|
|
set atom_file $feeds[3] # sets active feed to recipes if the is of type: recipe
|
|
end
|
|
end
|
|
# convert markddown to html
|
|
pandoc $file --standalone --template $html_template --metadata title="$title" --metadata date-modified="$date_modified" --metadata date-created="$date_created" -o "$site_path$page_name"
|
|
|
|
# create entry
|
|
echo " <entry>" >>"$atom_file"
|
|
echo " <title>"$title"</title>" >>"$atom_file"
|
|
echo " <summary>$summary</summary>" >>"$atom_file"
|
|
echo " <published>$created""Z""</published>" >>"$atom_file"
|
|
echo " <updated>$modified""Z""</updated>" >>"$atom_file"
|
|
echo " <link href=\"https://proto.garden/$page_name\"/>" >>"$atom_file"
|
|
echo " <id>tag:proto.garden,"$date_created":$path</id>" >>"$atom_file"
|
|
# TODO; ftx to allow for multi-line tags
|
|
# set categories (string trim --chars=, "$page_tags")
|
|
# for category in (string split " " ",$categories")
|
|
# echo "<category term=\"$category\"/>" >>"$atom_file"
|
|
# end
|
|
echo " <content type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">$content</div></content>" >>"$atom_file"
|
|
echo " </entry>" >>"$atom_file"
|
|
end
|
|
|
|
for file in **/*.html
|
|
# convert wikilinks that still link to markdown pages
|
|
sed -i 's/.md">/">/g' $file
|
|
sed -i 's/.md#/#/g' $file
|
|
# make the 'up' button work on folder index.html pages
|
|
if string match -rq index $file
|
|
sed -i 's|<a href="./">up</a>|<a href="../">up</a>|g' $file
|
|
end
|
|
end
|
|
# add closing tag to feed files
|
|
for feed_file in $feeds
|
|
echo "</feed> " >>$feed_file
|
|
sed -i 's/.md">/">/g' $feed_file
|
|
sed -i 's/.md#/#/g' $feed_file
|
|
end
|
|
# copy images to site folder
|
|
cp -r $vault_path"/lib/images/" $site_path"/lib"
|
|
|
|
# cleanup markdown files
|
|
cd $site_path
|
|
rm **/*.md
|
|
end
|