#!/usr/bin/perl -w
# rss2html.pl    September 2004.  Daniel Clemente Laboreo
# Creates an HTML from the RSS in my web.  All GPL.
# It actually creates two files:
#  -one with the first 10 items on the RSS
#  -another with all the items

use strict;
use XML::RSS;
use HTML::Entities;

my $rss = new XML::RSS;

Crea("index.html", 10); # only the 10 last items
Crea("todos.html", -1); # all items

# end of execution

sub Crea {

  open FILE, '>'.shift;

  my $cuantos=shift;

  # write the header
  print FILE <<FIN_DE_TROZO;
  <meta content="text/html; charset=utf-8" http-equiv="content-type">
  <style type="text/css">
    body {background-image: url(papel.jpg); margin: 4%;}
    h1 {text-align:center; text-decoration:underline; font-style:italic;}
    h2 {text-align:center;}
    body > ul > li[id] {color:#d00; font-size: 130%; font-weight: bold;
            list-style-type: none; margin-top: 30px;}
    body > ul > li {list-style-type: circle;}
    body > ul > li, p { text-indent: 15px; line-height: 110%;
            margin-bottom: 7px; }
    li:target {background:yellow; color:black;}
  <meta content="Daniel Clemente Laboreo" name="author">
  <meta content="$rss->{'channel'}->{'description'}" name="description">
  <link rel="shortcut icon" href="../dc.ico">
  <link rel="stylesheet" href="../menu/menu.css">
  <link rel="alternate" type="application/rss+xml" 
   href="cambios.xml" title="RSS feed de DanielClemente.com">
<script type="text/javascript" src="../menu/menubody.js"></script>
<h1>Historial de cambios</h1>

  # write subtitle
  if ($cuantos==-1) {
    print FILE "<h2>2001-2004</h2>";
  } else {
    print FILE "<h2>(&uacute;ltimos $cuantos)</h2>";

  # write "RSS feed" and "Valid HTML" icons
  print FILE <<FIN_DE_TROZO;
<p style="text-align:right">

<a href="cambios.xml"><img style="border:0; margin-right: 40px;"
 src="rss-badge.png" alt="rss feed"
 title="Suscr&iacute;bete a mi RSS para enterarte cuando actualice
la p&aacute;gina"></a>

<a href="http://validator.w3.org/check/referer">
<img src="../valid-html401.png" alt="Valid HTML 4.01!"
 style="border: 0px solid ; width: 88px; height: 31px;"></a></p>

  print FILE "\n\n<ul>\n";

  # write each <item>
  my $counter=0;
  foreach my $item (@{$rss->{'items'}}) {
    if ($cuantos!=-1 && $counter>=$cuantos) {
      last; # only write the specified number of items

    my $id=$item->{'link'}; # http://......html#id (I only want that 'id')
    $id =~ s/.*#//g; # trims the left part of the string, gets the id
    my $titulo=$item->{'title'};
    my $descripcion=$item->{'description'}; # which is composed by some <li>

    print FILE "<li id=\"$id\">$titulo</li>\n$descripcion\n";



  # write ending
  print FILE "\n\n</ul>\n";

  # if writing the short version, tell about the complete one
  print FILE "<p style=\"margin-top:30px; border-top: 2px solid black;
  padding-top: 10px;\">&Eacute;stos son s&oacute;lo los $cuantos
  &uacute;ltimos cambios. Puedes ver la <a href=\"todos.html\">lista
  completa de cambios a mi web</a>, desde 2001 hasta
  ahora.</p>" unless $cuantos==-1;

  print FILE <<FIN_DE_TROZO;

<script src="edad.js" type="text/javascript"></script>




} # end of sub Crea

# end of script.

syntax highlighted by Code2HTML, v. 0.9.1