Skip to content

Commit

Permalink
git fit for new index of musical works, link to GND directly if it do…
Browse files Browse the repository at this point in the history
…esn't link to the index, see #57
  • Loading branch information
pfefferniels committed May 20, 2020
1 parent bf51866 commit dd2152d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
6 changes: 5 additions & 1 deletion public/css/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tei-person {
tei-person, tei-bibl {
display: block;
margin-bottom: 1.5rem;
}
Expand Down Expand Up @@ -32,6 +32,10 @@ tei-surname:after {
content: ', ';
}

tei-title {
font-style: italic;
}

.view-occurences {
display: block;
}
Expand Down
25 changes: 22 additions & 3 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ const cetei = new CETEI();

cetei.addBehaviors({
handlers: {
'idno': linkToGND
'idno': linkToGND,
"title": [
["tei-titlestmt>tei-title", function(elt) {
$(`<title>${elt.innerText}</title>`).appendTo('head');
$(`<h4>${elt.innerText}</h4>`).prependTo('#main');
}]
]
}
});

Expand Down Expand Up @@ -71,13 +77,26 @@ $(document).ready(function () {
$(this).append('<button type="button" class="btn btn-link view-occurences">view occurences</button>');
});

$('tei-bibl').each(function() {
$(this).append('<button type="button" class="btn btn-link view-occurences">view occurences</button>');
});

$('.view-occurences').click(async function() {
let parent = $(this).parent('tei-person');
let personId = parent.attr('id');
if (!parent.length) {
parent = $(this).parent('tei-bibl');
console.log(parent);
if (!parent.length) {
console.log('no corresponding id found.');
return;
}
}

let refId = parent.attr('id');

if (!parent.find('.references').length) {
let referencesEl = $('<div class="references"/>').appendTo(parent);
loadReferences(personId, referencesEl);
loadReferences(refId, referencesEl);
return;
};

Expand Down
23 changes: 16 additions & 7 deletions public/js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const cetei = new CETEI();
let scoreToolkit = new verovio.toolkit();
let vrvToolkit = new verovio.toolkit();

function isUrl(str) {
const urlRegex = /(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/;
return str.match(urlRegex);
}

function generatePDF() {
let options = {
fontCallback: function(family, bold, italic, fontOptions) {
Expand Down Expand Up @@ -52,14 +57,13 @@ function generatePDF() {
doc.end();
}

function gndReference(el) {
function linkTo(place, el) {
let ref = el.getAttribute('ref');
if (!ref) {
return $('<span/>').html(el.innerHTML)[0];
}

let newRef = '/index/persons' + ref;
return $('<a/>').attr('href', newRef).html(el.innerHTML)[0];
return $('<a/>').attr('href', isUrl(ref) ? ref : (place + ref)).html(el.innerHTML)[0];
}

function geoReference(el) {
Expand Down Expand Up @@ -108,9 +112,15 @@ function geoReference(el) {

cetei.addBehaviors({
handlers: {
'persName': gndReference,
'persName': function(el) {
return linkTo('/index/persons', el);
},

'placeName': geoReference,
'name': gndReference,

'name': function(el) {
return linkTo('/index/musicalWorks', el);
},

'facsimile': function(el) {
this.hideContent(el, false);
Expand Down Expand Up @@ -271,10 +281,9 @@ function connectCrossRefs(el) {
}

function reconnectCrossRefs() {
const uriRegex = /(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/;
$('tei-ref[target]').each(function() {
let target = $(this).attr('target');
if (target.match(uriRegex)) {
if (isUrl(target)) {
$(this).wrap(`<a href="${target}" />`);
} else {
connectCrossRefs(this);
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ index.get('/persons', function(req, res) {
.catch(e => console.error(e));
});

index.get('/musicalWorks', function(req, res) {
db.retrieve('indices/musical-works.xml')
.then(function (response) {
res.render('index', {
tei: response.data
});
})
.catch(e => console.error(e));
});


module.exports = index;
4 changes: 0 additions & 4 deletions views/index.pug
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
extends layout.pug

block headAdditions
title Index of Persons

link(rel='stylesheet' href='/css/index.css')

script(type='text/javascript' src='/js/index.js')
script.
tei = `!{tei}`;

block content
h4 Index of Persons

#main
3 changes: 3 additions & 0 deletions views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ mixin subitem(title)
li.nav-item.pl-1
a(href='/index/persons') Index of Persons

li.nav-item.pl-1
a(href='/index/musicalWorks') Index of Musical Works

.mt-1#options
block options

Expand Down

0 comments on commit dd2152d

Please sign in to comment.