Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds redirects for other old embed routes #930

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@
"grid": "Pages",
"notes": "Notes",
"annotating": "Annotate",
"redacting": "Redact"
"redacting": "Redact",
"search": "Search"
},
"zoom": {
"zoom": "Zoom",
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/viewer/ReadingToolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Assumes it's a child of a ViewerContext
["text", $_("mode.text")],
["grid", $_("mode.grid")],
["notes", $_("mode.notes")],
["search", $_("mode.search")],
]);

const writeModes: Map<WriteMode, string> = new Map([
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/viewer/ViewerContext.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ layouts, stories, and tests.
}
$currentMode = mode;
$currentNote = $currentDoc.notes?.find(noteMatchingPageHash) ?? null;
if (shouldPaginate(mode) && $currentPage !== hashPage) {
if (shouldPaginate(mode) && (hashPage || 0) > 1) {
eyeseast marked this conversation as resolved.
Show resolved Hide resolved
scrollToHash(hash);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// this route was sometimes generated by old embeds and should redirect

import { redirect } from "@sveltejs/kit";
import { EMBED_URL } from "@/config/config.js";

export function load({ params }) {
const { id, note_id } = params;

// the embed route can handle errors
const url = new URL(
`/documents/${id}/annotations/${note_id}/?embed=1`,
EMBED_URL,
);

return redirect(302, url);
}
13 changes: 13 additions & 0 deletions src/routes/(app)/documents/[id]-[slug]/pages/[page]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// this route was sometimes generated by old embeds and should redirect

import { redirect } from "@sveltejs/kit";
import { EMBED_URL } from "@/config/config.js";

export function load({ params }) {
const { id, page } = params;

// if this is a 404, the embed route will handle it
const url = new URL(`/documents/${id}/pages/${page}/?embed=1`, EMBED_URL);

return redirect(302, url);
}
8 changes: 4 additions & 4 deletions src/routes/embed/documents/[id]/pages/[page]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@

<div class="dc-embed-container" class:active={Boolean(active)}>
<img
src={pageImageUrl(doc, page, "large").toString()}
src={pageImageUrl(doc, page, "large").href}
alt={$_("embedPage.pageOf", {
values: { page: page, title: doc.title },
})}
width="{width}px"
height="{height}px"
on:load={(e) => informSize(elem)}
on:load={() => informSize(elem)}
/>

<!-- Place notes on image -->
Expand Down Expand Up @@ -138,7 +138,7 @@
note={active}
{slugId}
{page}
on:close={(e) => (active = null)}
on:close={() => (active = null)}
/>
<Note active={true} note={active} />
{/if}
Expand Down Expand Up @@ -169,7 +169,7 @@
or
<a
style="color: #5a76a0; text-decoration: underline;"
href={textUrl(doc, page - 1).toString()}
href={textUrl(doc, page).href}
eyeseast marked this conversation as resolved.
Show resolved Hide resolved
title="Read the text of page {page} of {doc.title} on DocumentCloud in
new window or tab"
target="_blank"
Expand Down
Loading