7 use File::Spec::Functions qw(rel2abs splitpath splitdir catpath catdir catfile canonpath);
10 my $feed = XML::Feed->parse(URI->new('http://yapgh.blogspot.com/feeds/posts/default?alt=rss'))
11 or die XML::Feed->errstr;
13 my ($volume, $dirs) = splitpath(rel2abs(__FILE__));
15 my @directories = splitdir(canonpath($dirs));
17 my $parent_dir = catpath($volume, catdir(@directories));
18 my $output_path = catdir($parent_dir, 'pages');
20 die("Error: Output path '$output_path' not found.") unless(-d $output_path);
23 my %available_tags = (); # tags to filenames
24 my %tag_overview = (); # tags to short content
26 printf("path for placing files is: %s\n", $output_path);
29 for my $entry ($feed->entries)
31 my $output_file = sprintf("blog-%04d.html-inc", $i);
32 my @tags = $entry->tags;
34 foreach my $tag (sort @tags)
36 @{$available_tags{$tag}} = () unless defined ($available_tags{$tag});
37 push(@{$available_tags{$tag}}, $output_file);
40 open($fh, '>', catfile($output_path, $output_file));
41 binmode($fh, ":utf8");
42 print($fh "<div class=\"blog\">\n<h1 id=\"NAME\">\n",
44 "\n</h1>\n<div class=\"CONTENT\">\n",
45 $entry->content->body,
51 printf("created file: %s\n", $output_file);
56 open($fh, '>', catfile($output_path, 'blog-0000.html-inc'));
57 binmode($fh, ":utf8");
58 print($fh "<div class=\"blog\"><h1>Articles</h1>\n");
60 for my $entry ($feed->entries)
63 my @tags = $entry->tags;
64 foreach my $tag (sort @tags)
68 $tag_links .= sprintf(' <a href="tags-%s.html" style="font-size: 10px">[%s]</a>', $_tag, $tag);
71 my $text = $entry->content->body;
72 $text = $1 if $text =~ /^<div.+<\/div>(.+)<div.+<\/div>$/;
73 $text =~ s/<br\s*\/{0,1}>/\n/g;
74 $text =~ s/<[@#%\w\s"\/?&=:\-\.;']+>/ /g;
78 $text =~ s/\n/<br \/>/g;
79 $text = $1 if $text =~ /^([^<>]+<br \/>[^<>]+<br \/>[^<>]+<br \/>).*$/;
80 $text =~ s/(<br \/>)+$//g;
82 # overview of all blog entries
84 . '<a href="blog-%04d.html">%s</a><br />'
85 . '<span style="font-size: 10px">%s</span><br />'
86 . '<span style="font-size: 10px">Tags:</span>%s<br />'
87 . '%s<br /><a href="blog-%04d.html" style="font-size: 12px">[more]</a><br /><br />'
90 $i, $entry->title, $entry->issued->strftime('%A, %d %B %Y'), $tag_links, $text, $i
93 # preparing the %tag_overview hash for tag-overview-pages
95 foreach my $tag (sort @tags)
97 @{$tag_overview{$tag}} = () unless defined ($tag_overview{$tag});
98 push(@{$tag_overview{$tag}},
100 . '<a href="blog-%04d.html">%s</a><br />'
101 . '<span style="font-size: 10px">%s</span><br />'
102 . '<span style="font-size: 10px">Tags: %s</span><br />'
103 . '%s<br /><a href="blog-%04d.html" style="font-size: 12px">[more]</a><br /><br />'
105 $i, $entry->title, $entry->issued->strftime('%A, %d %B %Y'), $tag_links, $text, $i
111 print($fh "</div>\n");
113 printf("created file: %s\n", 'blog-0000.html-inc');
116 # csv: "tagname: file1,file2\n"
117 open($fh, '>', catfile($output_path, 'tags-index'));
118 binmode($fh, ":utf8");
119 foreach my $tag (sort keys %available_tags)
121 printf($fh "%s: %s\n", $tag, join(',', @{$available_tags{$tag}}));
124 printf("created file: %s\n", 'tags-index');
126 # overview pages for tags
127 foreach my $tag (sort keys %tag_overview)
131 open($fh, '>', catfile($output_path, 'tags-' . $_tag . '.html-inc'));
132 binmode($fh, ":utf8");
133 print($fh '<div class="blog"><h1>Results for tag: ' . $tag . '</h1>'
134 . join('<hr />', @{$tag_overview{$tag}})
137 printf("created file: %s\n", 'tags-' . $_tag . '.html-inc');