Skip to content

Commit

Permalink
contrôle miniatures : ajout d'un lien google images
Browse files Browse the repository at this point in the history
  • Loading branch information
mquandalle committed Aug 14, 2023
1 parent 9a5b96c commit 42f339b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/routes/dev/controle-miniatures/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
(ruleName) => ruleName.startsWith('aides .') && engine.getRule(ruleName).rawNode.titre
);
function simplifyTitle(title) {
return title
const simplifyTitle = (title) =>
title
.trim()
.replace(/ville (d'|d’|de)/i, '')
.replace(/communauté des? communes ?(du|de la|des|de)?/i, '')
.replace(/communauté( urbaine| d'agglomération( de)?)?/i, '')
.replace(/département (du|de la|de l'|de)/i, '')
.trim();
}
const googleSearchImageHref = (title) =>
`https://www.google.com/search?tbm=isch&q=${encodeURIComponent(`logo ${title}`)}`;
</script>

<h1 class="mx-4 my-2 font-bold font-serif">
<h1 class="mx-4 my-2 font-bold font-serif flex gap-x-3">
<span
class="mr-4 no-underline bg-gray-800 text-light-100 rounded-full px-2 py-1 uppercase text-xs font-bold tracking-widest self-center"
class="no-underline bg-gray-800 text-light-100 rounded-full px-2 py-1 uppercase text-xs font-bold tracking-widest self-center"
>DEV</span
>
Contrôle des miniatures
</h1>
<p class="mx-4 mb-4 text-xs text-gray-600">
Cliquez sur une image pour ouvrir une recherche Google Images.
</p>

<div
class="grid gap-2 items-stretch mx-4 mb-10"
Expand All @@ -33,15 +38,17 @@
{@const title = engine.getRule(aideRuleName).rawNode.titre}
<article class="flex flex-col justify-between items-center border shadow-sm p-2">
<div>
{#if miniaturesManifest[aideRuleName]}
<img
src="/miniatures/{miniaturesManifest[aideRuleName]}"
class="object-fill max-h-20"
alt="Logo {title.toLowerCase()}"
/>
{:else}
<div class="bg-gray-200 text-gray-800 italic text-center">Pas de miniature</div>
{/if}
<a href={googleSearchImageHref(title)}>
{#if miniaturesManifest[aideRuleName]}
<img
src="/miniatures/{miniaturesManifest[aideRuleName]}"
class="object-fill max-h-20"
alt="Logo {title.toLowerCase()}"
/>
{:else}
<span class="block bg-gray-200 text-gray-800 italic text-center">Pas de miniature</span>
{/if}
</a>
</div>
<h3 class="text-xs text-center mt-4">{simplifyTitle(title)}</h3>
</article>
Expand Down

0 comments on commit 42f339b

Please sign in to comment.