post-receive now works :-)
This commit is contained in:
parent
434d86694e
commit
5ff38e903a
99
README
99
README
|
@ -1,14 +1,24 @@
|
||||||
fugitive README file
|
fugitive: README
|
||||||
|
|
||||||
<h2 id="info">Info</h2>
|
<h2 id="info">Info</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
fugitive is a blog engine running on top of git using hooks to generate
|
fugitive is a blog engine running on top of git using hooks to generate
|
||||||
static html pages and thus having only git as dependency.
|
static html pages and thus having only git as dependency.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
In its hooks, fugitive uses only standard UNIX® tools that are included in
|
||||||
|
the GNU core-utils package, plus sh as script interpreter. That's it.<br />
|
||||||
|
Moreover, evrything that can be done using git, is.<br />
|
||||||
|
No dependencies like rack, heroku, or whatever Ruby gems you can think of. No
|
||||||
|
configuration files. No metadata in your articles files. Hell, if you want to
|
||||||
|
you could even make a <a href="#templating">template</a> that use git log as
|
||||||
|
storage backend, which means <em>no files</em> either, just and only git.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h2 id="install">Install</h2>
|
<h2 id="install">Install</h2>
|
||||||
|
|
||||||
<h3>Build</h3>
|
<h3 id="build">Build</h3>
|
||||||
<p>
|
<p>
|
||||||
If you want to build fugitive from the source, clone the git repository:
|
If you want to build fugitive from the source, clone the git repository:
|
||||||
<br />
|
<br />
|
||||||
|
@ -17,14 +27,24 @@ fugitive README file
|
||||||
Then go in the newly created directory: <code>cd fugitive</code>, and
|
Then go in the newly created directory: <code>cd fugitive</code>, and
|
||||||
run the build script: <code>./build.sh</code>.
|
run the build script: <code>./build.sh</code>.
|
||||||
<br />
|
<br />
|
||||||
This will generate an executable file "fugitive".
|
This will generate an executable file "fugitive" which you can use
|
||||||
|
to create your blog.
|
||||||
</p>
|
</p>
|
||||||
<h3>Create a blog</h3>
|
<h3 id="create">Create a blog</h3>
|
||||||
<p>
|
<p>
|
||||||
If you have the "fugitive" executable file and want to start a new
|
There's two install mode for fugitive: local and remote. The local mode
|
||||||
blog: Run <code>fugitive --install <dir></code>.
|
should be used to install a repository where you edit your blog, and the
|
||||||
|
remote mode for a repository to which you're going to push to publish your
|
||||||
|
blog.<br />
|
||||||
|
The local mode can also be used to publish if you edit your file directly on
|
||||||
|
your server.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
To create you blog run the commande:<br />
|
||||||
|
<code>fugitive --install-<em>mode</em> <dir></code>,
|
||||||
|
where <em>mode</em> is either "local" or "remote"
|
||||||
<br />
|
<br />
|
||||||
This will create the git repos with appropriate hooks and files in
|
This will create the git repos with appropriate hooks, config and files in
|
||||||
<dir>.
|
<dir>.
|
||||||
<br />
|
<br />
|
||||||
If <dir> isn't specified then the current working directory is used.
|
If <dir> isn't specified then the current working directory is used.
|
||||||
|
@ -34,24 +54,14 @@ fugitive README file
|
||||||
parameter in your git configuration. See <a href="#config">configuration</a>
|
parameter in your git configuration. See <a href="#config">configuration</a>
|
||||||
for details.
|
for details.
|
||||||
</p>
|
</p>
|
||||||
<p class="note">
|
|
||||||
You need to use the same process to install any remote
|
|
||||||
repository where you'd like to push your blog.
|
|
||||||
</p>
|
|
||||||
<h3>Update</h3>
|
|
||||||
<p>
|
|
||||||
Run <code>fugitive --install-hooks <dir></code>.<br />
|
|
||||||
This will only (re)install fugitive hooks scripts.<br />
|
|
||||||
If <dir> isn't specified then the current working directory is used.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h2 id="config">Configuration</h2>
|
<h2 id="config">Configuration</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
All this settings are in the "fugitive" section of the git config.
|
All this settings are in the "fugitive" section of the git config.
|
||||||
You can change them with the command <code>git config
|
You can change them with the command <br />
|
||||||
fugitive.<em>parameter</em> <em>value</em></code>, where <em>parameter</em>
|
<code>git config fugitive.<em>parameter</em> <em>value</em></code>,
|
||||||
is one of the following:
|
where <em>parameter</em> is one of the following:
|
||||||
</p>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>blog-url</dt>
|
<dt>blog-url</dt>
|
||||||
|
@ -60,24 +70,22 @@ fugitive README file
|
||||||
it</strong> as soon as possible since it's required for the RSS feed (and
|
it</strong> as soon as possible since it's required for the RSS feed (and
|
||||||
used in the default template's footer).
|
used in the default template's footer).
|
||||||
</dd>
|
</dd>
|
||||||
<dt>public-dir</dt>
|
<dt>public-dir*</dt>
|
||||||
<dd>
|
<dd>
|
||||||
This is the path to the directory that will contain the generated html
|
This is the path to the directory that will contain the generated html
|
||||||
files. Defautlt value is ".", the root of the git repository. You
|
files. Default value is "_public". You could set it to
|
||||||
could set it to "blog" for instance if you already have a static
|
"_public/blog" for instance if you want to have have a website in
|
||||||
website under your git repos.
|
"_public" and your blog in "/blog".
|
||||||
</dd>
|
</dd>
|
||||||
<dt>articles-dir</dt>
|
<dt>articles-dir*</dt>
|
||||||
<dd>
|
<dd>
|
||||||
This is the path where fugitive will look for published articles. Default
|
This is the path where fugitive will look for published articles. Default
|
||||||
value is "_articles". This path is relative to the root of the
|
value is "_articles".
|
||||||
git repository, must be in it and must not start with ".".
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt>templates-dire</dt>
|
<dt>templates-dire*</dt>
|
||||||
<dd>
|
<dd>
|
||||||
This is the path where fugitive will look for templates files. Default
|
This is the path where fugitive will look for templates files. Default
|
||||||
value is "_templates". This path is relative to the root of the
|
value is "_templates".
|
||||||
git repository, must be in it and must not start with ".".
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt>preproc</dt>
|
<dt>preproc</dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
@ -87,23 +95,38 @@ fugitive README file
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<p class="note">
|
<p class="note">
|
||||||
You must NOT put a trailing '/' at the end of any of the path.
|
* Those paths are relative to the root of the git repository, must be in it
|
||||||
|
and must not start with "." neither have a '/' at the end. Example:
|
||||||
|
"dir/subdir" is valid but "./dir/subdir" and
|
||||||
|
"dir/subdir/" are not.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 id="usage">Usage</h2>
|
<h2 id="usage">Usage</h2>
|
||||||
|
|
||||||
<h3>General use</h3>
|
<h3 id="general-use">General use</h3>
|
||||||
<p>
|
<p>
|
||||||
Article you want to publish should be file without the .html extension in the
|
Article you want to publish should be file without the .html extension in the
|
||||||
<em>articles-dir</em> directory (see CONFIGURATION).
|
<em>articles-dir</em> directory (see CONFIGURATION). The first line of the
|
||||||
|
file will be used as title and the rest of the file as the content of the
|
||||||
|
article.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
The first line of the file will be used as title and the rest of the file as
|
By default there's a "_drafts" directory in which you can put
|
||||||
the content.
|
articles you are writing and you want to version control in your git
|
||||||
|
repository but you don't want to publish yet.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
When you commit, <em>*TODO*: explain the process</em>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
When you push to a remote repository installed with fugitive, the same thing
|
||||||
|
will happen but instead of looking only at the last commit, the hooks will
|
||||||
|
analyse every change since the last push and then (re)generate html files
|
||||||
|
accordingly.
|
||||||
</p>
|
</p>
|
||||||
<p class="warning">
|
<p class="warning">
|
||||||
DO NOT CREATE AN ARTICLE FILE NAMED "archives".<br />
|
Do not create an article file named "archives".<br />
|
||||||
DO NOT CREATE AN ARTICLE FILE NAMED "index".
|
Do not create an article file named "index".
|
||||||
</p>
|
</p>
|
||||||
<h3>Template system</h3>
|
<h3 id="templating">Template system</h3>
|
||||||
<p><em>*TODO*</em></p>
|
<p><em>*TODO*</em></p>
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -12,7 +12,7 @@ include_file() {
|
||||||
|
|
||||||
cp install.sh tmp1
|
cp install.sh tmp1
|
||||||
i=1
|
i=1
|
||||||
for f in README post-commit.sh post-receive.sh default-files/*; do
|
for f in README post-commit.sh post-receive.sh html-gen.sh default-files/*; do
|
||||||
j=$((1 - i))
|
j=$((1 - i))
|
||||||
include_file tmp$i "$f" > tmp$j
|
include_file tmp$i "$f" > tmp$j
|
||||||
i=$j
|
i=$j
|
||||||
|
|
|
@ -0,0 +1,367 @@
|
||||||
|
blog_url=`git config --get fugitive.blog-url`
|
||||||
|
if [ "$blog_url" = "" ]; then
|
||||||
|
echo -n "[fugitive] WARNING: git config fugitive.blog-url is empty and "
|
||||||
|
echo "should not be, please set it as soon as possible."
|
||||||
|
fi
|
||||||
|
templates_dir=`git config --get fugitive.templates-dir`
|
||||||
|
public_dir=`git config --get fugitive.public-dir`
|
||||||
|
if [ ! -d "$public_dir" ]; then mkdir -p "$public_dir"; fi
|
||||||
|
articles_dir=`git config --get fugitive.articles-dir`
|
||||||
|
preproc=`git config --get fugitive.preproc`
|
||||||
|
|
||||||
|
generated_files=`mktemp --suffix "-fugitive"`
|
||||||
|
|
||||||
|
articles_sorted=`mktemp --suffix "-fugitive"`
|
||||||
|
for f in "$articles_dir"/*; do
|
||||||
|
ts=`git log --format="%at" -- "$f" | tail -1`
|
||||||
|
if [ "$ts" != "" ]; then
|
||||||
|
echo "$ts ${f#$articles_dir/}"
|
||||||
|
fi
|
||||||
|
done | sort -nr | cut -d' ' -f2 > "$articles_sorted"
|
||||||
|
|
||||||
|
articles_sorted_with_delete=`mktemp --suffix "-fugitive"`
|
||||||
|
for f in "$articles_dir"/* $deleted_files; do
|
||||||
|
ts=`git log --format="%at" -- "$f" | tail -1`
|
||||||
|
if [ "$ts" != "" ]; then
|
||||||
|
echo "$ts ${f#$articles_dir/}"
|
||||||
|
fi
|
||||||
|
done | sort -nr | cut -d' ' -f2 > "$articles_sorted_with_delete"
|
||||||
|
|
||||||
|
commits=`mktemp --suffix "-fugitive"`
|
||||||
|
git log --oneline | cut -d' ' -f1 > "$commits"
|
||||||
|
|
||||||
|
get_article_info() {
|
||||||
|
git log --format="$1" -- "$articles_dir/$2"
|
||||||
|
}
|
||||||
|
get_article_next_file() {
|
||||||
|
next=`grep -B1 "$1" "$articles_sorted" | head -1`
|
||||||
|
if [ "$next" != "$1" ]; then
|
||||||
|
echo "$next"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
get_article_previous_file() {
|
||||||
|
previous=`grep -A1 "$1" "$articles_sorted" | tail -1`
|
||||||
|
if [ "$previous" != "$1" ]; then
|
||||||
|
echo "$previous"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
get_deleted_next_file() {
|
||||||
|
next=`grep -B1 "$1" "$articles_sorted_with_delete" | head -1`
|
||||||
|
if [ "`echo $deleted_files | grep -c \"$next\"`" = "0" ]; then
|
||||||
|
echo "$next"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
get_deleted_previous_file() {
|
||||||
|
previous=`grep -A1 "$1" "$articles_sorted_with_delete" | tail -1`
|
||||||
|
if [ "`echo $deleted_files | grep -c \"$previous\"`" = "0" ]; then
|
||||||
|
echo "$previous"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
get_article_title() {
|
||||||
|
if [ "$1" != "" ]; then
|
||||||
|
head -1 "$articles_dir/$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
get_article_content() {
|
||||||
|
tmp=`mktemp --suffix "-fugitive"`
|
||||||
|
tail -n+2 "$articles_dir/$1" > "$tmp"
|
||||||
|
echo "$tmp"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_commit_info() {
|
||||||
|
git show --quiet --format="$1" "$2"
|
||||||
|
}
|
||||||
|
get_commit_body() {
|
||||||
|
tmp=`mktemp --suffix "-fugitive"`
|
||||||
|
git show --quiet --format="%b" "$1" > "$tmp"
|
||||||
|
if [ "`cat \"$tmp\" | sed \"/^$/d\" | wc -l`" != "0" ]; then
|
||||||
|
echo "$tmp"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
sanit_mail() {
|
||||||
|
sed "s/@/[at]/;s/\./(dot)/"
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_condition() {
|
||||||
|
if [ "$2" = "" ]; then
|
||||||
|
sed "s/<?fugitive\s\+\(end\)\?ifset:$1\s*?>/\n\0\n/g" | \
|
||||||
|
sed "/<?fugitive\s\+ifset:$1\s*?>/,/<?fugitive\s\+endifset:$1\s*?>/bdel
|
||||||
|
b
|
||||||
|
:del
|
||||||
|
s/<?fugitive\s\+endifset:$1\s*?>.*//
|
||||||
|
/<?fugitive\s\+endifset:$1\s*?>/b
|
||||||
|
d"
|
||||||
|
else
|
||||||
|
sed "s/<?fugitive\s\+\(end\)\?ifset:$1\s*?>//"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_str() {
|
||||||
|
esc=`echo $2 | sed 's/\//\\\\\//g'`
|
||||||
|
replace_condition "$1" "$2" | \
|
||||||
|
sed "s/<?fugitive\s\+$1\s*?>/$esc/g"
|
||||||
|
}
|
||||||
|
|
||||||
|
# REMEMBER: 2nd arg should be a tempfile!
|
||||||
|
replace_file() {
|
||||||
|
if [ -f "$2" ]; then
|
||||||
|
sed "s/<?fugitive\s\+$1\s*?>/\n\0\n/g" | \
|
||||||
|
sed "/<?fugitive\s\+$1\s*?>/ {
|
||||||
|
r $2
|
||||||
|
d }"
|
||||||
|
rm "$2"
|
||||||
|
else
|
||||||
|
cat
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_includes() {
|
||||||
|
buf=`mktemp --suffix "-fugitive"`
|
||||||
|
buf2=`mktemp --suffix "-fugitive"`
|
||||||
|
cat > "$buf"
|
||||||
|
includes=`cat "$buf" | \
|
||||||
|
sed "s/<?fugitive\s\+include:.\+\s*?>/\n\0\n/g" | \
|
||||||
|
grep -E "<\?fugitive\s+include:.+\s*\?>" | \
|
||||||
|
sed "s/^<?fugitive\s\+include://;s/\s*?>$//"`
|
||||||
|
for i in $includes; do
|
||||||
|
esc=`echo -n $i | sed 's/\//\\\\\//g'`
|
||||||
|
inc="$templates_dir/$i"
|
||||||
|
cat "$buf" | \
|
||||||
|
sed "/<?fugitive\s\+include:$esc\s*?>/ {
|
||||||
|
r $inc
|
||||||
|
d }" > "$buf2"
|
||||||
|
tmpbuf="$buf"
|
||||||
|
buf="$buf2"
|
||||||
|
buf2="$tmpbuf"
|
||||||
|
done
|
||||||
|
cat "$buf"
|
||||||
|
rm "$buf" "$buf2"
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_commit_info() {
|
||||||
|
commit_Hash=`get_commit_info "%H" "$1"`
|
||||||
|
commit_hash=`get_commit_info "%h" "$1"`
|
||||||
|
commit_author=`get_commit_info "%an" "$1"`
|
||||||
|
commit_author_email=`get_commit_info "%ae" "$1" | sanit_mail`
|
||||||
|
commit_datetime=`get_commit_info "%ai" "$1"`
|
||||||
|
commit_date=`echo $commit_datetime | cut -d' ' -f1`
|
||||||
|
commit_time=`echo $commit_datetime | cut -d' ' -f2`
|
||||||
|
commit_timestamp=`get_commit_info "%at" "$1"`
|
||||||
|
commit_subject=`get_commit_info "%s" "$1"`
|
||||||
|
commit_slug=`get_commit_info "%f" "$1"`
|
||||||
|
commit_body=`get_commit_body "$1"`
|
||||||
|
|
||||||
|
replace_str "commit_Hash" "$commit_Hash" | \
|
||||||
|
replace_str "commit_hash" "$commit_hash" | \
|
||||||
|
replace_str "commit_author" "$commit_author" | \
|
||||||
|
replace_str "commit_author_email" "$commit_author_email" | \
|
||||||
|
replace_str "commit_datetime" "$commit_datetime" | \
|
||||||
|
replace_str "commit_date" "$commit_date" | \
|
||||||
|
replace_str "commit_time" "$commit_time" | \
|
||||||
|
replace_str "commit_timestamp" "$commit_timestamp" | \
|
||||||
|
replace_str "commit_subject" "$commit_subject" | \
|
||||||
|
replace_str "commit_slug" "$commit_slug" | \
|
||||||
|
replace_file "commit_body" "$commit_body"
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_article_info() {
|
||||||
|
article_title=`get_article_title "$1"`
|
||||||
|
article_cdatetime=`get_article_info "%ai" "$1" | tail -1`
|
||||||
|
article_cdate=`echo "$article_cdatetime" | cut -d' ' -f1`
|
||||||
|
article_ctime=`echo "$article_cdatetime" | cut -d' ' -f2`
|
||||||
|
article_ctimestamp=`get_article_info "%at" "$1" | tail -1`
|
||||||
|
u=`get_article_info "%ai" "$1" | wc -l`
|
||||||
|
article_mdatetime=`if test "$u" -gt 1; then get_article_info "%ai" "$1" | \
|
||||||
|
head -1; fi`
|
||||||
|
article_mdate=`echo "$article_mdatetime" | cut -d' ' -f1`
|
||||||
|
article_mtime=`echo "$article_mdatetime" | cut -d' ' -f2`
|
||||||
|
article_mtimestamp=`if test "$u" -gt 1; then get_article_info "%at" \
|
||||||
|
"$1" | head -1; fi`
|
||||||
|
article_cauthor=`get_article_info "%an" "$1" | tail -1`
|
||||||
|
article_cauthor_email=`get_article_info "%ae" "$1" | tail -1 | sanit_mail`
|
||||||
|
article_mauthor=`get_article_info "%an" "$1" | head -1`
|
||||||
|
article_mauthor_email=`get_article_info "%ae" "$1" | head -1 | sanit_mail`
|
||||||
|
article_previous_file=`get_article_previous_file "$1"`
|
||||||
|
article_previous_title=`get_article_title "$article_previous_file"`
|
||||||
|
article_next_file=`get_article_next_file "$1"`
|
||||||
|
article_next_title=`get_article_title "$article_next_file"`
|
||||||
|
|
||||||
|
replace_file "article_content" "`get_article_content \"$1\"`" | \
|
||||||
|
replace_str "article_file" "$1" | \
|
||||||
|
replace_str "article_title" "$article_title" | \
|
||||||
|
replace_str "article_cdatetime" "$article_cdatetime" | \
|
||||||
|
replace_str "article_cdate" "$article_cdate" | \
|
||||||
|
replace_str "article_ctime" "$article_ctime" | \
|
||||||
|
replace_str "article_ctimestamp" "$article_ctimestamp" | \
|
||||||
|
replace_str "article_mdatetime" "$article_mdatetime" | \
|
||||||
|
replace_str "article_mdate" "$article_mdate" | \
|
||||||
|
replace_str "article_mtime" "$article_mtime" | \
|
||||||
|
replace_str "article_mtimestamp" "$article_mtimestamp" | \
|
||||||
|
replace_str "article_cauthor" "$article_cauthor" | \
|
||||||
|
replace_str "article_cauthor_email" "$article_cauthor_email" | \
|
||||||
|
replace_str "article_mauthor" "$article_mauthor" | \
|
||||||
|
replace_str "article_mauthor_email" "$article_mauthor_email" | \
|
||||||
|
replace_str "article_previous_file" "$article_previous_file" | \
|
||||||
|
replace_str "article_previous_title" "$article_previous_title" | \
|
||||||
|
replace_str "article_next_file" "$article_next_file" | \
|
||||||
|
replace_str "article_next_title" "$article_next_title"
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_empty_article_info() {
|
||||||
|
replace_str "article_file" "" | \
|
||||||
|
replace_str "article_title" "" | \
|
||||||
|
replace_str "article_cdatetime" "" | \
|
||||||
|
replace_str "article_cdate" "" | \
|
||||||
|
replace_str "article_ctime" "" | \
|
||||||
|
replace_str "article_ctimestamp" "" | \
|
||||||
|
replace_str "article_mdatetime" "" | \
|
||||||
|
replace_str "article_mdate" "" | \
|
||||||
|
replace_str "article_mtime" "" | \
|
||||||
|
replace_str "article_mtimestamp" "" | \
|
||||||
|
replace_str "article_cauthor" "" | \
|
||||||
|
replace_str "article_cauthor_email" "" | \
|
||||||
|
replace_str "article_mauthor" "" | \
|
||||||
|
replace_str "article_mauthor_email" "" | \
|
||||||
|
replace_str "article_previous_file" "" | \
|
||||||
|
replace_str "article_previous_title" "" | \
|
||||||
|
replace_str "article_next_file" "" | \
|
||||||
|
replace_str "article_next_title" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_foreach () {
|
||||||
|
foreach_body=`mktemp --suffix "-fugitive"`
|
||||||
|
tmpfile=`mktemp --suffix "-fugitive"`
|
||||||
|
temp=`mktemp --suffix "-fugitive"`
|
||||||
|
fe="foreach:$1"
|
||||||
|
cat > "$temp"
|
||||||
|
cat "$temp" | \
|
||||||
|
sed -n "/<?fugitive\s\+$fe\s*?>/,/<?fugitive\s\+end$fe\s*?>/p" | \
|
||||||
|
tail -n +2 | head -n -1 > "$foreach_body"
|
||||||
|
if [ ! -s "$foreach_body" ]; then
|
||||||
|
cat "$temp"
|
||||||
|
rm "$foreach_body" "$tmpfile" "$temp"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
cat "$temp" | \
|
||||||
|
sed "s/<?fugitive\s\+$fe\s*?>/<?fugitive foreach_body ?>\n\0/" | \
|
||||||
|
sed "/<?fugitive\s\+$fe\s*?>/,/<?fugitive\s\+end$fe\s*?>/d" | \
|
||||||
|
cat > "$tmpfile"
|
||||||
|
for i in `cat "$2"`; do
|
||||||
|
cat "$foreach_body" | replace_$1_info "$i"
|
||||||
|
done > "$temp"
|
||||||
|
cat "$tmpfile" | replace_file "foreach_body" "$temp"
|
||||||
|
rm "$foreach_body" "$tmpfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_article() {
|
||||||
|
if [ "$preproc" != "" ]; then
|
||||||
|
preproc_bak=`mktemp --suffix "-fugitive" -d "$articles_dir"`
|
||||||
|
mv "$1" "$preproc_bak"
|
||||||
|
($preproc) < "$preproc_bak" > "$1"
|
||||||
|
fi
|
||||||
|
art="${1#$articles_dir/}"
|
||||||
|
cat "$templates_dir/article.html" | \
|
||||||
|
replace_includes | \
|
||||||
|
replace_str "page_title" "`get_article_title \"$art\"`" | \
|
||||||
|
replace_str "blog_url" "$blog_url" | \
|
||||||
|
replace_commit_info "-1" | \
|
||||||
|
replace_article_info "$art" | \
|
||||||
|
sed "/^\s*$/d" > "$public_dir/$art.html"
|
||||||
|
if [ "$preproc" != "" ]; then mv "$preproc_bak" "$1"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
regenerate_previous_and_next_article_maybe() {
|
||||||
|
if [ "$1" != "" -a \
|
||||||
|
"`grep -c \"$1\" \"$generated_files\"`" = "0" ]; then
|
||||||
|
echo -n "[fugitive] Regenerating $public_dir/$1.html"
|
||||||
|
echo -n " (as previous article) from $articles_dir/$1... "
|
||||||
|
generate_article "$articles_dir/$1"
|
||||||
|
echo "done."
|
||||||
|
echo "$1" >> "$generated_files"
|
||||||
|
fi
|
||||||
|
if [ "$2" != "" -a \
|
||||||
|
"`grep -c \"$2\" \"$generated_files\"`" = "0" ]; then
|
||||||
|
echo -n "[fugitive] Regenerating $public_dir/$2.html"
|
||||||
|
echo -n " (as next article) from $articles_dir/$2... "
|
||||||
|
generate_article "$articles_dir/$2"
|
||||||
|
echo "done."
|
||||||
|
echo "$2" >> "$generated_files"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
modification=0
|
||||||
|
|
||||||
|
for f in $added_files $modified_files; do
|
||||||
|
if [ "$f" != "${f#$articles_dir}" ]; then
|
||||||
|
modification=$((modification + 1))
|
||||||
|
echo -n "[fugitive] Generating $public_dir/${f#$articles_dir/}.html from"
|
||||||
|
echo -n " $f... "
|
||||||
|
generate_article "$f"
|
||||||
|
echo "done."
|
||||||
|
echo "${f#$articles_dir/}" >> "$generated_files"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for f in $added_files; do
|
||||||
|
if [ "$f" != "${f#$articles_dir}" ]; then
|
||||||
|
art="${f#$articles_dir/}"
|
||||||
|
echo -n "[fugitive] Adding $public_dir/$art.html to git ignore list... "
|
||||||
|
echo "$public_dir/$art.html" >> .git/info/exclude
|
||||||
|
echo "done."
|
||||||
|
previous=`get_article_previous_file "$art"`
|
||||||
|
next=`get_article_next_file "$art"`
|
||||||
|
regenerate_previous_and_next_article_maybe "$previous" "$next"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for f in $deleted_files; do
|
||||||
|
if [ "$f" != "${f#$articles_dir}" ]; then
|
||||||
|
modification=$((modification + 1))
|
||||||
|
art="${f#$articles_dir/}"
|
||||||
|
echo -n "[fugitive] Deleting $public_dir/$art.html... "
|
||||||
|
rm "$public_dir/$art.html"
|
||||||
|
echo "done."
|
||||||
|
echo -n "[fugitive] Removing $art.html from git ignore list... "
|
||||||
|
sed -i "/^$public_dir\/$art.html$/d" .git/info/exclude
|
||||||
|
echo "done."
|
||||||
|
previous=`get_deleted_previous_file "$art"`
|
||||||
|
next=`get_deleted_next_file "$art"`
|
||||||
|
regenerate_previous_and_next_article_maybe "$previous" "$next"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $modification -gt 0 ]; then
|
||||||
|
echo -n "[fugitive] Generating $public_dir/archives.html... "
|
||||||
|
cat "$templates_dir/archives.html" | \
|
||||||
|
replace_includes | \
|
||||||
|
replace_foreach "article" "$articles_sorted" | \
|
||||||
|
replace_foreach "commit" "$commits" | \
|
||||||
|
replace_empty_article_info | \
|
||||||
|
replace_str "page_title" "archives" | \
|
||||||
|
replace_str "blog_url" "$blog_url" | \
|
||||||
|
replace_commit_info "-1" | \
|
||||||
|
sed "/^\s*$/d" > "$public_dir/archives.html"
|
||||||
|
echo "done."
|
||||||
|
echo -n "[fugitive] Generating $public_dir/feed.xml... "
|
||||||
|
last_5_articles=`mktemp --suffix "-fugitive"`
|
||||||
|
head -5 "$articles_sorted" > "$last_5_articles"
|
||||||
|
last_5_commits=`mktemp --suffix "-fugitive"`
|
||||||
|
head -5 "$commits" > "$last_5_commits"
|
||||||
|
cat "$templates_dir/feed.xml" | \
|
||||||
|
replace_foreach "article" "$last_5_articles" | \
|
||||||
|
replace_foreach "commit" "$last_5_commits" | \
|
||||||
|
replace_str "blog_url" "$blog_url" | \
|
||||||
|
replace_commit_info "-1" | \
|
||||||
|
sed "/^\s*$/d" > "$public_dir/feed.xml"
|
||||||
|
echo "done."
|
||||||
|
rm "$last_5_articles" "$last_5_commits"
|
||||||
|
echo -n "[fugitive] Using last published article as index page... "
|
||||||
|
cp "$public_dir/`head -1 $articles_sorted`.html" "$public_dir/index.html"
|
||||||
|
echo "done".
|
||||||
|
echo "[fugitive] Blog update complete."
|
||||||
|
fi
|
||||||
|
rm "$articles_sorted"
|
||||||
|
rm "$articles_sorted_with_delete"
|
||||||
|
rm "$commits"
|
||||||
|
rm "$generated_files"
|
13
install.sh
13
install.sh
|
@ -15,10 +15,14 @@ fugitive_install_hooks() {
|
||||||
(base64 -d | gunzip) > .git/hooks/post-commit <<EOF
|
(base64 -d | gunzip) > .git/hooks/post-commit <<EOF
|
||||||
#INCLUDE:post-commit.sh#
|
#INCLUDE:post-commit.sh#
|
||||||
EOF
|
EOF
|
||||||
chmod +x .git/hooks/post-commit
|
|
||||||
(base64 -d | gunzip) > .git/hooks/post-receive <<EOF
|
(base64 -d | gunzip) > .git/hooks/post-receive <<EOF
|
||||||
#INCLUDE:post-receive.sh#
|
#INCLUDE:post-receive.sh#
|
||||||
EOF
|
EOF
|
||||||
|
(base64 -d | gunzip | \
|
||||||
|
tee -a .git/hooks/post-commit) >> .git/hooks/post-receive <<EOF
|
||||||
|
#INCLUDE:html-gen.sh#
|
||||||
|
EOF
|
||||||
|
chmod +x .git/hooks/post-commit
|
||||||
chmod +x .git/hooks/post-receive
|
chmod +x .git/hooks/post-receive
|
||||||
echo "done."
|
echo "done."
|
||||||
}
|
}
|
||||||
|
@ -85,7 +89,7 @@ EOF
|
||||||
echo "done."
|
echo "done."
|
||||||
echo -n "Importing files into git repository... "
|
echo -n "Importing files into git repository... "
|
||||||
git add _templates/* _public/*.css >/dev/null
|
git add _templates/* _public/*.css >/dev/null
|
||||||
git commit -m "fugitive inital import" >/dev/null
|
git commit -m "fugitive inital import" &>/dev/null
|
||||||
echo "done."
|
echo "done."
|
||||||
echo "Writing dummy article (README) and adding it to the repos... "
|
echo "Writing dummy article (README) and adding it to the repos... "
|
||||||
(base64 -d | gunzip) > _articles/README <<EOF
|
(base64 -d | gunzip) > _articles/README <<EOF
|
||||||
|
@ -95,12 +99,13 @@ EOF
|
||||||
git ci -m "fugitive: README" >/dev/null
|
git ci -m "fugitive: README" >/dev/null
|
||||||
echo "done."
|
echo "done."
|
||||||
fi
|
fi
|
||||||
|
echo "Installation complete, please set your blog url using"
|
||||||
|
echo '`git config fugitive.blog-url "<url>"`.'
|
||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
echo 'Installation almost complete, please visit your blog :-).'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"--help") fugitive_help >&2;;
|
"--help"|"-h") fugitive_help >&2;;
|
||||||
"--install"|"--install-local") fugitive_install "$2" "local";;
|
"--install"|"--install-local") fugitive_install "$2" "local";;
|
||||||
"--install-remote") fugitive_install "$2" "remote";;
|
"--install-remote") fugitive_install "$2" "remote";;
|
||||||
"--install-hooks") fugitive_install_hooks "$2";;
|
"--install-hooks") fugitive_install_hooks "$2";;
|
||||||
|
|
364
post-commit.sh
364
post-commit.sh
|
@ -6,367 +6,3 @@ modified_files=`git log -1 --name-status --pretty="format:" | grep -E '^M' | \
|
||||||
cut -f2`
|
cut -f2`
|
||||||
deleted_files=`git log -1 --name-status --pretty="format:" | grep -E '^D' | \
|
deleted_files=`git log -1 --name-status --pretty="format:" | grep -E '^D' | \
|
||||||
cut -f2`
|
cut -f2`
|
||||||
|
|
||||||
blog_url=`git config --get fugitive.blog-url`
|
|
||||||
public_dir=`git config --get fugitive.public-dir`
|
|
||||||
if [ ! -d "$public_dir" ]; then mkdir -p "$public_dir"; fi
|
|
||||||
templates_dir=`git config --get fugitive.templates-dir`
|
|
||||||
articles_dir=`git config --get fugitive.articles-dir`
|
|
||||||
preproc=`git config --get fugitive.preproc`
|
|
||||||
|
|
||||||
generated_files=`mktemp --suffix "-fugitive"`
|
|
||||||
|
|
||||||
articles_sorted=`mktemp --suffix "-fugitive"`
|
|
||||||
for f in $articles_dir/*; do
|
|
||||||
ts=`git log --format="%at" -- "$f" | tail -1`
|
|
||||||
if [ "$ts" != "" ]; then
|
|
||||||
echo "$ts ${f#$articles_dir/}"
|
|
||||||
fi
|
|
||||||
done | sort -nr | cut -d' ' -f2 > "$articles_sorted"
|
|
||||||
|
|
||||||
articles_sorted_with_delete=`mktemp --suffix "-fugitive"`
|
|
||||||
for f in $articles_dir/* $deleted_files; do
|
|
||||||
ts=`git log --format="%at" -- "$f" | tail -1`
|
|
||||||
if [ "$ts" != "" ]; then
|
|
||||||
echo "$ts ${f#$articles_dir/}"
|
|
||||||
fi
|
|
||||||
done | sort -nr | cut -d' ' -f2 > "$articles_sorted_with_delete"
|
|
||||||
|
|
||||||
commits=`mktemp --suffix "-fugitive"`
|
|
||||||
git log --oneline | cut -d' ' -f1 > "$commits"
|
|
||||||
|
|
||||||
get_article_info() {
|
|
||||||
git log --format="$1" -- "$articles_dir/$2"
|
|
||||||
}
|
|
||||||
get_article_next_file() {
|
|
||||||
next=`grep -B1 "$1" "$articles_sorted" | head -1`
|
|
||||||
if [ "$next" != "$1" ]; then
|
|
||||||
echo "$next"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
get_article_previous_file() {
|
|
||||||
previous=`grep -A1 "$1" "$articles_sorted" | tail -1`
|
|
||||||
if [ "$previous" != "$1" ]; then
|
|
||||||
echo "$previous"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
get_deleted_next_file() {
|
|
||||||
next=`grep -B1 "$1" "$articles_sorted_with_delete" | head -1`
|
|
||||||
if [ "`echo $deleted_files | grep -c \"$next\"`" = "0" ]; then
|
|
||||||
echo "$next"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
get_deleted_previous_file() {
|
|
||||||
previous=`grep -A1 "$1" "$articles_sorted_with_delete" | tail -1`
|
|
||||||
if [ "`echo $deleted_files | grep -c \"$previous\"`" = "0" ]; then
|
|
||||||
echo "$previous"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
get_article_title() {
|
|
||||||
if [ "$1" != "" ]; then
|
|
||||||
head -1 "$articles_dir/$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
get_article_content() {
|
|
||||||
tmp=`mktemp --suffix "-fugitive"`
|
|
||||||
tail -n+2 "$articles_dir/$1" > "$tmp"
|
|
||||||
echo "$tmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
get_commit_info() {
|
|
||||||
git show --quiet --format="$1" "$2"
|
|
||||||
}
|
|
||||||
get_commit_body() {
|
|
||||||
tmp=`mktemp --suffix "-fugitive"`
|
|
||||||
git show --quiet --format="%b" "$1" > "$tmp"
|
|
||||||
if [ "`cat \"$tmp\" | sed \"/^$/d\" | wc -l`" != "0" ]; then
|
|
||||||
echo "$tmp"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
sanit_mail() {
|
|
||||||
sed "s/@/[at]/;s/\./(dot)/"
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_condition() {
|
|
||||||
if [ "$2" = "" ]; then
|
|
||||||
sed "s/<?fugitive\s\+\(end\)\?ifset:$1\s*?>/\n\0\n/g" | \
|
|
||||||
sed "/<?fugitive\s\+ifset:$1\s*?>/,/<?fugitive\s\+endifset:$1\s*?>/bdel
|
|
||||||
b
|
|
||||||
:del
|
|
||||||
s/<?fugitive\s\+endifset:$1\s*?>.*//
|
|
||||||
/<?fugitive\s\+endifset:$1\s*?>/b
|
|
||||||
d"
|
|
||||||
else
|
|
||||||
sed "s/<?fugitive\s\+\(end\)\?ifset:$1\s*?>//"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_str() {
|
|
||||||
esc=`echo $2 | sed 's/\//\\\\\//g'`
|
|
||||||
replace_condition "$1" "$2" | \
|
|
||||||
sed "s/<?fugitive\s\+$1\s*?>/$esc/g"
|
|
||||||
}
|
|
||||||
|
|
||||||
# REMEMBER: 2nd arg should be a tempfile!
|
|
||||||
replace_file() {
|
|
||||||
if [ -f "$2" ]; then
|
|
||||||
sed "s/<?fugitive\s\+$1\s*?>/\n\0\n/g" | \
|
|
||||||
sed "/<?fugitive\s\+$1\s*?>/ {
|
|
||||||
r $2
|
|
||||||
d }"
|
|
||||||
rm "$2"
|
|
||||||
else
|
|
||||||
cat
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_includes() {
|
|
||||||
buf=`mktemp --suffix "-fugitive"`
|
|
||||||
buf2=`mktemp --suffix "-fugitive"`
|
|
||||||
cat > "$buf"
|
|
||||||
includes=`cat "$buf" | \
|
|
||||||
sed "s/<?fugitive\s\+include:.\+\s*?>/\n\0\n/g" | \
|
|
||||||
grep -E "<\?fugitive\s+include:.+\s*\?>" | \
|
|
||||||
sed "s/^<?fugitive\s\+include://;s/\s*?>$//"`
|
|
||||||
for i in $includes; do
|
|
||||||
esc=`echo -n $i | sed 's/\//\\\\\//g'`
|
|
||||||
inc="$templates_dir/$i"
|
|
||||||
cat "$buf" | \
|
|
||||||
sed "/<?fugitive\s\+include:$esc\s*?>/ {
|
|
||||||
r $inc
|
|
||||||
d }" > "$buf2"
|
|
||||||
tmpbuf="$buf"
|
|
||||||
buf="$buf2"
|
|
||||||
buf2="$tmpbuf"
|
|
||||||
done
|
|
||||||
cat "$buf"
|
|
||||||
rm "$buf" "$buf2"
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_commit_info() {
|
|
||||||
commit_Hash=`get_commit_info "%H" "$1"`
|
|
||||||
commit_hash=`get_commit_info "%h" "$1"`
|
|
||||||
commit_author=`get_commit_info "%an" "$1"`
|
|
||||||
commit_author_email=`get_commit_info "%ae" "$1" | sanit_mail`
|
|
||||||
commit_datetime=`get_commit_info "%ai" "$1"`
|
|
||||||
commit_date=`echo $commit_datetime | cut -d' ' -f1`
|
|
||||||
commit_time=`echo $commit_datetime | cut -d' ' -f2`
|
|
||||||
commit_timestamp=`get_commit_info "%at" "$1"`
|
|
||||||
commit_subject=`get_commit_info "%s" "$1"`
|
|
||||||
commit_slug=`get_commit_info "%f" "$1"`
|
|
||||||
commit_body=`get_commit_body "$1"`
|
|
||||||
|
|
||||||
replace_str "commit_Hash" "$commit_Hash" | \
|
|
||||||
replace_str "commit_hash" "$commit_hash" | \
|
|
||||||
replace_str "commit_author" "$commit_author" | \
|
|
||||||
replace_str "commit_author_email" "$commit_author_email" | \
|
|
||||||
replace_str "commit_datetime" "$commit_datetime" | \
|
|
||||||
replace_str "commit_date" "$commit_date" | \
|
|
||||||
replace_str "commit_time" "$commit_time" | \
|
|
||||||
replace_str "commit_timestamp" "$commit_timestamp" | \
|
|
||||||
replace_str "commit_subject" "$commit_subject" | \
|
|
||||||
replace_str "commit_slug" "$commit_slug" | \
|
|
||||||
replace_file "commit_body" "$commit_body"
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_article_info() {
|
|
||||||
article_title=`get_article_title "$1"`
|
|
||||||
article_cdatetime=`get_article_info "%ai" "$1" | tail -1`
|
|
||||||
article_cdate=`echo "$article_cdatetime" | cut -d' ' -f1`
|
|
||||||
article_ctime=`echo "$article_cdatetime" | cut -d' ' -f2`
|
|
||||||
article_ctimestamp=`get_article_info "%at" "$1" | tail -1`
|
|
||||||
u=`get_article_info "%ai" "$1" | wc -l`
|
|
||||||
article_mdatetime=`if test "$u" -gt 1; then get_article_info "%ai" "$1" | \
|
|
||||||
head -1; fi`
|
|
||||||
article_mdate=`echo "$article_mdatetime" | cut -d' ' -f1`
|
|
||||||
article_mtime=`echo "$article_mdatetime" | cut -d' ' -f2`
|
|
||||||
article_mtimestamp=`if test "$u" -gt 1; then get_article_info "%at" \
|
|
||||||
"$1" | head -1; fi`
|
|
||||||
article_cauthor=`get_article_info "%an" "$1" | tail -1`
|
|
||||||
article_cauthor_email=`get_article_info "%ae" "$1" | tail -1 | sanit_mail`
|
|
||||||
article_mauthor=`get_article_info "%an" "$1" | head -1`
|
|
||||||
article_mauthor_email=`get_article_info "%ae" "$1" | head -1 | sanit_mail`
|
|
||||||
article_previous_file=`get_article_previous_file "$1"`
|
|
||||||
article_previous_title=`get_article_title "$article_previous_file"`
|
|
||||||
article_next_file=`get_article_next_file "$1"`
|
|
||||||
article_next_title=`get_article_title "$article_next_file"`
|
|
||||||
|
|
||||||
replace_file "article_content" "`get_article_content \"$1\"`" | \
|
|
||||||
replace_str "article_file" "$1" | \
|
|
||||||
replace_str "article_title" "$article_title" | \
|
|
||||||
replace_str "article_cdatetime" "$article_cdatetime" | \
|
|
||||||
replace_str "article_cdate" "$article_cdate" | \
|
|
||||||
replace_str "article_ctime" "$article_ctime" | \
|
|
||||||
replace_str "article_ctimestamp" "$article_ctimestamp" | \
|
|
||||||
replace_str "article_mdatetime" "$article_mdatetime" | \
|
|
||||||
replace_str "article_mdate" "$article_mdate" | \
|
|
||||||
replace_str "article_mtime" "$article_mtime" | \
|
|
||||||
replace_str "article_mtimestamp" "$article_mtimestamp" | \
|
|
||||||
replace_str "article_cauthor" "$article_cauthor" | \
|
|
||||||
replace_str "article_cauthor_email" "$article_cauthor_email" | \
|
|
||||||
replace_str "article_mauthor" "$article_mauthor" | \
|
|
||||||
replace_str "article_mauthor_email" "$article_mauthor_email" | \
|
|
||||||
replace_str "article_previous_file" "$article_previous_file" | \
|
|
||||||
replace_str "article_previous_title" "$article_previous_title" | \
|
|
||||||
replace_str "article_next_file" "$article_next_file" | \
|
|
||||||
replace_str "article_next_title" "$article_next_title"
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_empty_article_info() {
|
|
||||||
replace_str "article_file" "" | \
|
|
||||||
replace_str "article_title" "" | \
|
|
||||||
replace_str "article_cdatetime" "" | \
|
|
||||||
replace_str "article_cdate" "" | \
|
|
||||||
replace_str "article_ctime" "" | \
|
|
||||||
replace_str "article_ctimestamp" "" | \
|
|
||||||
replace_str "article_mdatetime" "" | \
|
|
||||||
replace_str "article_mdate" "" | \
|
|
||||||
replace_str "article_mtime" "" | \
|
|
||||||
replace_str "article_mtimestamp" "" | \
|
|
||||||
replace_str "article_cauthor" "" | \
|
|
||||||
replace_str "article_cauthor_email" "" | \
|
|
||||||
replace_str "article_mauthor" "" | \
|
|
||||||
replace_str "article_mauthor_email" "" | \
|
|
||||||
replace_str "article_previous_file" "" | \
|
|
||||||
replace_str "article_previous_title" "" | \
|
|
||||||
replace_str "article_next_file" "" | \
|
|
||||||
replace_str "article_next_title" ""
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_foreach () {
|
|
||||||
foreach_body=`mktemp --suffix "-fugitive"`
|
|
||||||
tmpfile=`mktemp --suffix "-fugitive"`
|
|
||||||
temp=`mktemp --suffix "-fugitive"`
|
|
||||||
fe="foreach:$1"
|
|
||||||
cat > "$temp"
|
|
||||||
cat "$temp" | \
|
|
||||||
sed -n "/<?fugitive\s\+$fe\s*?>/,/<?fugitive\s\+end$fe\s*?>/p" | \
|
|
||||||
tail -n +2 | head -n -1 > "$foreach_body"
|
|
||||||
if [ ! -s "$foreach_body" ]; then
|
|
||||||
cat "$temp"
|
|
||||||
rm "$foreach_body" "$tmpfile" "$temp"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
cat "$temp" | \
|
|
||||||
sed "s/<?fugitive\s\+$fe\s*?>/<?fugitive foreach_body ?>\n\0/" | \
|
|
||||||
sed "/<?fugitive\s\+$fe\s*?>/,/<?fugitive\s\+end$fe\s*?>/d" | \
|
|
||||||
cat > "$tmpfile"
|
|
||||||
for i in `cat "$2"`; do
|
|
||||||
cat "$foreach_body" | replace_$1_info "$i"
|
|
||||||
done > "$temp"
|
|
||||||
cat "$tmpfile" | replace_file "foreach_body" "$temp"
|
|
||||||
rm "$foreach_body" "$tmpfile"
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_article() {
|
|
||||||
if [ "$preproc" != "" ]; then
|
|
||||||
preproc_bak=`mktemp --suffix "-fugitive" -d "$articles_dir"`
|
|
||||||
mv "$1" "$preproc_bak"
|
|
||||||
($preproc) < "$preproc_bak" > "$1"
|
|
||||||
fi
|
|
||||||
art="${1#$articles_dir/}"
|
|
||||||
cat "$templates_dir/article.html" | \
|
|
||||||
replace_includes | \
|
|
||||||
replace_str "page_title" "`get_article_title \"$art\"`" | \
|
|
||||||
replace_str "blog_url" "$blog_url" | \
|
|
||||||
replace_commit_info "-1" | \
|
|
||||||
replace_article_info "$art" | \
|
|
||||||
sed "/^\s*$/d" > "$public_dir/$art.html"
|
|
||||||
if [ "$preproc" != "" ]; then mv "$preproc_bak" "$1"; fi
|
|
||||||
}
|
|
||||||
|
|
||||||
regenerate_previous_and_next_article_maybe() {
|
|
||||||
if [ "$1" != "" -a \
|
|
||||||
"`grep -c \"$1\" \"$generated_files\"`" = "0" ]; then
|
|
||||||
echo -n "[fugitive] Regenerating $public_dir/$1.html"
|
|
||||||
echo -n " (as previous article) from $articles_dir/$1... "
|
|
||||||
generate_article "$articles_dir/$1"
|
|
||||||
echo "done."
|
|
||||||
echo "$1" >> "$generated_files"
|
|
||||||
fi
|
|
||||||
if [ "$2" != "" -a \
|
|
||||||
"`grep -c \"$2\" \"$generated_files\"`" = "0" ]; then
|
|
||||||
echo -n "[fugitive] Regenerating $public_dir/$2.html"
|
|
||||||
echo -n " (as next article) from $articles_dir/$2... "
|
|
||||||
generate_article "$articles_dir/$2"
|
|
||||||
echo "done."
|
|
||||||
echo "$2" >> "$generated_files"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
modification=0
|
|
||||||
|
|
||||||
for f in $added_files $modified_files; do
|
|
||||||
if [ "$f" != "${f#$articles_dir}" ]; then
|
|
||||||
modification=$((modification + 1))
|
|
||||||
echo -n "[fugitive] Generating $public_dir/${f#$articles_dir/}.html from"
|
|
||||||
echo -n " $f... "
|
|
||||||
generate_article "$f"
|
|
||||||
echo "done."
|
|
||||||
echo "${f#$articles_dir/}" >> "$generated_files"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for f in $added_files; do
|
|
||||||
if [ "$f" != "${f#$articles_dir}" ]; then
|
|
||||||
art="${f#$articles_dir/}"
|
|
||||||
echo -n "[fugitive] Adding $public_dir/$art.html to git ignore list... "
|
|
||||||
echo "$public_dir/$art.html" >> .git/info/exclude
|
|
||||||
echo "done."
|
|
||||||
previous=`get_article_previous_file "$art"`
|
|
||||||
next=`get_article_next_file "$art"`
|
|
||||||
regenerate_previous_and_next_article_maybe "$previous" "$next"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for f in $deleted_files; do
|
|
||||||
if [ "$f" != "${f#$articles_dir}" ]; then
|
|
||||||
modification=$((modification + 1))
|
|
||||||
art="${f#$articles_dir/}"
|
|
||||||
echo -n "[fugitive] Deleting $public_dir/$art.html... "
|
|
||||||
rm "$public_dir/$art.html"
|
|
||||||
echo "done."
|
|
||||||
echo -n "[fugitive] Removing $art.html from git ignore list... "
|
|
||||||
sed -i "/^$art.html$/d" .git/info/exclude
|
|
||||||
echo "done."
|
|
||||||
previous=`get_deleted_previous_file "$art"`
|
|
||||||
next=`get_deleted_next_file "$art"`
|
|
||||||
regenerate_previous_and_next_article_maybe "$previous" "$next"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $modification -gt 0 ]; then
|
|
||||||
echo -n "[fugitive] Generating $public_dir/archives.html... "
|
|
||||||
cat "$templates_dir/archives.html" | \
|
|
||||||
replace_includes | \
|
|
||||||
replace_foreach "article" "$articles_sorted" | \
|
|
||||||
replace_foreach "commit" "$commits" | \
|
|
||||||
replace_empty_article_info | \
|
|
||||||
replace_str "page_title" "archives" | \
|
|
||||||
replace_str "blog_url" "$blog_url" | \
|
|
||||||
replace_commit_info "-1" | \
|
|
||||||
sed "/^\s*$/d" > "$public_dir/archives.html"
|
|
||||||
echo "done."
|
|
||||||
echo -n "[fugitive] Generating $public_dir/feed.xml... "
|
|
||||||
last_5_articles=`mktemp --suffix "-fugitive"`
|
|
||||||
head -5 "$articles_sorted" > "$last_5_articles"
|
|
||||||
last_5_commits=`mktemp --suffix "-fugitive"`
|
|
||||||
head -5 "$commits" > "$last_5_commits"
|
|
||||||
cat "$templates_dir/feed.xml" | \
|
|
||||||
replace_foreach "article" "$last_5_articles" | \
|
|
||||||
replace_foreach "commit" "$last_5_commits" | \
|
|
||||||
replace_str "blog_url" "$blog_url" | \
|
|
||||||
replace_commit_info "-1" | \
|
|
||||||
sed "/^\s*$/d" > "$public_dir/feed.xml"
|
|
||||||
echo "done."
|
|
||||||
rm "$last_5_articles" "$last_5_commits"
|
|
||||||
echo -n "[fugitive] Using last published article as index page... "
|
|
||||||
cp "$public_dir/`head -1 $articles_sorted`.html" "$public_dir/index.html"
|
|
||||||
echo "done".
|
|
||||||
echo "[fugitive] Blog update complete."
|
|
||||||
fi
|
|
||||||
rm "$articles_sorted"
|
|
||||||
rm "$articles_sorted_with_delete"
|
|
||||||
rm "$commits"
|
|
||||||
rm "$generated_files"
|
|
||||||
|
|
|
@ -1,3 +1,40 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "hi!"
|
cd ..
|
||||||
|
export GIT_DIR=.git
|
||||||
|
git reset --hard
|
||||||
|
|
||||||
|
refs=`cat - | head -1 | cut -d' ' -f1,2`
|
||||||
|
ref_begin=`echo $refs | cut -d' ' -f1`
|
||||||
|
ref_end=`echo $refs | cut -d' ' -f2`
|
||||||
|
|
||||||
|
if [ "$ref_begin" = "0000000000000000000000000000000000000000" ]; then
|
||||||
|
range="" # first push, empty repos.
|
||||||
|
else
|
||||||
|
range="$ref_begin..$ref_end"
|
||||||
|
fi
|
||||||
|
|
||||||
|
articles_dir=`git config --get fugitive.articles-dir`
|
||||||
|
|
||||||
|
added_files=`git log $range --name-status --pretty="format:" | \
|
||||||
|
grep -E '^A' | cut -f2 | sort | uniq`
|
||||||
|
modified_files=`git log $range --name-status --pretty="format:" | \
|
||||||
|
grep -E '^M' | cut -f2 | sort | uniq`
|
||||||
|
deleted_files=`git log $range --name-status --pretty="format:" | \
|
||||||
|
grep -E '^D' | cut -f2 | sort | uniq`
|
||||||
|
|
||||||
|
tmpart=`mktemp --suffix "-fugitive"`
|
||||||
|
tmpadd=`mktemp --suffix "-fugitive"`
|
||||||
|
tmpmod=`mktemp --suffix "-fugitive"`
|
||||||
|
tmpdel=`mktemp --suffix "-fugitive"`
|
||||||
|
ls "$articles_dir"/* > "$tmpart"
|
||||||
|
echo "$added_files" | tr " " "\n" > "$tmpadd"
|
||||||
|
echo "$modified_files" | tr " " "\n" > "$tmpmod"
|
||||||
|
echo "$deleted_files" | tr " " "\n" > "$tmpdel"
|
||||||
|
deleted_files=`comm -23 --nocheck-order "$tmpdel" "$tmpart"`
|
||||||
|
echo "$deleted_files" | tr " " "\n" > "$tmpdel"
|
||||||
|
deleted_files=`comm -23 --nocheck-order "$tmpdel" "$tmpadd"`
|
||||||
|
added_files=`comm -12 --nocheck-order "$tmpadd" "$tmpart"`
|
||||||
|
echo "$added_files" | tr " " "\n" > "$tmpadd"
|
||||||
|
modified_files=`comm -23 --nocheck-order "$tmpmod" "$tmpadd"`
|
||||||
|
rm "$tmpart" "$tmpadd" "$tmpmod" "$tmpdel"
|
||||||
|
|
Loading…
Reference in New Issue