~npisanti/npisantidotcomssg

b3c8bc64bb3fd8ea6be77dcd24a92ad8ef3c2199 — Nicola Pisanti a month ago f5d18bb
fixes script tabs
1 files changed, 115 insertions(+), 115 deletions(-)

M build.sh
M build.sh => build.sh +115 -115
@@ 24,10 24,10 @@ end

function date_and_category 
	set -l post_path $argv[1]
    if test -z  $argv[2]; or test $argv[2] -eq "1"
        set pagelink "index"
    else
        set pagelink "page$argv[2]"
	if test -z  $argv[2]; or test $argv[2] -eq "1"
		set pagelink "index"
	else
		set pagelink "page$argv[2]"
	end
	
	set -l post_split (string split / $argv[1])


@@ 41,7 41,7 @@ function date_and_category
end

function find_dir_page 
    # arg 1 is dir/postname.html 
	# arg 1 is dir/postname.html 
	set -l post_split (string split / $argv[1])
	set post_dir $post_split[1]
	set post_name $post_split[2]


@@ 49,10 49,10 @@ function find_dir_page
	set pagenum "1"
   
	for p in (ls -1 "$SCRIPTFOLDER/input/journal/$post_dir" | sort -r)
        if test "$p" = "$post_name"    
            set pagenum (math -s0 "(($postnum-1)/$MAXPOSTSPERPAGE)+1" )
        end
        set postnum (math "$postnum+1")
		if test "$p" = "$post_name"    
			set pagenum (math -s0 "(($postnum-1)/$MAXPOSTSPERPAGE)+1" )
		end
		set postnum (math "$postnum+1")
	end

	echo $pagenum


@@ 60,22 60,22 @@ end

function open_page #-------------------------------------------------------------
	# arg 1 should be page path to get thumb
    # arg 2 should be the title
	# arg 2 should be the title
	set    text '<!DOCTYPE html>'
	set -a text '\n<html>'
	set -a text '\n<head>'
	set -a text '\n<meta charset="utf-8" />'

	if test -n $argv[2] 
	    set -a text "\n<title>[ $argv[2] ]</title>"
		set -a text "\n<title>[ $argv[2] ]</title>"
	else
    	set -a text "\n<title>[ npisanti.com]</title>"
		set -a text "\n<title>[ npisanti.com]</title>"
	end 

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

	set -a text (og_image_path "$argv[1]") 
	

	set -a text '\n<meta property="og:image:height" content="230" />'
	set -a text '\n<meta property="og:image:width" content="230" />'



@@ 122,9 122,9 @@ function navigation_header #----------------------------------------------------
end 

function navigation_footer #-----------------------------------------------------
    set numpage "$argv[1]"
    set maxpage "$argv[2]"
    set archive_enable "$argv[3]"
	set numpage "$argv[1]"
	set maxpage "$argv[2]"
	set archive_enable "$argv[3]"
	set footer "<footer>"

	if test -n "$archive_enable" 


@@ 178,28 178,28 @@ function build_pages #----------------------------------------------------------
end

function build_feed #------------------------------------------------------------
    set channel_name "$argv[1]"
    printf "building $channel_name"
    set header_tag "$channel_name"
    set title "$channel_name"
	set channel_name "$argv[1]"
	printf "building $channel_name"
	set header_tag "$channel_name"
	set title "$channel_name"

	mkdir -p "$OUTFOLDER/$channel_name"

	if test "$channel_name" = "main"
		set list (cat input/journal/feed.list)
		set header_tag "feed"
		set title "npisanti.com"
	else
		set list "$argv[1]/"(ls -1 "$SCRIPTFOLDER/input/journal/$argv[1]" | sort -r)    
	end

    mkdir -p "$OUTFOLDER/$channel_name"
    
    if test "$channel_name" = "main"
        set list (cat input/journal/feed.list)
        set header_tag "feed"
        set title "npisanti.com"
    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)")

    # adds the last page if needed 
    if test (math -s0 "$posts_len % $MAXPOSTSPERPAGE") -ne "0"
        set max_pages (math "$max_pages+1")
    end
	# adds the last page if needed 
	if test (math -s0 "$posts_len % $MAXPOSTSPERPAGE") -ne "0"
		set max_pages (math "$max_pages+1")
	end
    
	for i in ( seq "$max_pages" )
		set start (math "(($i-1)*$MAXPOSTSPERPAGE)+1" ) 


