line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Plugin::SiteMap - Generate a SiteMap automatically. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This plugin must be enabled by adding two settings in the |
11
|
|
|
|
|
|
|
global configuration file; the name of the file to generate |
12
|
|
|
|
|
|
|
and the prefix of the output URLs. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
The following is a good example: |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=for example begin |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sitemap_file = /sitemap.xml |
19
|
|
|
|
|
|
|
sitemap_base = http://example.com/ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=for example end |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This plugin will generate a simple C<sitemap.xml> file including |
28
|
|
|
|
|
|
|
references to all pages which C<templer> knows about. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 LICENSE |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
35
|
|
|
|
|
|
|
under the terms of either: |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
38
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, |
39
|
|
|
|
|
|
|
or |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
b) the Perl "Artistic License". |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 AUTHOR |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Copyright (C) 2016 Steve Kemp <steve@steve.org.uk>. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
56
|
|
|
|
|
|
|
the same terms as Perl itself. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
11
|
|
|
11
|
|
3894
|
use strict; |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
241
|
|
67
|
11
|
|
|
11
|
|
30
|
use warnings; |
|
11
|
|
|
|
|
10
|
|
|
11
|
|
|
|
|
241
|
|
68
|
|
|
|
|
|
|
|
69
|
11
|
|
|
11
|
|
4764
|
use POSIX qw(strftime); |
|
11
|
|
|
|
|
45081
|
|
|
11
|
|
|
|
|
88
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
package Templer::Plugin::SiteMap; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 new |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Constructor. No arguments are required/supported. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub new |
81
|
|
|
|
|
|
|
{ |
82
|
11
|
|
|
11
|
1
|
21
|
my ( $proto, %supplied ) = (@_); |
83
|
11
|
|
33
|
|
|
53
|
my $class = ref($proto) || $proto; |
84
|
|
|
|
|
|
|
|
85
|
11
|
|
|
|
|
13
|
my $self = {}; |
86
|
11
|
|
|
|
|
17
|
bless( $self, $class ); |
87
|
11
|
|
|
|
|
76
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 init |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Initialisation function, which merely saves a reference to the |
94
|
|
|
|
|
|
|
L<Templer::Site> object. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub init |
100
|
|
|
|
|
|
|
{ |
101
|
2
|
|
|
2
|
1
|
3
|
my( $self, $site ) = ( @_); |
102
|
|
|
|
|
|
|
|
103
|
2
|
|
33
|
|
|
17
|
$self->{ 'site' } ||= $site; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 cleanup |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This method is invoked when site-generation is complete, and this |
110
|
|
|
|
|
|
|
is where we generate the sitemap, if our two required configuration |
111
|
|
|
|
|
|
|
values are present in the configuration file. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
If configuration-variables are not setup then we do nothing. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub cleanup |
118
|
|
|
|
|
|
|
{ |
119
|
2
|
|
|
2
|
1
|
3
|
my ($self) = (@_); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
3
|
my $file = $self->{'site'}->{'sitemap_file'}; |
125
|
2
|
|
|
|
|
4
|
my $base = $self->{'site'}->{'sitemap_base'}; |
126
|
2
|
|
|
|
|
3
|
my $path = $self->{'site'}->{'output'}; |
127
|
|
|
|
|
|
|
|
128
|
2
|
0
|
33
|
|
|
8
|
return unless ($file && $base && $path ); |
|
|
|
33
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $pages = $self->{ 'site' }->{ 'output-files' }; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
open( my $map, ">", $path . $file ); |
139
|
0
|
|
|
|
|
|
print $map <<EOF; |
140
|
|
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
141
|
|
|
|
|
|
|
<urlset |
142
|
|
|
|
|
|
|
xmlns="http://www.google.com/schemas/sitemap/0.84" |
143
|
|
|
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
144
|
|
|
|
|
|
|
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 |
145
|
|
|
|
|
|
|
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"> |
146
|
|
|
|
|
|
|
<url> |
147
|
|
|
|
|
|
|
<loc>$base</loc> |
148
|
|
|
|
|
|
|
<priority>0.75</priority> |
149
|
|
|
|
|
|
|
<changefreq>daily</changefreq> |
150
|
|
|
|
|
|
|
</url> |
151
|
|
|
|
|
|
|
EOF |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
foreach my $page (@$pages) |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
|
|
|
my $url = substr( $page, length($path) ); |
160
|
0
|
|
|
|
|
|
print $map <<EOF; |
161
|
|
|
|
|
|
|
<url> |
162
|
|
|
|
|
|
|
<loc>$base$url</loc> |
163
|
|
|
|
|
|
|
<priority>0.50</priority> |
164
|
|
|
|
|
|
|
<changefreq>weekly</changefreq> |
165
|
|
|
|
|
|
|
</url> |
166
|
|
|
|
|
|
|
EOF |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
print $map <<EOF; |
170
|
|
|
|
|
|
|
</urlset> |
171
|
|
|
|
|
|
|
EOF |
172
|
0
|
|
|
|
|
|
close($map); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Templer::Plugin::Factory->new()->register_plugin("Templer::Plugin::SiteMap"); |
179
|
|
|
|
|
|
|
|