Bug 16601: Update of italian MARC21 files
[koha.git] / misc / cronjobs / sitemap.pl
blob80c01fdd03fe0d918faa19019d86c539fb0f9a0a
1 #!/usr/bin/perl
3 # Copyright 2015 Tamil s.a.r.l.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 package Main;
22 use Modern::Perl;
23 use utf8;
24 use Pod::Usage;
25 use Getopt::Long;
26 use C4::Biblio;
27 use Koha::Sitemapper;
30 my ($verbose, $help, $url, $dir, $short) = (0, 0, '', '.', 1);
31 GetOptions(
32 'verbose' => \$verbose,
33 'help' => \$help,
34 'url=s' => \$url,
35 'dir=s' => \$dir,
36 'short!' => \$short,
39 sub usage {
40 pod2usage( -verbose => 2 );
41 exit;
44 usage() if $help;
46 unless ($url) {
47 $url = C4::Context->preference("OPACBaseURL");
48 unless ($url) {
49 say "OPACBaseURL syspref isn't defined. You can use --url parameter.";
50 exit;
53 $url =~ s/\/*$//g;
55 my $sitemapper = Koha::Sitemapper->new(
56 verbose => $verbose,
57 url => $url,
58 dir => $dir,
59 short => $short,
61 $sitemapper->run();
64 =head1 USAGE
66 =over
68 =item sitemap.pl [--verbose|--help|--short|--noshort|--url|--dir]
70 =back
72 =head1 SYNOPSIS
74 sitemap.pl --verbose
75 sitemap.pl --noshort --dir /home/koha/mylibrary/www
76 sitemap.pl --url opac.myDNSname.org
78 =head1 DESCRIPTION
80 Process all biblio records from a Koha instance and generate Sitemap files
81 complying with this protocol as described on L<http://sitemaps.org>. The goal of
82 this script is to be able to provide to search engines direct access to biblio
83 records. It avoid leaving search engine browsing Koha OPAC and so generating
84 a lot of traffic, and workload, for a bad result.
86 A file name F<sitemapindex.xml> is generated. It contains references to Sitemap
87 multiples files. Each file contains at most 50,000 urls, and is named
88 F<sitemapXXXX.xml>.
90 The files must be stored on Koha OPAC root directory, ie
91 F<<koha-root>/koha-tmpl/>. Place also in this directory a F<robots.txt> file
92 like this one:
94 Sitemap: sitemapindex.xml
95 User-agent: *
96 Disallow: /cgi-bin/
98 =head1 PARAMETERS
100 =over
102 =item B<--url=Koha OPAC base URL>
104 If omitted, OPACBaseURL syspref is used.
106 =item B<--short|noshort>
108 By default, --short. With --short, URL to bib record ends with
109 /bib/biblionumber. With --noshort, URL ends with
110 /cgi-bin/koha/opac-detail.pl?biblionumber=bibnum
112 =item B<--dir>
114 Directory where to write sitemap files. By default, the current directory.
116 =item B<--verbose|-v>
118 Enable script verbose mode: a message is displayed for each 10,000 biblio
119 records processed.
121 =item B<--help|-h>
123 Print this help page.
125 =back
127 =cut