blob: 0dcd7e2411541b25cacd3c7fa27f5f2392feb3dc (
plain)
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
|
#!/usr/bin/perl
use strict;
use warnings;
use Storable qw(nstore);
use HTML::Entities qw(decode_entities);
# --- Configuration ---
my $built_site_dir = '../log';
my $output_file = 'search_index.dat';
my %index;
print "Building search index from $built_site_dir...\n";
foreach my $path (glob("$built_site_dir/*/index.html")) {
next unless open(my $fh, '<:utf8', $path);
my $html = do { local $/; <$fh> };
close($fh);
# Extract Title and Main Content
my ($title) = $html =~ m|<title>(.*?)</title>|is || "Unknown";
my ($main) = $html;
# Normalize path
my $url = $path;
$index{$url} = {
t => $title || "Untitled",
c => $main
};
}
nstore(\%index, $output_file);
printf("Index complete: %d files (%.2f KB)\n", scalar(keys %index), (-s $output_file) / 1024);
|