-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrast
executable file
·111 lines (89 loc) · 2.69 KB
/
rast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl
# Blosxom Plugin: rast
# Author: Gosuke Miyashita <[email protected]>
# Version: 2005-05-03
# Blosxom Home/Docs/Licensing: http://www.blosxom.com/
package rast;
use strict;
use vars qw($query $summary);
use CGI qw(param url);
use Rast;
use HTML::TagFilter;
## --- configurable variables ---
my $rast_db_dir = "$blosxom::plugin_state_dir/rastdb";
my $rast_encoding = "euc_jp";
sub start {
return 1;
}
sub filter {
my($pkg, $files) = @_;
## create rast database
## Usage: blosxom.cgi rast_create_db=1 [recache=all]
if (!$ENV{GATEWAY_INTERFACE} and param('rast_create_db')){
Rast->create(
"$rast_db_dir",
{
encoding => $rast_encoding,
preserve_text => 1,
properties => [
['filename', RAST_TYPE_STRING, RAST_PROPERTY_FLAG_SEARCH|RAST_PROPERTY_FLAG_UNIQUE],
['last_modified', RAST_TYPE_DATE, RAST_PROPERTY_FLAG_SEARCH],
],
}
);
}
## reindex database
if (!$ENV{GATEWAY_INTERFACE} and param('rast_reindex_db')){
my $db = Rast->open("$rast_db_dir", RAST_RDWR, {sync_threshold_chars => 1000000});
foreach my $file (keys %$files){
my $time = $files->{$file};
my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime($time);
my $date = sprintf("%04d-%02d-%02dT%02d:%02d:%02d", $year + 1900, $month + 1, $mday, $hour, $min, $sec);
my $options = [$file, $date];
open(IN, $file) or die $!;
my @lines = <IN>;
my $lines;
my $tf = HTML::TagFilter->new( allow => {} );
foreach my $line (@lines){
if($line !~ /^meta-/){
$lines .= $tf->filter($line);
}
}
$db->register($lines, $options);
}
$db->close;
}
## search rast database
if(param('rast_search_query')){
$query = param('rast_search_query');
my $db = Rast->open("$rast_db_dir", RAST_RDWR, {sync_threshold_chars => 1000000});
my $result = $db->search(
$query,
{
need_summary => 1,
properties => ['filename', 'last_modified'],
}
);
my $hit_files;
while(my $row = $result->fetch){
$hit_files->{$row->{properties}->[0]} = $files->{$row->{properties}->[0]};
my @query = split(/\s/, $query);
map { $row->{summary} =~ s!$_!<strong class="search">$_</strong>!gi; } @query;
$summary->{$row->{properties}->[0]} = $row->{summary};
}
if($result->hit_count){
%$files = %$hit_files;
} else {
%$files = {};
}
$db->close;
}
}
sub story {
my($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_;
if(param('rast_search_query')){
$$body_ref = '<p class="entryBody">' . $summary->{"$blosxom::datadir$path/$fn.$blosxom::file_extension"} .
" ... <a href='$path/$fn.html'>[Á´ÉôÆÉ¤à]</a></p>";
}
}
1;