diff --git a/netlify.toml b/netlify.toml index b9954104b..94ab225b1 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,6 +2,9 @@ command = "npm run build" publish = "build" +[[context.production.plugins]] +package = "/plugins/cache-bust" + [[plugins]] package = "@netlify/plugin-lighthouse" # https://github.com/netlify/netlify-plugin-lighthouse diff --git a/src/routes/(app)/documents/[id]-[slug].[format]/+page.ts b/src/routes/(app)/documents/[id]-[slug].[format]/+page.ts new file mode 100644 index 000000000..3e8006814 --- /dev/null +++ b/src/routes/(app)/documents/[id]-[slug].[format]/+page.ts @@ -0,0 +1,43 @@ +// handle .html and other file extension routes from old versions of DocumentCloud + +import { error, redirect } from "@sveltejs/kit"; +import * as documents from "$lib/api/documents"; + +export const trailingSlash = "never"; + +export async function load({ params, fetch }) { + const { id, format } = params; + + const { data: document, error: err } = await documents.get(id, fetch); + + if (err) { + return error(err.status, err.message); + } + + if (!document) { + return error(404, "Not found"); + } + + let url: URL; + + switch (format) { + // for .html, redirect to embed + case "html": + url = documents.embedUrl(document); + return redirect(302, url); + + case "txt": + url = documents.canonicalUrl(document); + url.searchParams.set("mode", "text"); + return redirect(302, url); + + // redirect to the PDF file, no-op for errors + case "pdf": + url = documents.pdfUrl(document); + return redirect(302, url); + + // fallback: redirect to the canonical path, on the same host + default: + return redirect(302, documents.canonicalUrl(document)); + } +} diff --git a/src/routes/(app)/documents/[id]-[slug]/+page.ts b/src/routes/(app)/documents/[id]-[slug]/+page.ts index 63110c1eb..74a94e72b 100644 --- a/src/routes/(app)/documents/[id]-[slug]/+page.ts +++ b/src/routes/(app)/documents/[id]-[slug]/+page.ts @@ -29,7 +29,7 @@ export async function load({ depends(`document:${document.id}`); - const canonical = new URL(document.canonical_url); + const canonical = documents.canonicalUrl(document); if (document.slug !== params.slug) { redirect(302, canonical.pathname); } diff --git a/src/routes/(app)/projects/[id]/+page.ts b/src/routes/(app)/projects/[id]/+page.ts index 05aacc027..12cefc8b5 100644 --- a/src/routes/(app)/projects/[id]/+page.ts +++ b/src/routes/(app)/projects/[id]/+page.ts @@ -6,14 +6,14 @@ import * as projects from "$lib/api/projects"; export async function load({ params, fetch }) { const { data: project, error: err } = await projects.get(+params.id, fetch); - if (!project) { - return error(404, "Project not found"); - } - if (err) { return error(err.status, err.message); } + if (!project) { + return error(404, "Project not found"); + } + const url = projects.canonicalUrl(project); return redirect(302, url); diff --git a/static/apple-touch-icon-120x120-precomposed.png b/static/apple-touch-icon-120x120-precomposed.png new file mode 100755 index 000000000..497066d18 Binary files /dev/null and b/static/apple-touch-icon-120x120-precomposed.png differ diff --git a/static/apple-touch-icon-precomposed.png b/static/apple-touch-icon-precomposed.png new file mode 100755 index 000000000..497066d18 Binary files /dev/null and b/static/apple-touch-icon-precomposed.png differ diff --git a/static/apple-touch-icon.png b/static/apple-touch-icon.png new file mode 100755 index 000000000..497066d18 Binary files /dev/null and b/static/apple-touch-icon.png differ