Skip to content

Commit

Permalink
Stub out document and manager routes
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Jan 31, 2024
1 parent 1ef78b9 commit a4fd628
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
Empty file added src/routes/app/+layout.js
Empty file.
3 changes: 3 additions & 0 deletions src/routes/app/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svelte:head>
<title>DocumentCloud</title>
</svelte:head>
37 changes: 37 additions & 0 deletions src/routes/documents/[id]-[slug]/+layout.js
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 };
}
34 changes: 34 additions & 0 deletions src/routes/documents/[id]-[slug]/+page.svelte
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>

0 comments on commit a4fd628

Please sign in to comment.