#!/usr/bin/perl use strict; use warnings; use CGI; use lib '/home/dsktnk/local/lib/perl5'; use Text::Markdown::Discount qw/markdown/; #use Text::Markdown qw/markdown/; use LWP::UserAgent; use URI; use YAML::XS; my $obj = new CGI; my $url = $obj->param('url'); my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); my $request = HTTP::Request->new('GET' , "$url"); my $response = $ua->request($request); my $data = $response->content; my ($frontmatter,$md,$i); # YAML frontmatter #if ($data =~/(^-{3}${1}.*?-{3}${1})/s){ if ($data =~/^-{3}${1}(.*?)-{3}${1}/s){ $frontmatter = "$1"; } my $yf = YAML::XS::Load($frontmatter); my $titletag=$yf->{title}; print qq|Content-type: text/html\n\n|; print &header_html($titletag); print &adsense; print qq|

memo

|; # パンくずリスト my $uri = URI->new($url); my $relative; if ($uri){ my @line = split ( /\// , $uri->path ); @line = grep $_ !~ /^\s*$/, @line; shift @line; pop @line; if (@line){ for my $i (@line){ $relative .= "$i/"; print qq|$i|; } print qq|
|; } } # Markdown my @line = split ( /\n/ , $data ); my ($ln,$line); my $i=0; my $item ="-{3}"; foreach $ln(@line){ if ($ln =~ /$item/){ $i++ } elsif ($i>1){ $line .= "$ln\n"; } } #my $m = Text::Markdown::Discount->new; my $html = markdown($line); #my $html = markdown($line); print $html; print "
"; print $frontmatter; print &footer_html; sub header_html{ my $title=$_[0]; my $printlines = <<"__EOF__"; $title __EOF__ return $printlines; } sub footer_html{ my $printlines = <<"__EOF__"; __EOF__ return $printlines; } sub adsense{ my $printlines = <<"__EOF__"; __EOF__ return $printlines; }