Skip to content

Commit

Permalink
feat: display "earlier editions" on detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Dec 2, 2024
1 parent aefc275 commit f8c7d9d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
27 changes: 24 additions & 3 deletions app/[locale]/publications/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default async function PublicationPage(props: PublicationPageProps) {
return notFound();
}

// array of (Publication) promises
const earlier = pub.parents?.map((id) => {
return getPublication(id);
});

// array of (Publication) promises
const later = pub.later?.map((id) => {
return getPublication(id);
Expand Down Expand Up @@ -72,7 +77,7 @@ export default async function PublicationPage(props: PublicationPageProps) {
})
.join(" / ")}
</p>
<div className="flex gap-8">
<div className="flex gap-8 py-8">
<div className="relative h-96 min-w-44 grow basis-1/3">
<PublicationCover publication={pub} />
</div>
Expand Down Expand Up @@ -128,9 +133,25 @@ export default async function PublicationPage(props: PublicationPageProps) {
</div>
</div>

{earlier ? (
<>
<h2 className="pt-10 font-bold">{t("earlier_editions")}</h2>
<div className="flex">
{earlier.map(async (pp) => {
const p = await pp;
return (
<div key={p!.id} className="size-44 p-4">
<ClickablePublicationThumbnail publication={p!} />
</div>
);
})}
</div>
</>
) : null}

{later ? (
<>
<h2 className="pb-2 pt-6 font-bold">{t("later_editions")}</h2>
<h2 className="pt-10 font-bold">{t("later_editions")}</h2>
<div className="flex">
{later.map(async (pp) => {
const p = await pp;
Expand All @@ -145,7 +166,7 @@ export default async function PublicationPage(props: PublicationPageProps) {
) : null}

<section>
<h2 className="pb-2 pt-6 font-bold">
<h2 className="pt-10 font-bold">
{t("more_in")} {pub.language}
</h2>
<div className="flex">
Expand Down
1 change: 1 addition & 0 deletions lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Publication {

// ids of publications which contain re-prints of some of the translations first published in this
// publication. this field is inferred from the 'eltern' column in openrefine.
parents?: Array<string>;
later?: Array<string>;
year: number;
year_display?: string;
Expand Down
1 change: 1 addition & 0 deletions messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"more_in": "mehr auf",
"publisher": "Verlag / Publikation",
"translated_by": "übersetzt von",
"earlier_editions": "frühere Editionen",
"later_editions": "spätere Editionen",
"year": "Veröffentlichungsjahr"
},
Expand Down
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"more_in": "more in",
"publisher": "published by",
"translated_by": "contains translations by",
"earlier_editions": "earlier publications",
"later_editions": "later editions",
"year": "publication year"
},
Expand Down
39 changes: 27 additions & 12 deletions scripts/3_to_typesense.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,35 @@ def load_json(dirname, filename):
def merge_changes(orig, changed, field_names):
for e1, e2 in zip(orig, changed):
for f in field_names:
if isinstance(e2[f], dict):
e2[f] = e2[f]["value"]
elif isinstance(e1[f], int):
e2[f] = int(e2[f])

if e1[f] != e2[f]: # TODO check types and force original numbers
logging.info(
f"integrating manual change to field {f}: '{e1[f]}' > '{e2[f]}'"
)
e1[f] = e2[f]
try:
if isinstance(e2[f], dict):
e2[f] = e2[f]["value"]
elif isinstance(e1[f], int):
e2[f] = int(e2[f])

if e1[f] != e2[f]: # TODO check types and force original numbers
logging.info(
f"integrating manual change to field {f}: '{e1[f]}' > '{e2[f]}'"
)
e1[f] = e2[f]
except KeyError:
if e2[f]:
logging.info(f"adding new field {f} with value '{e2[f]}'")
e1[f] = e2[f]


# for publication: title, year, year_display, publisher, publication_details, exemplar_...
merge_changes(
publications,
publication_changes,
["title", "year", "year_display", "publisher", "publication_details"],
[
"title",
"short_title",
"year",
"year_display",
"publisher",
"publication_details",
],
)
merge_changes(translations, translation_changes, ["title", "work_display_title"])
merge_changes(works, work_changes, ["title", "short_title", "year", "category", "gnd"])
Expand Down Expand Up @@ -137,6 +149,9 @@ def del_empty_strings(o, field_names):

for i, pub in enumerate(publications):
pub["id"] = str(i + 1)
if not w["short_title"]:
w["short_title"] = w["title"]

pub["contains"] = [translations[t_id - 1] for t_id in pub["contains"]]

pub["images"] = (
Expand All @@ -152,7 +167,7 @@ def del_empty_strings(o, field_names):
else:
publications[pid - 1]["later"] = [i + 1]

del_empty_strings(pub, ["publication_details"])
del_empty_strings(pub, ["parents", "publication_details"])

# trim data a little
del pub["exemplar_suhrkamp_berlin"]
Expand Down

0 comments on commit f8c7d9d

Please sign in to comment.