Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying slug for papers for more/memorable readable URLs #527

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/paper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ body:
validations:
required: true

- type: input
id: slug
attributes:
label: Slug
description: >-
An identifier for the publication. This is used in the URL for the publication page
manzt marked this conversation as resolved.
Show resolved Hide resolved
(e.g., `https://hidivelab.org/publications/<YYYY>-<last>-**<slug>**`).
If left blank, the Zotero ID will be used.
placeholder: "e.g., my-project, awesome-tool"

- type: input
id: preprint
attributes:
Expand Down
14 changes: 9 additions & 5 deletions scripts/update-hidive-paper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* ```json
* {
* "zotero_id": "ZOTERO_ITEM_ID" | ,
* "slug": "some-identifier",
* "preprint": "ZOTERO_ITEM_ID or URL",
* "image": "<img src='URL' alt='ALT'>",
* "lab_members": "MEMBER1\nMEMBER2\n...",
Expand Down Expand Up @@ -46,6 +47,9 @@ type PaperIssueTempalte = z.infer<typeof issueTemplateSchema>;

let issueTemplateSchema = z.object({
zotero_id: z.string().transform((x) => x.trim()),
slug: z.string()
.nullable()
.transform((x) => x?.trim()),
preprint: z.string()
.nullable()
.transform((x) => x?.trim())
Expand All @@ -56,10 +60,10 @@ let issueTemplateSchema = z.object({
imgTag = imgTag?.trim() ?? "";
let alt = null;
let src = null;
if(imgTag.match(/<img[^>]*>/)) {
if (imgTag.match(/<img[^>]*>/)) {
alt = imgTag.match(/alt="([^"]*)"/)?.[1] ?? null;
src = imgTag.match(/src="([^"]*)"/)?.[1] ?? null;
} else if(imgTag.match(/!\[[^\]]*\]\([^\)]*\)/)) {
} else if (imgTag.match(/!\[[^\]]*\]\([^\)]*\)/)) {
alt = imgTag.match(/!\[([^\]]*)\]/)?.[1] ?? null;
src = imgTag.match(/\(([^\)]*)\)/)?.[1] ?? null;
}
Expand Down Expand Up @@ -112,15 +116,15 @@ let issueTemplateSchema = z.object({
* Use the first author's last name, publication year, and Zotero key to create
* a slug for the file.
*/
function determineFileStem(item: ZoteroItem) {
function determineFileStem(item: ZoteroItem, slug?: string) {
// first author last name
let first = item.creators[0];
let last = "lastName" in first ? first.lastName : "consortium";
last = last.split(" ").join("").toLowerCase();
last = last.replace("'", ""); // For Sehi
last = last.replace("ö", "oe"); // For Eric
last = last.replace("ä", "ae");
return `${last}-${item.date.year}-${item.key}`;
return `${last}-${item.date.year}-${slug || item.key}`;
}

async function resolvePreprint(
Expand All @@ -146,7 +150,7 @@ async function processGitHubIssue(
): Promise<{ file: string; contents: LabPaperData }> {
let todoValue = "<TODO>";
let paper = await fetchZoteroItem(issue.zotero_id);
let stem = determineFileStem(paper);
let stem = determineFileStem(paper, issue.slug);
let preprint = await resolvePreprint(issue.preprint);

let { title, authors, published, year } = formatZoteroItem(paper, {
Expand Down
Loading