-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
468 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
import type { Document, Note, OEmbed } from "./types"; | ||
import { test, describe, expect } from "vitest"; | ||
|
||
import { APP_URL, BASE_API_URL } from "@/config/config.js"; | ||
import { embedUrl, getEmbed } from "./embed.js"; | ||
import { embedUrl, getEmbed } from "./embed"; | ||
|
||
import * as documents from "./documents"; | ||
import * as notes from "./notes.js"; | ||
|
||
import document from "./fixtures/documents/document.json"; | ||
import note from "./fixtures/notes/note.json"; | ||
import oembed from "./fixtures/oembed.json"; | ||
|
||
describe("embed tests", () => { | ||
test("embedUrl", () => { | ||
// document | ||
const docUrl = documents.canonicalUrl(document); | ||
const docUrl = documents.canonicalUrl(document as Document); | ||
expect(embedUrl(docUrl)).toStrictEqual( | ||
new URL(`oembed/?url=${docUrl.toString()}`, BASE_API_URL), | ||
); | ||
|
||
// note | ||
const noteUrl = notes.noteUrl(document, note); | ||
const noteUrl = notes.noteUrl(document as Document, note as Note); | ||
expect(embedUrl(noteUrl)).toStrictEqual( | ||
new URL(`oembed/?url=${noteUrl.toString()}`, BASE_API_URL), | ||
); | ||
}); | ||
|
||
test.todo("getEmbed"); | ||
/* need to sort out mocking first | ||
test("getEmbed", async () => { | ||
const url = | ||
"https://www.documentcloud.org/documents/282753-lefler-thesis.html"; | ||
const result = await getEmbed(url); | ||
expect(result).toEqual(oembed); | ||
}); | ||
*/ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
// api utilities for embeds | ||
|
||
import type { OEmbed } from "./types"; | ||
import { BASE_API_URL } from "@/config/config.js"; | ||
|
||
/** | ||
* Generate an oembed URL for a given DocumentCloud URL | ||
* | ||
* @export | ||
* @param {URL | string} url | ||
* @returns {URL} | ||
*/ | ||
export function embedUrl(url) { | ||
export function embedUrl(url: URL | string): URL { | ||
return new URL(`oembed/?url=${url.toString()}`, BASE_API_URL); | ||
} | ||
|
||
/** | ||
* Fetch embed code from the OEmbed API endpoint | ||
* | ||
* @export | ||
* @param {URL | string} url | ||
* @returns {import('./types').OEmbed} | ||
*/ | ||
export async function getEmbed(url) {} | ||
export async function getEmbed(url: URL | string): Promise<OEmbed> { | ||
const endpoint = embedUrl(url); | ||
|
||
return fetch(endpoint, { credentials: "include" }).then((r) => r.json()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "1.0", | ||
"provider_name": "DocumentCloud", | ||
"provider_url": "https://www.documentcloud.org", | ||
"cache_age": 300, | ||
"title": "Lefler Thesis", | ||
"width": 700, | ||
"height": 905, | ||
"html": "<iframe\n src=\"https://embed.documentcloud.org/documents/282753-lefler-thesis/?embed=1\"\n title=\"Lefler Thesis (Hosted by DocumentCloud)\"\n width=\"700\"\n height=\"905\"\n style=\"border: 1px solid #aaa;\"\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-forms allow-popups-to-escape-sandbox\"\n></iframe>\n", | ||
"type": "rich" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
export let key: string; | ||
export let value: string; | ||
</script> | ||
|
||
<div class="metadata"> | ||
<slot name="icon" /> | ||
<dl class="text"> | ||
<dt>{key}</dt> | ||
<dd>{value}</dd> | ||
</dl> | ||
</div> | ||
|
||
<style> | ||
.metadata { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: 0.5rem; | ||
} | ||
.text { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script context="module" lang="ts"> | ||
import { Story } from "@storybook/addon-svelte-csf"; | ||
import { Tag16 } from "svelte-octicons"; | ||
import Metadata from "../Metadata.svelte"; | ||
export const meta = { | ||
title: "Components / Common / Metadata", | ||
component: Metadata, | ||
tags: ["autodocs"], | ||
parameters: { layout: "centered" }, | ||
}; | ||
</script> | ||
|
||
<Story name="default"> | ||
<Metadata key="Last Updated" value="March 21, 2024" /> | ||
</Story> | ||
|
||
<Story name="icon"> | ||
<Metadata key="Last Updated" value="March 21, 2024"> | ||
<Tag16 slot="icon" /> | ||
</Metadata> | ||
</Story> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.