Skip to content

Commit

Permalink
Merge pull request #930 from MuckRock/928-page-link
Browse files Browse the repository at this point in the history
Adds redirects for other old embed routes
  • Loading branch information
eyeseast authored Dec 4, 2024
2 parents f77d2d8 + 6ff8921 commit ba7cba2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
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) {
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}
title="Read the text of page {page} of {doc.title} on DocumentCloud in
new window or tab"
target="_blank"
Expand Down

0 comments on commit ba7cba2

Please sign in to comment.