Skip to content

Commit

Permalink
Generate the sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Apr 29, 2019
1 parent c737ab5 commit ddb8f95
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 52 deletions.
16 changes: 16 additions & 0 deletions build
Expand Up @@ -5,6 +5,7 @@ use warnings;

use Template;
use File::Copy::Recursive 'dircopy';
use Time::Piece;
use Literature::Schema;

my %resources = qw[
Expand All @@ -26,6 +27,11 @@ my $sch = Literature::Schema->get_schema;
$tt->process('index.tt', {}, 'index.html')
or die $tt->error;

my $vars = {
url => 'https://literatureon.tv',
date => localtime->strftime('%Y-%m-%d'),
};

for (keys %resources) {
print "Processing $_\n";

Expand All @@ -40,7 +46,17 @@ for (keys %resources) {
$tt->process("$singular.tt", { $singular => $obj },
"$_/" . $obj->slug . '/index.html')
or die $tt->error;

push @{$vars->{$_}}, $obj;
}
}

$tt = Template->new({
INCLUDE_PATH => [ qw( in tt_lib ) ],
OUTPUT_PATH => 'docs',
});

$tt->process('sitemap.tt', $vars, 'sitemap.xml')
or die $tt->error;

dircopy('static', 'docs');
56 changes: 56 additions & 0 deletions in/sitemap.tt
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

<url>
<loc>[% url %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>1.00</priority>
</url>
[% FOREACH type IN ['actors', 'authors', 'characters', 'productions',
'works' ] -%]
<url>
<loc>[% url %]/[% type %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>0.90</priority>
</url>
[% END -%]
[% FOREACH actor IN actors -%]
<url>
<loc>[% url %]/actors/[% actor.slug %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>0.80</priority>
</url>
[% END -%]
[% FOREACH author IN authors -%]
<url>
<loc>[% url %]/authors/[% author.slug %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>0.80</priority>
</url>
[% END -%]
[% FOREACH character IN characters -%]
<url>
<loc>[% url %]/characters/[% character.slug %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>0.80</priority>
</url>
[% END -%]
[% FOREACH production IN productions -%]
<url>
<loc>[% url %]/productions/[% production.slug %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>0.80</priority>
</url>
[% END -%]
[% FOREACH work IN works -%]
<url>
<loc>[% url %]/works/[% work.slug %]/</loc>
<lastmod>[% date %]</lastmod>
<priority>0.80</priority>
</url>
[% END -%]
</urlset>
52 changes: 0 additions & 52 deletions static/sitemap.xml

This file was deleted.

0 comments on commit ddb8f95

Please sign in to comment.