diff --git a/src/lib/api/fixtures/documents/document.txt.json b/src/lib/api/fixtures/documents/document.txt.json new file mode 100644 index 000000000..c427ad071 --- /dev/null +++ b/src/lib/api/fixtures/documents/document.txt.json @@ -0,0 +1,26 @@ +{ + "updated": 1708614455938, + "pages": [ + { + "page": 0, + "contents": "\u201cThe Santa Anas\u201d\nJoan Didion\nThere is something uneasy in the Los Angeles air this afternoon, some unnatural \nstillness, some tension. What it means is that tonight a Santa Ana will begin to \nblow, a hot wind from the northeast whining down through the Cajon and San \nGorgonio Passes, blowing up sand storms out along Route 66, drying the hills and \nthe nerves to flash point. For a few days now we will see smoke back in the \ncanyons, and hear sirens in the night. \nI have neither heard nor read that a Santa Ana is due, but I know it, and almost \neveryone I have seen today knows it too. We know it because we feel it. The baby \nfrets. The maid sulks. I rekindle a waning argument with the telephone company, \nthen cut my losses and lie down, given over to whatever it is in the air. To live \nwith the Santa Ana is to accept, consciously or unconsciously, a deeply \nmechanistic view of human behavior.\nI recall being told, when I first moved to Los Angeles and was living on an \nisolated beach, that the Indians would throw themselves into the sea when the bad \nwind blew. I could see why. The Pacific turned ominously glossy during a Santa \nAna period, and one woke in the night troubled not only by the peacocks \nscreaming in the olive trees but by the eerie absence of surf. The heat was surreal. \nThe sky had a yellow cast, the kind of light sometimes called \"earthquake \nweather\". My only neighbor would not come out of her house for days, and there \nwere no lights at night, and her husband roamed the place with a machete. One \nday he would tell me that he had heard a trespasser, the next a rattlesnake. \n\"On nights like that,\" Raymond Chandler once wrote about the Santa Ana, \"every \nbooze party ends in a fight. Meek little wives feel the edge of the carving knife \nand study their husbands' necks. Anything can happen.\" That was the kind of \nwind it was. I did not know then that there was any basis for the effect it had on \nall of us, but it turns out to be another of those cases in which science bears out \nfolk wisdom. \nThe Santa Ana, which is named for one of the canyons it rushers through, is foehn \nwind, like the foehn of Austria and Switzerland and the hamsin of Israel. There \nare a number of persistent malevolent winds, perhaps the best know of which are \nthe mistral of France and the Mediterranean sirocco, but a foehn wind has distinct \ncharacteristics: it occurs on the leeward slope of a mountain range and, although \nthe air begins as a cold mass, it is warmed as it comes down the mountain and \nappears finally as a hot dry wind. Whenever and wherever foehn blows, doctors \nhear about headaches and nausea and allergies, about \"nervousness,\" about \n\"depression.\" \nIn Los Angeles some teachers do not attempt to conduct formal classes during a \nSanta Ana, because the children become unmanageable. In Switzerland the \u0000", + "ocr": null, + "lang": "eng", + "updated": 1708614455938 + }, + { + "page": 1, + "contents": "suicide rate goes up during the foehn, and in the courts of some Swiss cantons the \nwind is considered a mitigating circumstance for crime. Surgeons are said to \nwatch the wind, because blood does not clot normally during a foehn. \nA few years ago an Israeli physicist discovered that not only during such winds, \nbut for the ten or twelve hours which precede them, the air carries an unusually \nhigh ratio of positive to negative ions. No one seems to know exactly why that \nshould be; some talk about friction and others suggest solar disturbances. In any \ncase the positive ions are there, and what an excess of positive ions does, in the \nsimplest terms, is make people unhappy. One cannot get much more mechanistic \nthan that. \nEasterners commonly complain that there is no \"weather\" at all in Southern \nCalifornia, that the days and the seasons slip by relentlessly, numbingly bland. \nThat is quite misleading. In fact the climate is characterized by infrequent but \nviolent extremes: two periods of torrential subtropical rains which continue for \nweeks and wash out the hills and send subdivisions sliding toward the sea; about \ntwenty scattered days a year of the Santa Ana, which, with its incendiary dryness, \ninvariably means fire. At the first prediction of a Santa Ana, the Forest Service \nflies men and equipment from northern California into the southern forests, and \nthe Los Angeles Fire Department cancels its ordinary non-firefighting routines. \nThe Santa Ana caused Malibu to burn as it did in 1956, and Bel Air in 1961, and \nSanta Barbara in 1964. In the winter of 1966-67 eleven men were killed fighting a \nSanta Ana fire that spread through the San Gabriel Mountains.\nJust to watch the front-page news out of Los Angeles during a Santa Ana is to get \nvery close to what it is about the place. The longest single Santa Ana period in \nrecent years was in 1957, and it lasted not the usual three or four days but \nfourteen days, from November 21 until December 4. On the first day 25,000 acres \nof the San Gabriel Mountains were burning, with gusts reaching 100 miles an \nhour. In town, the wind reached Force 12, or hurricane force, on the Beaufort \nScale; oil derricks were toppled and people ordered off the downtown streets to \navoid injury from flying objects. On November 22 the fire in the San Gabriels \nwas out of control. On November 24 six people were killed in automobile \naccidents, and by the end of the week the Los Angeles Times was keeping a box \nscore of traffic deaths. On November 26 a prominent Pasadena attorney, \ndepressed about money, shot and killed his wife, their two sons and himself. On \nNovember 27 a South Gate divorc\u00e9e, twenty-two, was murdered and thrown from \na moving car. On November 30 the San Gabriel fire was still out of control, and \nthe wind in town was blowing eighty miles an hour. On the first day of December \nfour people died violently, and on the third the wind began to break. \nIt is hard for people who have not lived in Los Angeles to realize how radically \nthe Santa Ana figures in the local imagination. The city burning is Los Angeles's \ndeepest image of itself. Nathaniel West perceived that, in The Day of the Locust, \nand at the time of the 1965 Watts riots what struck the imagination most indelibly \u0000", + "ocr": null, + "lang": "eng", + "updated": 1708614455938 + }, + { + "page": 2, + "contents": "were the fires. For days one could drive the Harbor Freeway and see the city on \nfire, just as we had always known it would be in the end. \nLos Angeles weather is the weather of catastrophe, of apocalypse, and, just as the \nreliably long and bitter winters of New England determine the way life is lived \nthere, so the violence and the unpredictability of the Santa Ana affect the entire \nquality of life in Los Angeles, accentuate its impermanence, its unreliability. The \nwinds shows us how close to the edge we are. \nin Slouching Towards Bethlehem, 1969, London: Andre Deutch.\u0000", + "ocr": null, + "lang": "eng", + "updated": 1708614455938 + } + ] +} diff --git a/src/lib/api/types.d.ts b/src/lib/api/types.d.ts index 3359c317e..28e451967 100644 --- a/src/lib/api/types.d.ts +++ b/src/lib/api/types.d.ts @@ -207,4 +207,18 @@ export interface Pending { pages: number; } +// See JSON Text https://www.documentcloud.org/help/api/#static-assets +export interface TextPage { + page: number; + contents: string; + ocr: string | null; + lang: string; + updated: number; // timestamp +} + +export interface DocumentText { + updated: number; // timestamp + pages: TextPage[]; +} + export type ProjectMembershipList = Page; diff --git a/src/lib/components/documents/TextPage.svelte b/src/lib/components/documents/TextPage.svelte new file mode 100644 index 000000000..b45f6338c --- /dev/null +++ b/src/lib/components/documents/TextPage.svelte @@ -0,0 +1,37 @@ + + +
+

