From c28b7cc2146cc0b2583eb883d7eec7deba4659ba Mon Sep 17 00:00:00 2001 From: Sebastian Flick Date: Sat, 22 Jun 2024 22:03:18 +0200 Subject: [PATCH] styling and remove empty cols --- .../[[thirties]]/[[verse]]/+page.svelte | 123 +++++++++--------- .../[[verse]]/TextzeugenContent.svelte | 25 +++- 2 files changed, 85 insertions(+), 63 deletions(-) diff --git a/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.svelte b/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.svelte index 0ecb929..56de746 100644 --- a/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.svelte +++ b/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.svelte @@ -78,69 +78,70 @@ {#if data.content} - {#each data.content as content, i} -
-
-
-

Textzeuge: {generateLabel([content.sigla])}

-

- Vers: {localVerses[i]} -

- -
- {#await content.meta then meta} - {#if typeof meta === 'object' && typeof meta.tpData === 'object'} - {#await meta.tpData} -

Loading...

- {:then tpData} - {#if tpData} - {#if tpData?.content} - (localVerses[i] = e.detail)} - /> +
+ {#each data.content as content, i} +
+
+
+

Textzeuge: {generateLabel([content.sigla])}

+

+ Vers: {localVerses[i]} +

+ +
+ {#await content.meta then meta} + {#if typeof meta === 'object' && typeof meta.tpData === 'object'} + {#await meta.tpData} +

Loading...

+ {:then tpData} + {#if tpData} + {#if tpData?.content} + (localVerses[i] = e.detail)} + /> + {:else} + {JSON.stringify(tpData)} + {/if} {:else} - {JSON.stringify(tpData)} +

Der Vers existiert nicht

{/if} - {:else} -

Der Vers existiert nicht

+ {:catch error} +

{error.message}

+ {/await} + {/if} + {/await} +
+ {#if !($page.url.searchParams.get('iiif')?.split('-')[i] === 'true')} +
+ {#await content.meta then meta} + {#if typeof meta === 'object' && typeof meta.tpData === 'object'} + {#await meta.iiif} +

Loading...

+ {:then iiif} + {#if typeof iiif === 'object'} + + + {/if} + {:catch error} +

{error.message}

+ {/await} {/if} - {:catch error} -

{error.message}

{/await} - {/if} - {/await} -
-
- {#await content.meta then meta} - {#if typeof meta === 'object' && typeof meta.tpData === 'object'} - {#await meta.iiif} -

Loading...

- {:then iiif} - {#if typeof iiif === 'object'} - {#if !($page.url.searchParams.get('iiif')?.split('-')[i] === 'true')} - - - {:else} - - {/if} - {/if} - {:catch error} -

{error.message}

- {/await} - {/if} - {/await} -
-
- {/each} +
+ {:else} + + {/if} +
+ {/each} + {/if} diff --git a/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/TextzeugenContent.svelte b/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/TextzeugenContent.svelte index 8adad29..f2d0934 100644 --- a/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/TextzeugenContent.svelte +++ b/src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/TextzeugenContent.svelte @@ -86,15 +86,36 @@ destroy() {} }; }; + // returns true when the column is empty or when it contains only children that are empty or themselves have empty children (recursively) + const isEmptyColumn = (/** @type {String} */ column) => { + const parser = new DOMParser(); + const doc = parser.parseFromString(column, 'text/html'); + const children = doc.body.children; + for (let i = 0; i < children.length; i++) { + const child = children[i]; + if (child.children.length === 0) { + if (child.textContent.trim() !== '') { + return false; + } + } else { + if (!isEmptyColumn(child.innerHTML)) { + return false; + } + } + } + return true; + };
{#each columns as column} -
{@html column}
+ {#if !isEmptyColumn(column)} +
{@html column}
+ {/if} {/each}