diff --git a/src/lib/components/PostCard.svelte b/src/lib/components/PostCard.svelte index bd9ab80..5a48e3c 100644 --- a/src/lib/components/PostCard.svelte +++ b/src/lib/components/PostCard.svelte @@ -47,7 +47,7 @@ let contenido = $derived(() => { let t = post.content.replaceAll('\n', '
'); t = t.replace( - /#\w*/gm, + /#\p{L}*/u, (match) => `${match}` ); diff --git a/src/lib/hooks/obtenerCantidadDeUsosdeHtag.ts b/src/lib/hooks/obtenerCantidadDeUsosdeHtag.ts new file mode 100644 index 0000000..1289737 --- /dev/null +++ b/src/lib/hooks/obtenerCantidadDeUsosdeHtag.ts @@ -0,0 +1,22 @@ +import { apiBase } from '@/stores/url'; +import { sesionStore } from '@/stores/usuario'; +import { get } from 'svelte/store'; + +export async function obtenerCantidadDeUsosdeHtag(htag: string) { + if (!htag) return null; + try { + const req = await fetch(`${get(apiBase)}/api/posts/hashtag/${htag}`, { + method: 'GET', + headers: { + Authorization: `Bearer ${get(sesionStore)?.accessToken}` + } + }); + if (req.ok) { + let data = await req.json(); + return data; + } + return null; + } catch { + return null; + } +} diff --git a/src/routes/htag/[htag]/+page.svelte b/src/routes/htag/[htag]/+page.svelte new file mode 100644 index 0000000..8ad1003 --- /dev/null +++ b/src/routes/htag/[htag]/+page.svelte @@ -0,0 +1,75 @@ + + +
+
+ + + +

+ #{data.htag} +

+ + Uso del hashtag: + +
+
+ +

El hashtag se ha utilizado {data.cantidad} veces

+
+
+
+ +
+ {#each postsfiltro as post} + + {/each} +
+
+
+{#if postAModificar} +
+ +
+{/if} diff --git a/src/routes/htag/[htag]/+page.ts b/src/routes/htag/[htag]/+page.ts new file mode 100644 index 0000000..6055d00 --- /dev/null +++ b/src/routes/htag/[htag]/+page.ts @@ -0,0 +1,10 @@ +import { obtenerCantidadDeUsosdeHtag } from '@/hooks/obtenerCantidadDeUsosdeHtag.js'; +import { error } from '@sveltejs/kit'; + +export async function load({ params }) { + let { htag } = params; + + const cantidad = await obtenerCantidadDeUsosdeHtag(htag); + if (cantidad == null || cantidad.lenght == 0) return error(404, 'no existe el #(hashtag)'); + return { htag, cantidad }; +}