Skip to content

Commit

Permalink
fixing read file
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Flick committed Oct 2, 2024
1 parent 9532758 commit 7411bc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/routes/einzelverssynopse/+layout.server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { teipb, api } from '$lib/constants';
import { writeFile } from 'node:fs';
import { writeFile, readFile } from 'node:fs/promises';

/** @type {import('./$types').LayoutServerLoad} */
export async function load({ fetch }) {
console.log('loading einzelverssynopse');
let publisherData;
try {
publisherData = await import('./publisherdata_verse.json');
} catch (_error) {
publisherData = await readFile('./src/routes/einzelverssynopse/publisherdata_verse.json', { encoding: 'utf8' });
publisherData = JSON.parse(publisherData);
} catch (error) {
console.error('error importing the file', error);
console.log('fetching from api');
const { codices } = await fetch(`${api}/json/metadata-nomenclature.json`).then((r) => r.json());
const siglaArray = codices.map((/** @type {{ handle: string; }} */ codex) => codex.handle);
Expand Down
16 changes: 9 additions & 7 deletions src/routes/einzelverssynopse/[thirties]/[verse]/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { api, teipb } from '$lib/constants';
import { generateEntries } from '$lib/functions';
import { JSDOM } from 'jsdom';

/** @type {import('./$types').PageServerLoad} */
export async function load({ fetch, params, parent }) {
Expand All @@ -15,12 +14,15 @@ export async function load({ fetch, params, parent }) {

// Fetch the textzeugen
sigla.codices.forEach(async (/** @type {{ handle: string; }} */ element) => {
const html = JSDOM.fragment((await rawPublisherData[element.handle]).content);
console.log('created fragment');
const line = html.querySelector(`span[data-verse="${thirties}.${verse}"]`);
console.log('found line', line);
if (line) {
publisherData[element.handle] = line.outerHTML;
// const html = JSDOM.fragment((await rawPublisherData[element.handle]).content);
// console.log('created fragment');
// const line = html.querySelector(`span[data-verse="${thirties}.${verse}"]`);
const content = (await rawPublisherData[element.handle]).content;
const start = content.indexOf(`<span class="verse-inline" data-verse="${thirties}.${verse}">`);
const end = content.indexOf('</span>', start);
if (start !== -1 && end !== -1) {
const line = content.slice(start, end);
publisherData[element.handle] = line;
}
});
// Fetch fassungen
Expand Down

0 comments on commit 7411bc5

Please sign in to comment.