Skip to content

Commit

Permalink
fix: ODS links
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Jul 22, 2024
1 parent 12ab7be commit 4570fbc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
19 changes: 19 additions & 0 deletions app/utils/opendata.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DataCubeMetadata } from "@/domain/data";
import { makeOpenDataLink } from "@/utils/opendata";

describe("makeOpenDataLink", () => {
it("should remove creator slug from identifier", () => {
const orgSuffix = "exampleOrg";
const cube = {
identifier: `https://ld.admin.ch/data/123@${orgSuffix}`,
creator: {
iri: `https://register.ld.admin.ch/opendataswiss/org/${orgSuffix}`,
},
workExamples: ["https://ld.admin.ch/application/opendataswiss"],
} as DataCubeMetadata;

expect(makeOpenDataLink("de", cube)).toBe(
`https://opendata.swiss/de/perma/${encodeURIComponent(`https://ld.admin.ch/data/123@${orgSuffix}`)}`
);
});
});
11 changes: 7 additions & 4 deletions app/utils/opendata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export const makeOpenDataLink = (lang: string, cube: DataCubeMetadata) => {
return;
}

const creatorSlug = creatorIri.replace(
"https://register.ld.admin.ch/opendataswiss/org/",
""
);

return `https://opendata.swiss/${lang}/perma/${encodeURIComponent(
`${identifier}@${creatorIri.replace(
"https://register.ld.admin.ch/opendataswiss/org/",
""
)}`
// Sometimes the identifier is prefixed with the creator slug
`${identifier.replace(`@${creatorSlug}`, "")}@${creatorSlug}`
)}`;
};

0 comments on commit 4570fbc

Please sign in to comment.