-
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.
Stub out document and manager routes
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,3 @@ | ||
<svelte:head> | ||
<title>DocumentCloud</title> | ||
</svelte:head> |
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,37 @@ | ||
import { error, redirect } from "@sveltejs/kit"; | ||
import { BASE_API_URL } from "@/config/config.js"; | ||
|
||
const EXPAND = "user,organization"; | ||
|
||
/** | ||
* @type {import('./$types').PageLoad} | ||
* | ||
* @export | ||
* | ||
* Load a single document from the API | ||
* Example: https://api.www.documentcloud.org/api/documents/1/ | ||
* | ||
* We do this in a layout module because sub-routes can use the same | ||
* document without loading it again. | ||
*/ | ||
export async function load({ fetch, params }) { | ||
const endpoint = new URL(`documents/${params.id}.json`, BASE_API_URL); | ||
|
||
endpoint.searchParams.set("expand", EXPAND); | ||
|
||
const resp = await fetch(endpoint, { credentials: "include" }); | ||
|
||
if (!resp.ok) { | ||
console.error(endpoint.toString()); | ||
error(resp.status, resp.statusText); | ||
} | ||
|
||
const document = await resp.json(); | ||
|
||
if (document.slug !== params.slug) { | ||
const canonical = new URL(document.canonical_url); | ||
redirect(302, canonical.pathname); | ||
} | ||
|
||
return { document }; | ||
} |
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,34 @@ | ||
<script lang="ts"> | ||
import type { PageData } from "./$types"; | ||
import { embedUrl } from "@/api/embed.js"; | ||
import { pageImageUrl } from "@/api/viewer.js"; | ||
export let data: PageData; | ||
</script> | ||
|
||
<svelte:head> | ||
<!-- Insert canonical URL --> | ||
<link rel="canonical" href={data.document.canonical_url} /> | ||
|
||
{#if data.document.noindex || data.document.admin_noindex} | ||
<meta name="robots" content="noindex" /> | ||
{/if} | ||
<!-- Social cards --> | ||
<meta property="twitter:card" content="summary_large_image" /> | ||
<meta property="og:url" content={data.document.canonical_url} /> | ||
<meta property="og:url" content={data.document.canonical_url} /> | ||
<meta property="og:title" content={data.document.title} /> | ||
<title>{data.document.title} - DocumentCloud</title> | ||
<link | ||
rel="alternate" | ||
type="application/json+oembed" | ||
href={embedUrl(data.document.canonical_url)} | ||
title={data.document.title} | ||
/> | ||
{#if data.document?.description?.trim().length > 0} | ||
<meta property="og:description" content={data.document.description} /> | ||
{/if} | ||
<meta property="og:image" content={pageImageUrl(data.document, 0, 700, 1)} /> | ||
</svelte:head> | ||
|
||
<h1>{data.document.title}</h1> |