Skip to content

Commit

Permalink
Render corpus text details incl. publication
Browse files Browse the repository at this point in the history
  • Loading branch information
Mau Zsofia Abraham committed Feb 4, 2025
1 parent e78b9c1 commit 179fa1d
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 72 deletions.
70 changes: 49 additions & 21 deletions components/corpus-text-window-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const currentPage = ref(1);
const api = useApiClient();
const scrollComplete = ref<boolean>(false);
const teiHeader = simpleItems.value.find((header) => header.id === props.params.textId);
const publication = teiHeader?.publication;
const loadNextPage = async function () {
const text = await api.vicav.getCorpusText(
{
Expand Down Expand Up @@ -117,27 +119,53 @@ watch(utteranceElements.value, (value) => {
<div :id="params.textId" ref="utterancesWrapper" class="p-4">
<h2 class="m-3 text-lg">{{ props.params.label }}</h2>

<table class="m-3 border border-gray-300">
<thead>
<tr></tr>
<tr></tr>
</thead>
<tbody>
<tr>
<th>Recording:</th>
<td>{{ teiHeader?.resp }}</td>
</tr>
<tr>
<th>Speakers:</th>
<td>
<span v-for="(person, index) in teiHeader?.person" :key="index">
{{ person.name }} (age: {{ person.age }}, sex: {{ person.sex }})
<span v-if="index < (teiHeader?.person.length || 1) - 1">, </span>
</span>
</td>
</tr>
</tbody>
</table>
<div class="m-3 rounded-sm border border-gray-300 bg-gray-50 p-4">
<table>
<thead>
<tr></tr>
<tr></tr>
</thead>
<tbody>
<tr>
<th class="w-44">Recording:</th>
<td>
{{ teiHeader?.recording?.map((p) => [p.given, p.family].join(" ")).join(", ") }}
</td>
</tr>
<tr>
<th>Recording date:</th>
<td>{{ teiHeader?.recordingDate }}</td>
</tr>
<tr>
<th>Transcribed by:</th>
<td>
{{ teiHeader?.transcription?.map((p) => [p.given, p.family].join(" ")).join(", ") }}
</td>
</tr>
<tr v-if="teiHeader?.hasOwnProperty('transfer to ELAN')">
<th>Transferred to ELAN:</th>
<td>
{{
teiHeader["transfer to ELAN"].map((p) => [p.given, p.family].join(" ")).join(", ")
}}
</td>
</tr>
<tr v-if="publication">
<th class="align-text-top">Published in:</th>
<td><Citation v-bind="publication" /></td>
</tr>
<tr>
<th>Speakers:</th>
<td>
<span v-for="(person, index) in teiHeader?.person" :key="index">
{{ person.name }} (age: {{ person.age }}, sex: {{ person.sex }})
<span v-if="index < (teiHeader?.person.length || 1) - 1">, </span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
<table>
<tr
v-for="u in utterances"
Expand Down
94 changes: 71 additions & 23 deletions components/ui/citation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,102 @@ import type { simpleTEIMetadata } from "@/types/teiCorpus";
interface Props {
type: string;
refType?: "internal" | "external";
header?: simpleTEIMetadata;
bibl?: {
author: Array<CSLName>;
editor?: Array<CSLName>;
title: string;
"container-title"?: string;
issued?: Array<string>;
publisherPlace?: string;
page?: string;
volume?: string;
};
}
const { data: config } = useProjectInfo();
const props = defineProps<Props>();
const date = new Date();
const data = computed<CSLJSON>(() =>
props.type === "entry" && props.header
? {
type: "entry",
editor: config.value?.projectConfig?.editors as Array<CSLName>,
"container-title": config.value?.projectConfig?.title as string,
title: props.header.title as string,
author: props.header.author as Array<CSLName>,
issued: { "date-parts": [config.value?.projectConfig?.pubDate] } as CSLDate,
}
: {
type: "software",
editor: config.value?.projectConfig?.editors as Array<CSLName>,
title: config.value?.projectConfig?.title,
issued: { "date-parts": [config.value?.projectConfig?.pubDate] } as CSLDate,
},
);
const data = computed<CSLJSON>(() => {
if (props.type === "entry" && props.header) {
return {
type: "entry",
editor: config.value?.projectConfig?.editors as Array<CSLName>,
"container-title": config.value?.projectConfig?.title as string,
title: props.header.title as string,
author: (props.header.author ?? props.header.transcription ?? []) as Array<CSLName>,
issued: { "date-parts": [config.value?.projectConfig?.pubDate] } as CSLDate,
};
} else if (props.type === "book" && props.bibl) {
return {
type: "book",
title: props.bibl.title as string,
author: props.bibl.author as Array<CSLName>,
issued: { "date-parts": [props.bibl.issued?.map((i) => parseInt(i))] } as CSLDate,
publisherPlace: props.bibl.publisherPlace!,
};
} else if (props.type === "chapter" && props.bibl) {
return {
type: "chapter",
editor: props.bibl.editor as Array<CSLName>,
"container-title": props.bibl["container-title"] ? props.bibl["container-title"] : "",
title: props.bibl.title as string,
author: props.bibl.author as Array<CSLName>,
issued: { "date-parts": [props.bibl.issued?.map((i) => parseInt(i))] } as CSLDate,
publisherPlace: props.bibl.publisherPlace,
page: props.bibl.page,
};
} else if (props.type === "journalArticle" && props.bibl) {
return {
type: "article-journal",
editor: props.bibl.editor as Array<CSLName>,
"container-title": props.bibl["container-title"] ? props.bibl["container-title"] : "",
title: props.bibl.title as string,
author: props.bibl.author as Array<CSLName>,
issued: { "date-parts": [props.bibl.issued?.map((i) => parseInt(i))] } as CSLDate,
publisherPlace: props.bibl.publisherPlace,
page: props.bibl.page,
volume: props.bibl.volume,
};
} else {
return {
type: "software",
editor: config.value?.projectConfig?.editors as Array<CSLName>,
title: config.value?.projectConfig?.title,
issued: { "date-parts": [config.value?.projectConfig?.pubDate] } as CSLDate,
};
}
});
const url = window.location.href.replace(/(https?:\/\/.+)[/?].*/, "$1");
const cite = new Cite(data.value);
const appendText =
props.refType === "external"
? ""
: ` [Available online at ${url}. Accessed on ${String(date.getFullYear())}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}.]`;
const citation = computed(() =>
cite.format("bibliography", {
format: "html",
template: "apa",
// prepend (entry) {
// return `[${entry.id}]: `
// },
append: ` [Available online at ${url}.
Accessed on ${String(date.getFullYear())}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}.]`,
append: appendText,
}),
);
const citationText = computed(() =>
cite.format("bibliography", {
format: "text",
template: "apa",
// prepend (entry) {
// return `[${entry.id}]: `
// },
append: ` [Available online at ${url}.
Accessed on ${String(date.getFullYear())}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}.]`,
append: appendText,
}),
);
Expand All @@ -76,7 +122,9 @@ async function copyToClipboard(e: Event) {
</script>

<template>
<div class="m-4 flex flex-wrap gap-3 rounded-sm border-gray-300 bg-gray-100 p-4">
<!-- eslint-disable vue/no-v-html -->
<div v-if="props.refType === 'external'" v-html="citation" />
<div v-else class="m-4 flex flex-wrap gap-3 rounded-sm border-gray-300 bg-gray-100 p-4">
<div class="flex-none"><Quote class="h-4" /></div>
<!-- eslint-disable vue/no-v-html -->
<div class="flex-1" v-html="citation" />
Expand Down
139 changes: 112 additions & 27 deletions composables/use-tei-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed } from "vue";
import type {
PersName,
Person,
Responsibility,
RespStmt,
simpleTEIMetadata,
Taxonomy,
Expand Down Expand Up @@ -69,7 +70,7 @@ const extractMetadata = function (
"@hasTEIw": "false",
teiHeader: item.teiHeader,
} as simpleTEIMetadata;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

template.id = item["@id"]
? item["@id"]
: item.teiHeader.fileDesc.publicationStmt.idno?.$
Expand Down Expand Up @@ -157,33 +158,117 @@ const extractMetadata = function (
template.resp = "Unknown";
}

if (
item.teiHeader.fileDesc.titleStmt.respStmts?.find((r) =>
["author", "recording", "principal"].includes(r.resp.$),
) &&
corpusMetadata
) {
template.author = item.teiHeader.fileDesc.titleStmt.respStmts
.filter((r) => ["author", "recording", "principal"].includes(r.resp.$))
.map((resp) => {
const respPerson = corpusMetadata.fileDesc.titleStmt.respStmts?.find((resp2: RespStmt) => {
if (resp2.persName) {
return resp.persName!["@ref"] === resp2.persName["@ref"];
} else {
return false;
}
});
(
[
"author",
"recording",
"principal",
"transcription",
"transfer to ELAN",
] as Array<Responsibility>
).forEach((responsibility) => {
if (
item.teiHeader.fileDesc.titleStmt.respStmts?.find((r) => r.resp.$ === responsibility) &&
corpusMetadata
) {
template[responsibility as keyof simpleTEIMetadata] =
item.teiHeader.fileDesc.titleStmt.respStmts
.filter((r) => responsibility === r.resp.$)
.map((resp) => {
const respPerson = corpusMetadata.fileDesc.titleStmt.respStmts?.find(
(resp2: RespStmt) => {
if (resp2.persName) {
return resp.persName!["@ref"] === resp2.persName["@ref"];
} else {
return false;
}
},
);

if (!respPerson) {
return { family: "", given: "" };
} else {
const persName = respPerson.persName as PersName;
return {
given: persName.forename!.$,
family: persName.surname!.$,
};
}
});
if (!respPerson) {
return { family: "", given: "" };
} else {
const persName = respPerson.persName as PersName;
return {
given: persName.forename!.$,
family: persName.surname!.$,
};
}
});
}
});

if (item.teiHeader.fileDesc.sourceDesc.biblStruct?.["@type"] === "bookSection") {
template.publication = {
refType: "external",
type: "chapter",
bibl: {
"container-title": item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.title?.$,
title: item.teiHeader.fileDesc.sourceDesc.biblStruct.analytic?.title.$ ?? "",
author: [
{
given: item.teiHeader.fileDesc.sourceDesc.biblStruct.analytic?.author.forename?.$ ?? "",
family: item.teiHeader.fileDesc.sourceDesc.biblStruct.analytic?.author.surname?.$ ?? "",
},
],
editor: [
{
given: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.editor?.forename?.$ ?? "",
family: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.editor?.surname?.$ ?? "",
},
],
issued: [item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.date.$ ?? ""],
publisherPlace: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.pubPlace?.$,
page: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.biblScope.find(
(s) => s["@unit"] === "page",
)?.$,
},
};
} else if (item.teiHeader.fileDesc.sourceDesc.biblStruct?.["@type"] === "journalArticle") {
template.publication = {
refType: "external",
type: "journalArticle",
bibl: {
"container-title": item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.title?.$,
title: item.teiHeader.fileDesc.sourceDesc.biblStruct.analytic?.title.$ ?? "",
author: [
{
given: item.teiHeader.fileDesc.sourceDesc.biblStruct.analytic?.author.forename?.$ ?? "",
family: item.teiHeader.fileDesc.sourceDesc.biblStruct.analytic?.author.surname?.$ ?? "",
},
],
editor: [
{
given: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.editor?.forename?.$ ?? "",
family: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.editor?.surname?.$ ?? "",
},
],
issued: [item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.date.$ ?? ""],
publisherPlace: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.pubPlace?.$,
volume: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.biblScope.find(
(s) => s["@unit"] === "volume",
)?.$,
page: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.biblScope.find(
(s) => s["@unit"] === "page",
)?.$,
},
};
} else if (item.teiHeader.fileDesc.sourceDesc.biblStruct?.["@type"] === "thesis") {
template.publication = {
refType: "external",
type: "book",
bibl: {
title: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.title?.$ ?? "",
author: [
{
given: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.author?.forename?.$ ?? "",
family: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.author?.surname?.$ ?? "",
},
],
issued: [item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.date.$ ?? ""],
publisherPlace: item.teiHeader.fileDesc.sourceDesc.biblStruct.monogr.imprint?.pubPlace?.$,
},
};
}

template.person = extractPersons(item, corpusMetadata);
Expand Down
Loading

0 comments on commit 179fa1d

Please sign in to comment.