monochromatic

monochromatic blog: http://blog.z3bra.org
git clone git://z3bra.org/monochromatic
Log | Files | Refs

commit 10c68e2381a256731b104332d1525302028b8ece
parent 07e6ce25eba10c2beafd9c25b996292779f22213
Author: z3bra <willy@mailoo.org>
Date:   Tue,  1 Apr 2014 11:33:54 +0200

Moved tools to the main directory, and added a sed script

Diffstat:
check.sh | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
feeds.sh | 22++++++++++++++++++++++
post.sh | 28++++++++++++++++++++++++++++
tomarkdown.sed | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/body.template | 15---------------
tools/check.sh | 60------------------------------------------------------------
tools/feeds.sh | 37-------------------------------------
tools/foot.template | 12------------
tools/head.template | 13-------------
tools/post.sh | 37-------------------------------------
tools/publi.sh | 10----------
tools/update.sh | 11-----------
12 files changed, 185 insertions(+), 195 deletions(-)

diff --git a/check.sh b/check.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +uri=blog.z3bra.org +charset=utf-8 +doctype=Inline +profile=css3 + +function w3c_valid () { + if (curl -sI "$1" | grep -o 'Invalid' >/dev/null); then + echo -e "[\033[1;31mFAIL\033[0m]" + echo -e " Errors : $1" + exit 1 + fi +} + +function rss_valid () { + if (curl -s "$check" | grep -o 'Sorry' >/dev/null); then + echo -e "[\033[1;31mFAIL\033[0m]" + echo -e " Errors : $1" + exit 1 + fi +} + + +# HTML files + +http=http://validator.w3.org/check +count=0 +total=`find -name '*.html'|wc -l` +for file in `find -name '*.html'`; do + + count=$(( $count+1 )) + echo -ne "\rChecking HTML file(s) ... $count/$total" + + full_uri=${uri}/${file/.\//} + check="${http}?uri=${full_uri}&charset=${charset}&$doctype=${doctype}" + + w3c_valid "$check" + echo -ne "\rChecking HTML file(s) ... " +done + +echo -e "[\033[1;32m OK \033[0m]" + +# CSS files +echo -n 'Checking CSS file(s) ... ' + +http=http://jigsaw.w3.org/css-validator/validator +check="${http}?uri=${uri}&profile=${profile}" + +w3c_valid "$check" +echo -e "[\033[1;32m OK \033[0m]" + + +# RSS feed +echo -n 'Checking RSS file(s) ... ' +http=http://feedvalidator.org/check.cgi +check="${http}?url=${uri}/rss/feed.xml" + +rss_valid "$check" +echo -e "[\033[1;32m OK \033[0m]" diff --git a/feeds.sh b/feeds.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +test -z "$1" && echo "usage: `basename $0` <input file>" && exit 1 + +cat << EOF +<?xml version='1.0'?> +<rss version='2.0'> +<channel> +<title>Monochromatic</title> +<description>z3bra, the stripes appart</description> +<link>http://blog.z3bra.org</link> +EOF + +sed -e 's/^## .*$/<description>/' \ + -e 's/^$/<\/description>\n<\/item>/' \ + -e 's/^# \[\(.*\)\](\(.*\))/<item>\n<title>\1<\/title>\n<link>\2<\/link>/' $1 + +cat << EOF +</item> +</channel> +</rss> +EOF diff --git a/post.sh b/post.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Ask the user for a title +read -p "Post title: " title + +# use post title to name the file +file=`echo ${title}| sed "s/\s\+/-/g;s/./\l&/g;s/[,.!;\"']//g"`.txt + +test -z "$file" && exit 1 + +#date format for the post +date=`date +"%d %B, %Y"` + +# The format of the path to the post, here: /yyyy/mm/ +folder=`date +%Y/%m` + +# create the path if it does not exists +test -d ${folder} || mkdir -p ${folder} + +# build the whole path +post="${folder}/${file}" + +test -f ${post} || echo "cannot create ${post}" && exit 1 + +echo "$post created" + +# create a symlink to the last post, to easily access it +ln -fs ${post} last.txt diff --git a/tomarkdown.sed b/tomarkdown.sed @@ -0,0 +1,75 @@ +#!/bin/sed -f + +# remove header +1,/<div id='wrapper'>/d + +# no more indentation +s/^\s*// + +# reformat titles +/<h[1-6][^>]*>/{ + $!N + s/<h1[^>]*>\s*\(.*\)\(<\/h1>\)\?/# \1/ + s/<h2[^>]*>\s*\(.*\)\(<\/h2>\)\?/## \1/ + s/<h3[^>]*>\s*\(.*\)\(<\/h3>\)\?/### \1/ + s/<h4[^>]*>\s*\(.*\)\(<\/h4>\)\?/#### \1/ + s/<h5[^>]*>\s*\(.*\)\(<\/h5>\)\?/##### \1/ + s/<h6[^>]*>\s*\(.*\)\(<\/h6>\)\?/###### \1/ +} + +# remove closing title tags +/^\s*<\/h[1-6]>\s*$/d +s/<\/h[1-6]>// + +# replace all links/strong/emphasis +s/<a href=["']\(.*\)["']>\(.*\)<\/a>/[\2](\1)/ +s/<\/\?strong>/**/g +s/<\/\?em>/_/g + +# lists +/<ul[^>]*>/,/<\/ul>/{ + /^\s*<\/\?ul>$/d + s/<li>\(.*\)<\/li>/* \1/ +} + +# images +/<a class='a_img'/{ + $!N + /<img/{ + $!N + s/<a class='[a-z_]*' href='\(.*\)'> *\n*\ + *<img class='[a-z_]*' src='\(.*\)' alt='\(.*\)'\/> *\n *<\/a>/[![\3](\2)](\1)/ + } +} + +# pre formatted text +/<pre>/,/<\/pre>/{ + s/<\/\?code>//g + s/<\/\?pre>//g + s/^/ / +} + +/<code>/{ + $!N + s/<\/\?code>/`/g +} + +# new lines +s/<br[\/ ]*>/ / + +# paragraphs +/<p[^>]*>/,/<\/p>/s/<\/\?p>//g + +# quotes +/<blockquote[^>]*>/,/<\/blockquote>/s/^\s*/> / +s/<\/\?blockquote>//g +/^> $/d + +# remove simple tag, and span tags +#s/<\/\?[A-Za-z0-9]*>//g +s/<\/\?span[^>]*>//g +s/<\/\?section[^>]*>//g +s/<\/\?article[^>]*>//g + +# remove footer +/<\/div>/,$d diff --git a/tools/body.template b/tools/body.template @@ -1,15 +0,0 @@ - <div id='wrapper'> - <section> - <h1> - <a href='#'>BLOG_TITLE</a> - </h1> - <h2> - &mdash; BLOG_DATE - </h2> - <article> - <p> - - </p> - </article> - </section> - </div> diff --git a/tools/check.sh b/tools/check.sh @@ -1,60 +0,0 @@ -#!/bin/bash - -uri=blog.z3bra.org -charset=utf-8 -doctype=Inline -profile=css3 - -function w3c_valid () { - if (curl -sI "$1" | grep -o 'Invalid' >/dev/null); then - echo -e "[\033[1;31mFAIL\033[0m]" - echo -e " Errors : $1" - exit 1 - fi -} - -function rss_valid () { - if (curl -s "$check" | grep -o 'Sorry' >/dev/null); then - echo -e "[\033[1;31mFAIL\033[0m]" - echo -e " Errors : $1" - exit 1 - fi -} - - -# HTML files - -http=http://validator.w3.org/check -count=0 -total=`find -name '*.html'|wc -l` -for file in `find -name '*.html'`; do - - count=$(( $count+1 )) - echo -ne "\rChecking HTML file(s) ... $count/$total" - - full_uri=${uri}/${file/.\//} - check="${http}?uri=${full_uri}&charset=${charset}&$doctype=${doctype}" - - w3c_valid "$check" - echo -ne "\rChecking HTML file(s) ... " -done - -echo -e "[\033[1;32m OK \033[0m]" - -# CSS files -echo -n 'Checking CSS file(s) ... ' - -http=http://jigsaw.w3.org/css-validator/validator -check="${http}?uri=${uri}&profile=${profile}" - -w3c_valid "$check" -echo -e "[\033[1;32m OK \033[0m]" - - -# RSS feed -echo -n 'Checking RSS file(s) ... ' -http=http://feedvalidator.org/check.cgi -check="${http}?url=${uri}/rss/feed.xml" - -rss_valid "$check" -echo -e "[\033[1;32m OK \033[0m]" diff --git a/tools/feeds.sh b/tools/feeds.sh @@ -1,37 +0,0 @@ -#!/bin/bash - -RSS=rss/feed.xml - -echo -ne "\rGenerating RSS file ... " - -cat << EOF > $RSS -<?xml version='1.0'?> -<rss version='2.0'> -<channel> -<title>Monochromatic</title> -<description>z3bra, the stripes appart</description> -<link>http://blog.z3bra.org</link> -<item> -EOF - -sed -n '/section/,/section/p' index.html >> $RSS - -# dat regex... Delete lines with <section>, </section>, <p>, </p>, <br />, <h2> -# to </h2> or <!-- -sed -i '/<\/*section>/d;/<\/\?[pb]\+[/r ]*>/d;/<h2>/,/<\/h2>/d;/<!--/d' $RSS - -# change <article> in <description>, <h1> in <title>, ^$ in <item> -sed -i 's/^\s*//' $RSS -sed -i '/^$/{N;s/\n//}' $RSS -sed -i 's/<\(\/\)\?article>/<\1description>/' $RSS -sed -i 's/<\(\/\)\?h1>/<\1title>/' $RSS -sed -i 's/^$/<\/item>\n<item>/' $RSS -sed -i 's/<a\ .*>\(.*\)<\/a>/\1/' $RSS - -cat << EOF >> $RSS -</item> -</channel> -</rss> -EOF - -echo -e "[\033[1;32m OK \033[0m]" diff --git a/tools/foot.template b/tools/foot.template @@ -1,12 +0,0 @@ - <!-- footer {{{ --> - <footer> - <a href='http://www.acme.com/software/thttpd/'>thttpd</a> <!-- &hearts; -->// - <a href='http://www.wtfpl.net/about/'>wtfpl</a> <!-- &copy; -->// - <a href='mailto:willy@mailoo.org'>mail</a> <!-- &#9993; -->// - <a href='http://z3bra.org'>root</a> <!-- &#9774; -->// - <a href='http://blog.z3bra.org/rss/feed.xml'>rss</a> <!-- &#9733; --> - </footer> - <!-- }}} --> - </body> -</html> -<!-- vim: set sw=2 et ai fdm=marker ft=html: --> diff --git a/tools/head.template b/tools/head.template @@ -1,13 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset='utf-8'/> - <link rel='stylesheet' href='/css/monochrome.css'/> - <link rel='stylesheet' href='/css/code.css'/> - <link rel='stylesheet' href='/css/phone.css' media='screen and (max-width: 540px)'/> - <title>z3bra.org - monochromatic blog</title> - </head> - <body> - <header> - <h1><a href='/'>Monochromatic</a></h1> <h2>&mdash; <a href='/about.html'>z3bra</a>, the stripes apart</h2> - </header> diff --git a/tools/post.sh b/tools/post.sh @@ -1,37 +0,0 @@ -#!/bin/bash - - - -# Ask the user for a title -read -p "Post title: " title - - -# use post title to name the file -file=`echo ${title}| sed "s/\s\+/-/g;s/./\l&/g;s/[,.!;\"']//g"`.html - -test -z "$file" && exit 1 - -#date format for the post -date=`date +"%d %B, %Y"` - -# The format of the path to the post, here: /yyyy/mm/ -folder=`date +%Y/%m` - -# create the path if it does not exists -test -d ${folder} || mkdir -p ${folder} - -# build the whole path -post="${folder}/${file}" - -# use the templates to create the post skeleton -cat tools/{head,body,foot}.template >> ${post} - -# put the title and date in the post -sed -i "s/BLOG_TITLE/${title}/;s/BLOG_DATE/${date}/" ${post} - -test -f ${post} || echo "cannot create ${post}" && exit 1 - -echo "$post created" - -# create a symlink to the last post, to easily access it -ln -fs ${post} last_post.html diff --git a/tools/publi.sh b/tools/publi.sh @@ -1,10 +0,0 @@ -#!/bin/sh - -# Re-generate the RSS feed -tools/feeds.sh - -# Check HTML / CSS / RSS -tools/check.sh - -# Check what have changed -git status diff --git a/tools/update.sh b/tools/update.sh @@ -1,11 +0,0 @@ -#!/bin/bash - -for file in $(find . -name '*.html'); do - if [[ -n "$(cat $file|tr -d '\n' |grep -E '</header>.*<footer>')" ]]; then - cat tools/head.template > buffer.html - sed '1,/<\/header>/d;/<!-- footer/,$d' $file >> buffer.html - cat tools/foot.template >> buffer.html - - mv buffer.html $file - fi -done