Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial concept for git-weblog

  • Loading branch information...
commit df17f94ce7a63f66dc567a5f52e6bc94990897e8 1 parent e57f42d
@mikegerwitz authored
Showing with 62 additions and 0 deletions.
  1. +62 −0 bin/git-weblog
View
62 bin/git-weblog
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# Generates XHTML for each provided commit/treeish/etc
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# #
+
+# defaults
+format_subject='<h3 class="git-commit">%s</h3>'
+format_body='<div class="git-commit-body">%n<p>%b</p>%n</div>'
+parser_body=parser-default
+
+get-part()
+{
+ git log -n1 --pretty="format:$1" "$2"
+}
+
+format-body()
+{
+ local commit="$1"
+ local body=$( get-part '%b' "$commit" )
+
+ # default body text to let user know there was no body to the commit
+ [ -z "$body" ] && body="(No body)"
+
+ # to avoid having to worry about escapes and such, we will simply output
+ # everything before the %b placeholder, the parsed body and then the text
+ # after it (this is, of course, assuming that there is only one such
+ # placeholder)
+ echo -n "$format_body" | sed 's/^\(.*\)%b.*$/\1/'
+ echo -n "$body" | $parser_body
+ echo "$format_body" | sed 's/^.*%b\(.*\)$/\1/'
+}
+
+parser-default()
+{
+ # escape tags and entities, wrap paragraphs (delimited by two newlines) in <p>
+ # tags
+ sed ':a;N;$!ba;s/</&lt\;/g;s/>/&rt\;/g;s/&/&amp\;/g;s/\n\n/<\/p>\n\n<p>/g'
+}
+
+
+# generate XHTML for each provided commit/treeish/etc
+for commit in "$@"; do
+ subject=$( get-part "$format_subject" "$commit" )
+ body=$( get-part "$( format-body "$commit" )" "$commit" )
+
+ echo "$subject"
+ echo "$body"
+done
+
Please sign in to comment.
Something went wrong with that request. Please try again.