Skip to content

Commit

Permalink
Added label script
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Jul 9, 2024
1 parent a2cd9f1 commit 6636045
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/sync-libis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup bun.sh environment
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- run: |
git clone --depth=1 --branch=main https://github.com/libis/ca_tudelft_iiif
pwd
Expand All @@ -22,6 +27,7 @@ jobs:
cp -a ca_tudelft_iiif/objects/. apps/iiif/manifests/collective-access/objects
cp -a ca_tudelft_iiif/collections/. apps/iiif/manifests/collective-access/collections
rm -r ca_tudelft_iiif
bun run ./process-libis.mts
git config user.name github-actions
git config user.email [email protected]
git add .
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@tailwindcss/typography": "^0.5.10",
"@types/bun": "^1.1.6",
"autoprefixer": "^10.4.16",
"contentlayer": "^0.3.4",
"github-slugger": "^2.0.0",
Expand All @@ -33,6 +34,7 @@
"packages/*"
],
"dependencies": {
"bun-types": "*",
"@types/react-lazy-load-image-component": "^1.6.3",
"react-instantsearch-router-nextjs": "^7.7.0",
"react-social-icons": "^6.14.0"
Expand Down
29 changes: 29 additions & 0 deletions process-libis.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { readdir } from "node:fs/promises";
import { cwd } from "node:process";
import { join } from "node:path";

const manifestsToProcess = [
// Add new lines for more manifests to process
...(await readdir(join(cwd(), "apps/iiif/manifests/collective-access/objects"))).map((r) => {
return join(cwd(), "apps/iiif/manifests/collective-access/objects", r);
}),
];

for (const manifestPath of manifestsToProcess) {
const file = Bun.file(manifestPath);

try {
const manifestJson = await file.json();
if (manifestJson && !manifestJson.label && manifestJson.metadata) {
const foundMetadata = manifestJson.metadata.find((m: any) => m.label === "Titel" || m.label === "Title");
if (foundMetadata && foundMetadata.value) {
manifestJson.label = foundMetadata.value;
await Bun.write(file, JSON.stringify(manifestJson, null, 2));
}
}

console.log(manifestPath);
} catch (e) {
console.error(e);
}
}

0 comments on commit 6636045

Please sign in to comment.