I was asked to explain into more detail how to get the search
function (search.cgi)
into the blog, so here we go.
First, you will have to install SWISH-E. Since I'm using FreeBSD,
that's a breeze:
# cd /usr/ports/www/swish-e/
# make
# make install
For some reason, it didn't install the perl API, so I had to do
that manually:
# cd work/swish-e-2.4.2/perl/
# perl Makefile.PL
# make
# make test
# make install
After that, I copied /usr/local/lib/swish-e/search.cgi
to my cgi-bin and created the swish-e.config
$ cat swish-e.config
IndexOnly .htm .html
DefaultContents HTML*
StoreDescription HTML* <body>
metanames swishtitle swishdocpath
So far, still following the documentation of http://swish-e.org/current/docs/search.html
Time to create an index! And while I'm at it, I'd might as well
make it a NanoBlogger plugin, for I want it to create a new index
every time I update my blog. For that I altered the holy
/usr/local/bin/nb a little.
--- /usr/local/bin/nb.orig Fri Jan 7 23:56:21 2005
+++ /usr/local/bin/nb Fri Jan 7 23:57:55 2005
@@ -611,6 +611,9 @@
nb_msg "generating main index page(s) ..."
ARCHIVES_PATH="${BASE_URL}$ARCHIVES_DIR/"
paginate "$QUERY_MODE" nocat "$MAX_ENTRIES" "$MAIN_TEMPLATE" "$BLOG_DIR" index."$NB_FILETYPE"
+
+# load postblog plugins
+load_plugins postblog
}
# add a new entry
This way, nb will run the plugins in
$PLUGINS_DIR/postblog. So why not create that plugin?
$ cd /usr/local/share/nanoblogger/plugins/
$ mkdir postblog
$ vim postblog/swish-e.sh
$ cat postblog/swish-e.sh
echo "Updating SWISH-E..."
cd /path/to/cgi-bin/
swish-e -e -c /path/to/swish.config -i ../blog/articles/ ../blog/archives/
cd -
Please note that all paths are for my machine and you most likely
have to alter them!
Now for the final part, slightly alter the output of
search.cgi. Once again, you will have to change this to
your blog's settings
--- /usr/local/lib/swish-e/search.cgi Fri Jan 7 21:42:55 2005
+++ /home/menno/html/cgi-bin/search.cgi Fri Jan 7 23:32:54 2005
@@ -207,13 +207,17 @@
<head>
<title>Search Documents</title>
- <style type="text/css">
- a:hover { background: #CCC; }
- body { font-family : verdana,arial,helvetica,sans-serif; }
+ <link rel="stylesheet" href="/blog/styles/nb_default.css" type="text/css" />
+
+ <style type="text/css">
.header { background-color: #EEEEEE; padding-left: 5px; }
- .title { font-size: 1.2em; margin-top: 1em; }
- .rank { color: red; font-size: 0.8em; }
- .description {
+ .result_title {
+ color: #921d00;
+ margin-top: 7px;
+ }
+ .result_description {
+ font-size:small;
+ font-weight:normal;
margin-top: 1em; margin-bottom: 1em; margin-left: 2em;
max-width: 700px; /* not supported by IE */
width:expression(document.body.clientWidth > 600? "600px": "auto" );
@@ -221,11 +225,17 @@
.metadata { margin-left: 2em; font-size: 0.8em; color: green; }
.metadata a { text-decoration: none; color: green; }
.highlight { background : #FFFF99; font-weight: bold; }
+ #logo { text-align: center }
</style>
</head>
<body>
+<div id="banner">
+<h1><a href="/" accesskey="1">B10[m|g]</a></h1>
+<span class="description">Yet another non-informative, useless blog</span>
+</div>
+<div class="blog">
[% PROCESS form %]
<p>
[% IF search %]
@@ -236,6 +246,12 @@
[% PROCESS display_results %]
[% END %]
[% END %]
+<div id="logo">
+<a href="http://swish-e.org/">
+<img alt="powered by SWISH-E" src="/blog/images/swishe.png" style="border: 0;" />
+</a>
+</div>
+</div>
</body>
@@ -268,14 +284,14 @@
[% BLOCK display_results %]
[% USE date %]
[% FOREACH item = search.results %]
- <div class="title">
+ <div class="result_title">
<a href="[% item.Property('swishdocpath') | uri | html %]">
[% item.Property('swishtitle') || item.Property('swishdocpath') | html %]</a>
- <span class="rank"> -- rank: <b>[% item.Property('swishrank') %]</b></span>
+ <!-- <span class="rank"> -- rank: <b>[% item.Property('swishrank') %]</b></span> -->
</div>
- <div class="description">
+ <div class="result_description">
[% item.Property('swishdescription') || "No description" | highlight('swishdefault') %]
</div>
Yes, I downloaded (and converted to PNG format) an image from
http://swish-e.org/graphics.html
Finally you can set it up in your templates
(main_index.html)
<div class="sidetitle">Search</div>
<div class="side">
<form action="/cgi-bin/search.cgi" method="get"><input type="text"
name="query" class="input" /> <input type="submit" value="Search"
class="input" /></form>
</div>