+ {$_("documents.pageAbbrev")} {page + 1} +

+ +
+    {contents}
+  
+
+ + diff --git a/src/lib/components/documents/stories/TextPage.stories.svelte b/src/lib/components/documents/stories/TextPage.stories.svelte new file mode 100644 index 000000000..c15474c3c --- /dev/null +++ b/src/lib/components/documents/stories/TextPage.stories.svelte @@ -0,0 +1,19 @@ + + + + + diff --git a/src/routes/documents/[id]-[slug]/+layout.ts b/src/routes/documents/[id]-[slug]/+layout.ts index 1df17523c..c585e01a1 100644 --- a/src/routes/documents/[id]-[slug]/+layout.ts +++ b/src/routes/documents/[id]-[slug]/+layout.ts @@ -18,7 +18,6 @@ function documentPath(document: Document) { export async function load({ fetch, params, parent }) { const document = await documents.get(+params.id, fetch).catch(console.error); - console.log({ document }); if (!document) { error(404, "Document not found"); } diff --git a/src/routes/documents/[id]-[slug]/text/+page.svelte b/src/routes/documents/[id]-[slug]/text/+page.svelte new file mode 100644 index 000000000..7b207b8fa --- /dev/null +++ b/src/routes/documents/[id]-[slug]/text/+page.svelte @@ -0,0 +1,13 @@ + + +
+ {#each pages as { page, contents }} + + {/each} +
diff --git a/src/routes/documents/[id]-[slug]/text/+page.ts b/src/routes/documents/[id]-[slug]/text/+page.ts new file mode 100644 index 000000000..6d4860c34 --- /dev/null +++ b/src/routes/documents/[id]-[slug]/text/+page.ts @@ -0,0 +1,26 @@ +import type { DocumentText } from "$lib/api/types"; + +import { jsonUrl } from "$lib/api/documents"; +import { error } from "@sveltejs/kit"; +import { isErrorCode } from "@/lib/utils/api.js"; + +export async function load({ fetch, parent }) { + const { document } = await parent(); + const url = jsonUrl(document); + + const resp = await fetch(url).catch(console.error); + + if (!resp) { + error(500, "Server error"); + } + + if (isErrorCode(resp.status)) { + error(resp.status, resp.statusText); + } + + const text: DocumentText = await resp.json(); + + return { + pages: text.pages, + }; +}