@@ 216,11 216,11 @@ function build_feed #-----------------------------------------------------------
			set -a text "\n<section>"
			set -a text "\n"(cat "input/journal/$p")
			if test "$channel_name" = "main"
                # this will search for the correct category page
			    set -l dirpage (find_dir_page "$p")
			    set -a text "\n"(date_and_category $p $dirpage )
				# this will search for the correct category page
				set -l dirpage (find_dir_page "$p")
				set -a text "\n"(date_and_category $p $dirpage )
			else
			    set -a text "\n"(date_and_category $p $i)
				set -a text "\n"(date_and_category $p $i)
			end
			set -a text "\n</section>"
		end


@@ 233,120 233,120 @@ function build_feed #-----------------------------------------------------------
		printf "."
	end
	cp "$OUTFOLDER/$channel_name/page1.html" "$OUTFOLDER/$channel_name/index.html"
    printf "\n"
	printf "\n"
end

function build_posts #-----------------------------------------------------------
    printf "building posts"
    mkdir -p "$OUTFOLDER/posts"

    for dir in $CATEGORIES
        set postnum "1"
        set list (ls -1 "$SCRIPTFOLDER/input/journal/$dir" | sort -r)    
	for dir in $CATEGORIES
		set postnum "1"
		set list (ls -1 "$SCRIPTFOLDER/input/journal/$dir" | sort -r)    

		for p in $list
		    if test -n $p
                set -l pagenum (math -s0 "(($postnum-1)/$MAXPOSTSPERPAGE)+1" )
                set -l title ( basename "$p" .html | string sub -s 13 | string replace -a _ " " )
        		set    text (open_page "" "$title")
        		set -a text "\n"(navigation_header "post" )
    			set -a text "\n<section>"
    			set -a text "\n"(cat "input/journal/$dir/$p" )
    			set -a text "\n"(date_and_category "$dir/$p" "$pagenum" )
    			set -a text "\n</section>"
                set -a text "\n"(close_page)
                set    text (echo $text | sed -e "s|SITEROOTPATH|..|g") 		
                echo -e "$text" > "$OUTFOLDER/posts/$p"

                set postnum (math "$postnum + 1")
                printf "."
            end
			if test -n $p
				set -l pagenum (math -s0 "(($postnum-1)/$MAXPOSTSPERPAGE)+1" )
				set -l title ( basename "$p" .html | string sub -s 13 | string replace -a _ " " )
				set    text (open_page "" "$title")
				set -a text "\n"(navigation_header "post" )
				set -a text "\n<section>"
				set -a text "\n"(cat "input/journal/$dir/$p" )
				set -a text "\n"(date_and_category "$dir/$p" "$pagenum" )
				set -a text "\n</section>"
				set -a text "\n"(close_page)
				set    text (echo $text | sed -e "s|SITEROOTPATH|..|g") 		
				echo -e "$text" > "$OUTFOLDER/posts/$p"

				set postnum (math "$postnum + 1")
				printf "."
			end
		end
    end
	end
    
    printf "\n"
end

function build_archives #--------------------------------------------------------
    printf "building archives"
    set last_year "1995"
	printf "building archives"
	set last_year "1995"

    for dir in $CATEGORIES
        set list (ls -1 "$SCRIPTFOLDER/input/journal/$dir")    
	for dir in $CATEGORIES
		set list (ls -1 "$SCRIPTFOLDER/input/journal/$dir")    

		set    text (open_page "" "$dir archives")
		set -a text "\n"(navigation_header "$dir archives" )
        set -a text "\n<section>"
		set -a text "\n<section>"

		for p in $list
			set -l post_date (string sub -s 1 -l 10 $p | string replace -a _ / )
			set -l post_year (string sub -s 1 -l 4 $p )
			if test "$last_year" != "$post_year"
                set last_year "$post_year"
                set -a text "\n<br/>"
				set last_year "$post_year"
				set -a text "\n<br/>"
			end

			set -l post_name ( basename "$p" .html | string sub -s 12 | string replace -a _ " " )
		    set -a text "\n$post_date <a href=\"../posts/$p\">$post_name</a><br/>"
			set -a text "\n$post_date <a href=\"../posts/$p\">$post_name</a><br/>"
		end

        set -a text "\n</section>"
        set -a text "\n"(close_page)
        set    text (echo $text | sed -e "s|SITEROOTPATH|..|g") 
        echo -e "$text" > "$OUTFOLDER/$dir/archive.html"
        printf "."
    end
    
    printf "\n"
		set -a text "\n</section>"
		set -a text "\n"(close_page)
		set    text (echo $text | sed -e "s|SITEROOTPATH|..|g") 
		echo -e "$text" > "$OUTFOLDER/$dir/archive.html"
		printf "."
	end

	printf "\n"
