-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_page
executable file
·125 lines (112 loc) · 2.68 KB
/
build_page
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
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env perl
#
# vim: tabstop=4
use strict;
my %vars;
my ($rootdir, $url);
my $freshports_url = "https://freshports.org";
sub mklink {
my ($site, $document) = @_;
my $url = "$site/$document";
return "<a href=\"$url\">$document</a>";
}
while ($ARGV[0] =~ m/^-/) {
if ($ARGV[0] eq "-r") {
shift;
@ARGV > 0 || die "Usage: $0 -r <rootdir>";
$rootdir = $ARGV[0];
}
shift;
}
$url = $ARGV[0];
my (@content, @head, $date);
my ($in_list, $in_list_item);
$date = localtime();
while (<STDIN>) {
if (/^TITLE=(.*)/) {
chomp($vars{title} = $1);
} elsif(/^PAGEDESCRIPTION=(.*)/) {
chomp($vars{pagedescription} = $1);
} elsif (/^PAGEURL=(.*)/) {
chomp($vars{pageurl} = $1);
} elsif (/^KEYWORDS=(.*)/) {
chomp($vars{keywords} = $1);
} elsif (/^ID=(.*)/) {
chomp($vars{id} = $1);
} elsif (/^BODY_ATTR=(.*)/) {
chomp($vars{body_attr} = $1);
} elsif (/^HEAD_START/) {
while (($_ = <STDIN>) && !/^HEAD_END/) {
push(@head, $_);
}
} elsif (/^CONTENT_START/) {
while (($_ = <STDIN>) && !/^CONTENT_END/) {
push(@content, $_);
}
}
}
open(FH, "template") || die "Couldn't open template file: $!";
while (<FH>) {
next if (/^#/);
s/\@URL\@/$url/g;
s/\@PAGEDESCRIPTION\@/$vars{pagedescription}/g;
s/\@PAGEURL\@/$vars{pageurl}/g;
s/\@KEYWORDS\@/$vars{keywords}/g;
s/\@ID\@/$vars{id}/g;
s/\@TITLE\@/$vars{title}/g;
s/\@ROOTDIR\@/$rootdir/g;
s/\@BODY_ATTR\@/$vars{body_attr}/g;
if (/\@HEAD\@/) {
foreach (@head) {
s/\@ROOTDIR\@/$rootdir/g;
s/\@TITLE\@/$vars{title}/g;
s/\@PAGEDESCRIPTION\@/$vars{pagedescription}/g;
s/\@PAGEURL\@/$vars{pageurl}/g;
s/\@KEYWORDS\@/$vars{keywords}/g;
s/\@ID\@/$vars{id}/g;
print;
}
} elsif (/\@CONTENT\@/) {
foreach (@content) {
s/\@ROOTDIR\@/$rootdir/g;
s/\@TITLE\@/$vars{title}/g;
s/\@PAGEDESCRIPTION\@/$vars{pagedescription}/g;
s/\@PAGEURL\@/$vars{pageurl}/g;
s/\@KEYWORDS\@/$vars{keywords}/g;
s/\@ID\@/$vars{id}/g;
s/\@DATE\@/$date/g;
if (/^\@DOWNLOAD_TABLE\@/) {
system("./mkdltbl");
next;
}
if (/^\@MIRROR_TABLE\@/) {
system("./mkmirrortbl");
next;
}
# Replace @PORT@(category/portname) with a link to freshports.org
s/\@PORT\@\(([^\)]+)\)/mklink($freshports_url, $1)/eg;
# Replace @CODE@(string) with <span class="code">string</span>
s/\@CODE\@\(([^\)]+)\)/<span class="code">$1<\/span>/g;
if (/^\s*LIST_START/) {
$in_list++;
$_ = "<ul>";
} elsif (/^\s*LIST_END/) {
$in_list--;
$_ = "</ul>" . "\n";
} elsif ($in_list) {
if (/^\s*\*\s(.*)$/) {
$in_list_item++;
$_ = "<li>" . $1 . "\n";
} elsif (/^$/) {
if ($in_list_item) {
$in_list_item--;
$_ = "</li>" . "\n";
}
}
}
print;
}
} else {
print;
}
}