~npisanti/npisantidotcomssg

105aa370948c512c2442475268e57c21ca538dfe — Nicola Pisanti a month ago cb3aff4
builds feed and main
1 files changed, 83 insertions(+), 61 deletions(-)

M build_fish.sh
M build_fish.sh => build_fish.sh +83 -61
@@ 29,6 29,18 @@ function og_image_path
	echo "<meta property=\"og:image\" content=\"http://npisanti.com/data/$og_thumbfile\" />"
end

function date_and_category 
	set -l post_path $argv[1]
	set -l post_split (string split / $argv[1])
	# channel in [1], name in [2]
	set -l post_dir $post_split[1]
	set -l post_name $post_split[2]
	
	set -l date_str (string sub -s 1 -l 10 $post_name | string replace -a _ / )

	echo "<br><br><div style=\"text-align:right\"><a href=\"../posts/$post_name\">$date_str</a> | posted in <a href=\"../$post_dir/index.html\">$post_dir</a></div>"
end

function open_page #-------------------------------------------------------------
	# arg 1 should be page path to get thumb
	set    text '<!DOCTYPE html>'


@@ 37,6 49,8 @@ function open_page #------------------------------------------------------------
	set -a text '\n<meta charset="utf-8" />'
	set -a text '\n<title>npisanti.com</title>' 

    set -a text (cat input/base/head.html) 

	set -a text (og_image_path "$argv[1]") 
	
	set -a text '\n<meta property="og:image:height" content="230" />'


@@ 52,33 66,33 @@ function close_page
	echo "</body></html>"
end

function build_header #----------------------------------------------------------
function navigation_header #-----------------------------------------------------
	# argument 1 is the tab to highlight
	# argument 2 is a string to prepend to relative links, eg "../"	
	set -l tabs "feed" "more" "contact" "webring"
	set text ""
	set text "<header>"

	for x in $tabs
		if test "$x" = "$argv[1]"
			set pretab "["
			set posttab "]"
			set pretab "[ "
			set posttab " ]"
		else
			set pretab ""
			set posttab ""
		end
		
		switch $x 
		case feed
			set text "$pretab<a href=\"$argv[2]index.html\">feed</a>$posttab&nbsp;"
		case feed main
			set -a text "$pretab<a href=\"../main/index.html\">feed</a>$posttab&nbsp;"
		case more
			set -a text "$pretab<a href=\"$argv[2]more.html\">more</a>$posttab&nbsp;"
			set -a text "$pretab<a href=\"../pages/more.html\">more</a>$posttab&nbsp;"
		case contact 
			set -a text "$pretab<a href=\"$argv[2]contact.html\">contact</a>$posttab&nbsp;"
			set -a text "$pretab<a href=\"../pages/contact.html\">contact</a>$posttab&nbsp;"
		case webring
			set -a text "$pretab<a href=\"https://webring.xxiivv.com/\">webring</a>$posttab&nbsp;"
		end
	end

	set -a text "</header>"
	echo $text
end 



@@ 86,12 100,8 @@ end
function navigation_footer
    set numpage "$argv[1]"
    set maxpage "$argv[2]"
    set prepend_path "$argv[3]"
    set archive_enable "$argv[4]"
	set footer ""
	if test -z "$prepend_path"
		set prepend_path "."
	end
    set archive_enable "$argv[3]"
	set footer "<footer>"

	if test -n "$archive_enable" 
		set -a footer "<a href=\"$prepend_path/archive.html\">all</a>"        


@@ 99,43 109,25 @@ function navigation_footer

	if test "$numpage" -ne "1"
		set -l prev (math "$numpage-1")
		set -a footer "<a href=\"$prepend_path/page$prev.html\">prev</a>"
		set -a footer "<a href=\"page$prev.html\">prev</a>"
	end

	for i in (seq $maxpage)
		if test "$i" -eq "$numpage"
			set -a footer "<a href=\"$prepend_path/page$i.html\">[$i]</a>"
			set -a footer "<a href=\"page$i.html\">[$i]</a>"
		else
			set -a footer "<a href=\"$prepend_path/page$i.html\">$i</a>"
			set -a footer "<a href=\"page$i.html\">$i</a>"
		end
	end
	
	if test "$numpage" -ne "$maxpage"
		set -l next (math "$numpage+1")
		set -a footer "<a href=\"$prepend_path/page$next.html\">next</a>"
	end

	echo $footer