end

function build_rss #-------------------------------------------------------------
    printf "building RSS"
	printf "building RSS"

	set list (cat input/journal/rss.list)  

	set text "<?xml version='1.0' encoding='UTF-8' ?>"
 
	set -a text "\n<rss version=\"2.0\">"
	set -a text "\n"(cat input/base/rssbase.xml)

	for p in $list
		if test -n $p
			set -l post_split (string split / $p)
			set post_dir $post_split[1]
			set post_name $post_split[2]
			set -l year (string sub -s 1 -l 4 $post_name)
			set -l month (string sub -s 6 -l 2 $post_name)
			set -l day (string sub -s 9 -l 2 $post_name)
			set -l title ( basename "$post_name" .html | string sub -s 13 | string replace -a _ " " )
			set -l pagelink "posts/$post_name"
			set -l RFC822_time (date --date=$month/$day/$year -R)

			set -a text "\n\t\t<item>"
			set -a text "\n\t\t\t<title>$title</title>" 
			set -a text "\n\t\t\t<description><![CDATA["
			set -a text "\n\t\t\t"(cat "input/journal/$p")
			set -a text "\n\t\t\t]]></description>"
			set -a text "\n\t\t\t<pubDate>$RFC822_time</pubDate>"
			set -a text "\n\t\t\t<guid>http://npisanti.com/$pagelink</guid>"
			set -a text "\n\t\t</item>"

			printf "."
		end
	end

    set list (cat input/journal/rss.list)  
    
    set text "<?xml version='1.0' encoding='UTF-8' ?>"
 
    set -a text "\n<rss version=\"2.0\">"
    set -a text "\n"(cat input/base/rssbase.xml)

    for p in $list
        if test -n $p
        	set -l post_split (string split / $p)
        	set post_dir $post_split[1]
        	set post_name $post_split[2]
            set -l year (string sub -s 1 -l 4 $post_name)
            set -l month (string sub -s 6 -l 2 $post_name)
            set -l day (string sub -s 9 -l 2 $post_name)
            set -l title ( basename "$post_name" .html | string sub -s 13 | string replace -a _ " " )
            set -l pagelink "posts/$post_name"
            set -l RFC822_time (date --date=$month/$day/$year -R)

            set -a text "\n\t\t<item>"
            set -a text "\n\t\t\t<title>$title</title>" 
            set -a text "\n\t\t\t<description><![CDATA["
            set -a text "\n\t\t\t"(cat "input/journal/$p")
            set -a text "\n\t\t\t]]></description>"
            set -a text "\n\t\t\t<pubDate>$RFC822_time</pubDate>"
            set -a text "\n\t\t\t<guid>http://npisanti.com/$pagelink</guid>"
            set -a text "\n\t\t</item>"

            printf "."
        end
    end

    set -a text "\n\t</channel>"
    set -a text "\n</rss>"    
    set text (echo $text | sed -e "s|SITEROOTPATH|http://npisanti.com|g") 
    echo -e "$text" > "$OUTFOLDER/rss.xml"
    printf "\n"
	set -a text "\n\t</channel>"
	set -a text "\n</rss>"    
	set text (echo $text | sed -e "s|SITEROOTPATH|http://npisanti.com|g") 
	echo -e "$text" > "$OUTFOLDER/rss.xml"
	printf "\n"
end

function build_index_redirect #--------------------------------------------------
	echo "creating index redirect..."
	echo "creating index redirect.echo.."
	set    text '<!DOCTYPE html>'
	set -a text '\n<html>\n<head>\n<meta charset="utf-8" />'
	set -a text "\n<title>[ npisanti.com]</title>"
    set -a text "\n"(cat input/base/head.html) 
	set -a text "\n"(cat input/base/head.html) 
	set -a text (og_image_path) 
	set -a text '\n<meta property="og:image:height" content="230" />'
	set -a text '\n<meta property="og:image:width" content="230" />'