Skip to content

Commit

Permalink
Add the date of first edition to the pmh export
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Sep 27, 2023
1 parent 6d575b1 commit bec6b23
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/AmuseWikiFarm/Schema/Result/Title.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ sub dublin_core_entry {
map { /\w/ ? $_ : '-' } ($self->teaser, $self->notes)
],
publisher => [ $self->publisher ],
date => [ $self->date_year || $self->pubdate->ymd ],
date => [ grep { $_ } ($self->year_first_edition, $self->date_year || $self->pubdate->year) ],
source => [ $self->source ],
language => [ $self->lang || 'en' ],
rights => [ $self->rights ],
Expand Down Expand Up @@ -1809,6 +1809,16 @@ sub author_title {
}
}

sub year_first_edition {
my $self = shift;
if (my $date = $self->datefirst) {
if ($date =~ m/\b([0-9]{4})\b/) {
return $1;
}
}
return;
}

sub date_year {
my $self = shift;
if (my $date = $self->date) {
Expand Down
4 changes: 3 additions & 1 deletion t/oai-pmh.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BEGIN {


use Data::Dumper;
use Test::More tests => 224;
use Test::More tests => 225;
use AmuseWikiFarm::Schema;
use AmuseWikiFarm::Archive::OAI::PMH;
use File::Spec::Functions qw/catfile catdir/;
Expand Down Expand Up @@ -76,6 +76,7 @@ diag $oai_pmh->process_request({
#attach shot.pdf
#publisher <testing> publisher
#date 1923 and something else
#datefirst 1888 and something else
#subtitle This is a subtitle
#teaser This is the teaser
#notes These are the notes
Expand Down Expand Up @@ -300,6 +301,7 @@ foreach my $test ({
'<dc:subject>And &lt;another&gt;</dc:subject>',
'<dc:subject>xAnd&amp;another</dc:subject>',
'<dc:publisher>&lt;testing&gt; publisher</dc:publisher>',
'<dc:date>1888</dc:date>',
'<dc:date>1923</dc:date>',
'<dc:source>From "the" internet</dc:source>',
'<dc:language>it</dc:language>',
Expand Down
51 changes: 51 additions & 0 deletions t/years.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!perl
use strict;
use warnings;


BEGIN {
$ENV{DBIX_CONFIG_DIR} = "t";
};

use Test::More tests => 4;
use File::Spec::Functions qw/catfile catdir/;
use lib catdir(qw/t lib/);
use AmuseWiki::Tests qw/create_site/;
use AmuseWikiFarm::Schema;
use Test::WWW::Mechanize::Catalyst;
use Data::Dumper::Concise;
use Path::Tiny;

my $schema = AmuseWikiFarm::Schema->connect('amuse');
my $site = create_site($schema, '0year0');

my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'AmuseWikiFarm',
host => $site->canonical);

foreach my $uri (qw/f-f-first/) {
my $file = path($site->repo_root, qw/f ff/, "$uri.muse");
$file->parent->mkpath;
my $muse = <<"MUSE";
#author <Author>
#topics <Topic>
#authors Author
#lang en
#date laskdf 2023
#datefirst lasdf 1932
MUSE
$file->spew_utf8($muse);
}


$site->update_db_from_tree(sub { diag @_ });


my $title = $site->titles->first;
is $title->date, "laskdf 2023";
is $title->datefirst, "lasdf 1932";
is $title->date_year, 2023;
is $title->year_first_edition, 1932;

diag "TODO: document in the manual the #datefirst";

0 comments on commit bec6b23

Please sign in to comment.