~stormdragon2976/bashtml

1f459e4caed973d39dfb02fa8eff125f6ee57437 — Storm Dragon 10 months ago ce633ae
Moved disqus and twitter into plugins. They are not actually working plugins yet because I don't use either of them. I am hoping that if there is interest in them someone will convert them to the plugin style code, test them, and create a pull request.
1 files changed, 2 insertions(+), 109 deletions(-)

M bashtml.sh
M bashtml.sh => bashtml.sh +2 -109
@@ 55,18 55,6 @@ global_analytics_file=""
# or change it to your own URL
global_feedburner=""

# Change this to your username if you want to use twitter for comments
global_twitter_username=""
# Set this to false for a Twitter button with share count. The cookieless version
# is just a link.
global_twitter_cookieless="true"
# Default search page, where tweets more than a week old are hidden
global_twitter_search="twitter"

# Change this to your disqus username to use disqus for comments
global_disqus_username=""


# Blog generated files
# index page of blog (it is usually good to use "index.html" here)
index_file="index.html"


@@ 115,8 103,6 @@ css_include=()
html_exclude=()

# Localization and i18n
# "Comments?" (used in twitter link after every post)
template_comments="Comments?"
# "Read more..." (link under cut article on index page)
template_read_more="Read more..."
# "View more posts" (used on bottom of index page as link to archive)


@@ 139,9 125,6 @@ template_archive_index_page="Back to the index page"
template_subscribe="Subscribe"
# "Subscribe to this page..." (used as text for browser feed button that is embedded to html)
template_subscribe_browser_button="Subscribe to this page..."
# "Tweet" (used as twitter text button for posting to twitter)
template_twitter_button="Tweet"
template_twitter_comment="<Type your comment here but please leave the URL so that other people can follow the comments>"
    
# The locale to use for the dates displayed on screen
date_format="%B %d, %Y"


@@ 220,43 203,6 @@ google_analytics() {
    fi
}

# Prints the required code for disqus comments
disqus_body() {
    [[ -z $global_disqus_username ]] && return

    echo '<div id="disqus_thread"></div>
            <script type="text/javascript">
            /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
               var disqus_shortname = '"'$global_disqus_username'"'; // required: replace example with your forum shortname

            /* * * DONT EDIT BELOW THIS LINE * * */
            (function() {
            var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
            dsq.src = "//" + disqus_shortname + ".disqus.com/embed.js";
            (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
            })();
            </script>
            <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
            <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>'
}

# Prints the required code for disqus in the footer
disqus_footer() {
    [[ -z $global_disqus_username ]] && return
    echo '<script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = '"'$global_disqus_username'"'; // required: replace example with your forum shortname

        /* * * DONT EDIT BELOW THIS LINE * * */
        (function () {
        var s = document.createElement("script"); s.async = true;
        s.type = "text/javascript";
        s.src = "//" + disqus_shortname + ".disqus.com/count.js";
        (document.getElementsByTagName("HEAD")[0] || document.getElementsByTagName("BODY")[0]).appendChild(s);
    }());
    </script>'
}

# Reads HTML file from stdin, prints its content to stdout
# $1    where to start ("text" or "entry")
# $2    where to stop ("text" or "entry")


@@ 339,52 285,6 @@ edit() {
    fi
}

# Create a Twitter summary (twitter "card") for the post
#
# $1 the post file
# $2 the title
twitter_card() {
    [[ -z $global_twitter_username ]] && return
    
    echo "<meta name='twitter:card' content='summary' />"
    echo "<meta name='twitter:site' content='@$global_twitter_username' />"
    echo "<meta name='twitter:title' content='$2' />" # Twitter truncates at 70 char
    description=$(grep -v "^<p>$template_tags_line_header" "$1" | sed -e 's/<[^>]*>//g' | tr '\n' ' ' | sed "s/\"/'/g" | head -c 250) 
    echo "<meta name='twitter:description' content=\"$description\" />"
    image=$(sed -n '2,$ d; s/.*<img.*src="\([^"]*\)".*/\1/p' "$1") # First image is fine
    [[ -z $image ]] && return
    [[ $image =~ ^https?:// ]] || image=$global_url/$image # Check that URL is absolute
    echo "<meta name='twitter:image' content='$image' />"
}

# Adds the code needed by the twitter button
#
# $1 the post URL
twitter() {
    [[ -z $global_twitter_username ]] && return

    if [[ -z $global_disqus_username ]]; then
        if [[ $global_twitter_cookieless == true ]]; then 
            id=$RANDOM

            search_engine="https://twitter.com/search?q="

            echo "<p id='twitter'><a href='http://twitter.com/intent/tweet?url=$1&text=$template_twitter_comment&via=$global_twitter_username'>$template_comments $template_twitter_button</a> "
            echo "<a href='$search_engine""$1'><span id='count-$id'></span></a>&nbsp;</p>"
            return;
        else 
            echo "<p id='twitter'>$template_comments&nbsp;"; 
        fi
    else
        echo "<p id='twitter'><a href=\"$1#disqus_thread\">$template_comments</a> &nbsp;"
    fi  

    echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"$template_twitter_comment\" data-url=\"$1\""
    echo " data-via=\"$global_twitter_username\""
    echo ">$template_twitter_button</a>	<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>"
    echo "</p>"
}

# Check if the file is a 'boilerplate' (i.e. not a post)
# The return values are designed to be used like this inside a loop:
# is_boilerplate_file <file> && continue


@@ 437,7 337,7 @@ create_html_page() {
        cat ".header.html"
        echo "<title>$title</title>"
        google_analytics
        twitter_card "$content" "$title"
        call_plugins html_head
        echo "</head><body>"
        # stuff to add before the actual body content
        [[ -n "$body_begin_file" ]] && cat "$body_begin_file"


@@ 486,8 386,6 @@ create_html_page() {
        if [[ $index == no ]]; then
            echo -e '\n<!-- text end -->'

            twitter "$global_url/$file_url"

            echo '<!-- entry end -->' # absolute end of the post
        fi



@@ 499,14 397,10 @@ create_html_page() {
        fi
        echo '</div>' # content

        # Add disqus commments except for index and all_posts pages
        [[ $index == no ]] && disqus_body

        # page footer
        cat .footer.html
        # close divs
        echo '</div></div>' # divbody and divbodyholder 
        disqus_footer
        [[ -n $body_end_file ]] && cat "$body_end_file"
        echo '</body></html>'
    } > "$filename"


@@ 1022,8 916,7 @@ create_css() {
        #description{font-size:large;margin-bottom:12px;}
        h3{margin-top:42px;margin-bottom:8px;}
        h4{margin-left:24px;margin-right:24px;}
        img{max-width:100%;}
        #twitter{line-height:20px;vertical-align:top;text-align:right;font-style:italic;color:#333;margin-top:24px;font-size:14px;}' > blog.css
        img{max-width:100%;}' > blog.css
    fi

    # If there is a style.css from the parent page (i.e. some landing page)