ADD: changed to perl only bibtex parser + multi page support
This commit is contained in:
parent
fccff5c467
commit
20b694ec76
@ -3,10 +3,10 @@ package HiD::Generator::BibtexPage;
|
|||||||
use Moose;
|
use Moose;
|
||||||
with 'HiD::Generator';
|
with 'HiD::Generator';
|
||||||
use HiD::Page;
|
use HiD::Page;
|
||||||
use Text::BibTeX;
|
use BibTeX::Parser;
|
||||||
use Text::BibTeX::Bib;
|
use IO::File;
|
||||||
|
|
||||||
our $VERSION = "0.3";
|
our $VERSION = "0.4";
|
||||||
|
|
||||||
|
|
||||||
# a map of bibtex publication item names to real/speaking names
|
# a map of bibtex publication item names to real/speaking names
|
||||||
@ -23,7 +23,7 @@ my $type_map = {
|
|||||||
|
|
||||||
=method generate
|
=method generate
|
||||||
|
|
||||||
reads the configured bibtex file and generates an html version
|
reads the configured bibtex files and generates an html version
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
@ -31,94 +31,60 @@ sub generate {
|
|||||||
my( $self , $site ) = @_;
|
my( $self , $site ) = @_;
|
||||||
return unless $site->config->{bibtex_page}{generate};
|
return unless $site->config->{bibtex_page}{generate};
|
||||||
|
|
||||||
my $input_file = $site->config->{bibtex_page}{layout}
|
die("no bibtex pages defined") unless $site->config->{bibtex_page}{pages};
|
||||||
or die "Must define bibtex_page.layout in config if bibtex_page.generate is enabled";
|
|
||||||
|
|
||||||
my $bibtex_file = $site->config->{bibtex_page}{bibtex}
|
for my $p (keys %{$site->config->{bibtex_page}{pages}})
|
||||||
or die "Must define bibtex_page.bibtex in config if bibtex_page.generate is enabled";
|
{
|
||||||
|
|
||||||
if (! -e $site->config->{bibtex_page}{bibtex}) {
|
my $input_file = $site->config->{bibtex_page}{pages}{$p}{layout}
|
||||||
die "bibtex_page.bibtex:".$site->config->{bibtex_page}{bibtex}." file must exist\n";
|
or die "Must define bibtex_page.layout in config if bibtex_page.generate is enabled";
|
||||||
}
|
|
||||||
|
|
||||||
my $url = $site->config->{bibtex_page}{url} // 'publications/';
|
my $bibtex_file = $site->config->{bibtex_page}{pages}{$p}{bibtex}
|
||||||
|
or die "Must define bibtex_page.bibtex in config if bibtex_page.generate is enabled";
|
||||||
|
|
||||||
my $destination = $site->config->{bibtex_page}{destination} // $site->destination;
|
if (! -e $site->config->{bibtex_page}{pages}{$p}{bibtex}) {
|
||||||
|
die "bibtex_page.bibtex:".$site->config->{bibtex_page}{bibtex}." file must exist\n";
|
||||||
|
}
|
||||||
|
|
||||||
$self->_create_destination_directory_if_needed( $destination );
|
my $url = $site->config->{bibtex_page}{pages}{$p}{url} // 'publications/';
|
||||||
|
|
||||||
# here we need to parse the bibtex file and generate the list
|
my $destination = $site->config->{bibtex_page}{pages}{$p}{destination} // $site->destination;
|
||||||
my @publications;
|
|
||||||
my $bibfile = new Text::BibTeX::File($site->config->{bibtex_page}{bibtex});
|
|
||||||
$bibfile->set_structure ('Bib',sortby => 'year');
|
|
||||||
while (my $entry = new Text::BibTeX::Entry $bibfile) {
|
|
||||||
next unless $entry->parse_ok;
|
|
||||||
my %pub;
|
|
||||||
$pub{type}=$type_map->{$entry->type};
|
|
||||||
|
|
||||||
my @names = $entry->names ('author');
|
$self->_create_destination_directory_if_needed( $destination );
|
||||||
my @last;
|
|
||||||
for my $n (@names){
|
# here we need to parse the bibtex file and generate the list
|
||||||
push(@last, $n->part('last'));
|
my @publications;
|
||||||
}
|
my $fh = IO::File->new($site->config->{bibtex_page}{pages}{$p}{bibtex});
|
||||||
$pub{author}=\@last;
|
my $bibfile = BibTeX::Parser->new($fh);
|
||||||
if ($entry->type eq "mastersthesis" || $entry->type eq "phdthesis") {
|
|
||||||
$pub{title}=$entry->get('title') . ", " . $entry->get('school') . ", " . $entry->get('address');
|
my @entries;
|
||||||
} elsif($entry->type eq "inproceedings") {
|
while (my $entry = $bibfile->next ) {
|
||||||
$pub{title}=$entry->get('title') . ", " .$entry->get('booktitle') . ", ". $entry->get('address');
|
if ($entry->parse_ok) {
|
||||||
} elsif($entry->type eq "misc") {
|
push(@entries, $entry);
|
||||||
$pub{title}=$entry->get('title');
|
}
|
||||||
if (defined($entry->get('howpublished')) && length($entry->get('howpublished'))>0) {
|
|
||||||
$pub{title}.="," . $entry->get('howpublished');
|
|
||||||
}
|
}
|
||||||
if (defined($entry->get('address')) && length($entry->get('address'))>0) {
|
|
||||||
$pub{title}.="," . $entry->get('address');
|
|
||||||
}
|
|
||||||
} elsif($entry->type eq "inbook") {
|
|
||||||
$pub{title} = "Chap: " . $entry->get('chapter') . ", Book: " . $entry->get('title');
|
|
||||||
$pub{title} .= ", Editor: " . $entry->get('editor') unless !defined($entry->get('editor'));
|
|
||||||
$pub{title} .= ", " . $entry->get('publisher') unless !defined($entry->get('publisher'));
|
|
||||||
} elsif($entry->type eq "incollection") {
|
|
||||||
$pub{title} = $entry->get('title') .", " . $entry->get('booktitle');
|
|
||||||
$pub{title} .= " Vol. " . $entry->get('volume') unless !defined($entry->get('volume'));
|
|
||||||
$pub{title} .= ", Editor: " . $entry->get('editor') unless !defined($entry->get('editor'));
|
|
||||||
$pub{title} .= ", " . $entry->get('publisher') unless !defined($entry->get('publisher'));
|
|
||||||
} elsif($entry->type eq "article") {
|
|
||||||
$pub{title} = $entry->get('title') .", " . $entry->get('journal');
|
|
||||||
$pub{title} .= " Issue " . $entry->get('number') unless !defined($entry->get('number'));
|
|
||||||
$pub{title} .= " Vol. " . $entry->get('volume') unless !defined($entry->get('volume'));
|
|
||||||
$pub{title} .= ", " . $entry->get('publisher') unless !defined($entry->get('publisher'));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$pub{title}=$entry->get('title');
|
|
||||||
}
|
|
||||||
$pub{year}=$entry->get('year');
|
|
||||||
$pub{month}=$entry->get('month');
|
|
||||||
$pub{day}=$entry->get('day');
|
|
||||||
$pub{url}=$entry->get('url');
|
|
||||||
$pub{source}=$entry->print_s;
|
|
||||||
$pub{id}=$entry->key;
|
|
||||||
|
|
||||||
push(@publications, \%pub);
|
|
||||||
}
|
|
||||||
|
|
||||||
# sort publications by year
|
# sort publications by year
|
||||||
@publications=sort { $b->{year} <=> $a->{year} } @publications;
|
@publications=sort { $b->{year} <=> $a->{year} } @entries;
|
||||||
|
|
||||||
# create the new page
|
# create the new page
|
||||||
my $page = HiD::Page->new({
|
my $page = HiD::Page->new({
|
||||||
dest_dir => $destination ,
|
dest_dir => $destination ,
|
||||||
hid => $site ,
|
hid => $site ,
|
||||||
url => $url ,
|
url => $url ,
|
||||||
input_filename => $input_file ,
|
input_filename => $input_file ,
|
||||||
layouts => $site->layouts ,
|
layouts => $site->layouts ,
|
||||||
});
|
});
|
||||||
$page->metadata->{publications} = \@publications;
|
$page->metadata->{publications} = \@publications;
|
||||||
|
|
||||||
$site->add_input( "Publication" => 'page' );
|
$site->add_input( "Publication" => 'page' );
|
||||||
$site->add_object( $page );
|
$site->add_object( $page );
|
||||||
|
|
||||||
$site->INFO( "* Injected Bibtex page");
|
$site->INFO( "* Injected Bibtex page $p");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__PACKAGE__->meta->make_immutable;
|
__PACKAGE__->meta->make_immutable;
|
||||||
|
Loading…
Reference in New Issue
Block a user