end

function date_and_category 
	set -l post_path $argv[1]
	set prepend_path $argv[2]
	if test -z $argv[2]
		set prepend_path ".."	
		set -a footer "<a href=\"page$next.html\">next</a>"
	end
	set -l post_split (string split / $argv[1])
	# channel in [1], name in [2]
	set -l post_dir $post_split[1]
	set -l post_name $post_split[2]
	
	set -l date_str (string sub -s 1 -l 10 $post_name | string replace -a _ / )


	echo "<br><br><div style=\"text-align:right\"><a href=\"$prepend_path/posts/$post_name\">$date_str</a> | posted in <a href=\"$prepend_path/$post_dir/index.html\">$post_dir</a></div>"
	set -a footer "</footer>"

	
	
	echo $footer
end

#--------------------------------------------------------------------------------


@@ 147,47 139,77 @@ function build_pages
		set outname (basename $x)

		set    text (open_page "$x")
		set -a text "\n"(build_header $name)
		set -a text "\n"(navigation_header $name)
		set -a text "\n"(cat "$x")
		set -a text "\n"(close_page)
		set text (echo $text | sed -e "s|SITEROOTPATH|..|g") 		

		echo -e "$text" > "$OUTFOLDER/$outname"
		echo -e "$text" > "$OUTFOLDER/pages/$outname"
	end
end

function build_index
	set    text (open_page "")
	set -a text "\n"(build_header "feed")
function build_feed
    # the feed_list has to be set before running
    set channel_name "$argv[1]"
    set header_tag "$channel_name"

	set list (cat input/journal/feed.list)
    if test "$channel_name" = "main"
        set list (cat input/journal/feed.list)
        set header_tag "feed"
    else
        set list "$argv[1]/"(ls -1 "$SCRIPTFOLDER/input/journal/$argv[1]" | sort -r)    
    end
 
	set posts_len (count $list)
	set max_pages (math "floor($posts_len / $MAXPOSTSPERPAGE) +1")

	for p in $list[1..$MAXPOSTSPERPAGE]
		set -a text "\n<section>"
		set -a text "\n"(cat "input/journal/$p")
		set -a text "\n"(date_and_category $p ".")
		set -a text "\n</section>"
	end
	mkdir -p "$OUTFOLDER/$channel_name"

	set -l posts_len (count $list)
	set -l max_pages (math "floor($posts_len / $MAXPOSTSPERPAGE) +1")
	echo "MAX $max_pages"
	
	for i in ( seq "$max_pages" )
		echo "processing page $i"
		set start (math "(($i-1)*$MAXPOSTSPERPAGE)+1" ) 
		set stop (math "(($i)*$MAXPOSTSPERPAGE)" ) 
		if test "$stop" -gt "$posts_len" 
			set stop $posts_len
		end

		set    text (open_page "")
		set -a text "\n"(navigation_header "$header_tag" )

		for p in $list[$start..$stop]
			set -a text "\n<section>"
			set -a text "\n"(cat "input/journal/$p")
			set -a text "\n"(date_and_category $p )
			set -a text "\n</section>"
		end

		set -a text "\n"(navigation_footer $i $max_pages "active") 
		set -a text "\n"(close_page)
		set    text (echo $text | sed -e "s|SITEROOTPATH|..|g") 		

	set -a text "\n"(navigation_footer 1 $max_pages "main") 
	set -a text "\n"(close_page)
	set    text (echo $text | sed -e "s|SITEROOTPATH|.|g") 		
		echo -e "$text" > "$OUTFOLDER/$channel_name/page$i.html"
	end

	echo -e "$text" > "$OUTFOLDER/index.html"
	cp "$OUTFOLDER/$channel_name/page1.html" "$OUTFOLDER/$channel_name/index.html"
end



# TODO
# build index : takes range from (cat feed.list)
# build_feed 
# build_channel

# built posts_and_archives
# build_rss
# add link from npisanti.com/index.html to npisanti.com/main/index.html

build_pages

build_index
build_feed "main"
build_feed "ink"
build_feed "installations"
build_feed "visuals"
build_feed "music"

#echo (navigation_footer 2 7 "")