diff --git a/bibcop.pl b/bibcop.pl index bd60811..c407ce8 100755 --- a/bibcop.pl +++ b/bibcop.pl @@ -27,6 +27,7 @@ package bibcop; use warnings; use strict; use File::Basename; +use Time::Piece; # Hash of incoming command line arguments. my %args = map { $_ => 1 } @ARGV; @@ -39,7 +40,7 @@ package bibcop; 'article' => ['doi', 'year', 'title', 'author', 'journal', 'volume', 'number', 'publisher?', 'pages?'], 'inproceedings' => ['doi', 'booktitle', 'title', 'author', 'year', 'pages?', 'organization?', 'volume?'], 'book' => ['title', 'author', 'year', 'publisher', 'doi?'], - 'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'publisher?', 'organization?', 'doi?', 'url?', 'howpublished?', 'note?'], + 'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'publisher?', 'organization?', 'doi?', 'howpublished?', 'note?'], ); # See https://research.arizona.edu/faq/what-do-you-mean-when-you-say-use-title-case-proposalproject-titles @@ -534,10 +535,16 @@ sub entry_fix { if ($tag =~ /^:/) { next; } + my $value = clean_tex($entry{$tag}); + if ($tag eq 'url') { + my $today = localtime->strftime('%d-%m-%Y'); + push(@lines, " howpublished = {\\url{$value}},"); + push(@lines, " note = {[Online; accessed $today]},"); + next; + } if (not exists $allowed{$tag} and not exists $allowed{$tag . '?'}) { next; } - my $value = clean_tex($entry{$tag}); my $fixer = "fix_$tag"; my $fixed = $value; if (defined &{$fixer}) { diff --git a/perl-tests/entry_fixing.pl b/perl-tests/entry_fixing.pl index bf49501..b6af831 100755 --- a/perl-tests/entry_fixing.pl +++ b/perl-tests/entry_fixing.pl @@ -25,13 +25,16 @@ package bibcop; use strict; use warnings; +use Time::Piece; require './bibcop.pl'; -fixes({':name' => 'knuth78', ':type' => 'book', 'title' => 'The TeX Book'}, "\@book{knuth78,\n title = {{The TeX Book}},\n}\n\n"); -fixes({':name' => 'k', ':type' => 'article', 'title' => 'Book', 'pages' => ''}, "\@article{k,\n title = {{Book}},\n}\n\n"); +fixes_entry({':name' => 'knuth78', ':type' => 'book', 'title' => 'The TeX Book'}, "\@book{knuth78,\n title = {{The TeX Book}},\n}\n\n"); +fixes_entry({':name' => 'k', ':type' => 'article', 'title' => 'Book', 'pages' => ''}, "\@article{k,\n title = {{Book}},\n}\n\n"); +my $today = localtime->strftime('%d-%m-%Y'); +fixes_entry({':name' => 'f', ':type' => 'misc', 'url' => 'http://google.com'}, "\@misc{f,\n howpublished = {\\url{http://google.com}},\n note = {[Online; accessed $today]},\n}\n\n"); -sub fixes { +sub fixes_entry { my ($hash, $expected) = @_; my %entry = %$hash; my $after = entry_fix(%entry);