From 8a236d6e5a1e21f8cbfcf4efa8de2f3291ded136 Mon Sep 17 00:00:00 2001 From: Emre Yurtseven Date: Tue, 28 May 2024 22:00:56 +0200 Subject: [PATCH] add wotd --- components/word_of_day.tsx | 2 +- routes/index.tsx | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/components/word_of_day.tsx b/components/word_of_day.tsx index 5c734c6..2838f02 100644 --- a/components/word_of_day.tsx +++ b/components/word_of_day.tsx @@ -16,7 +16,7 @@ export default function WordOfTheDay({ word, link }: WOTD) {
{word_data.word}
-
is the Duden's German word of the day.
+
is the Duden's German word of the day.
); } diff --git a/routes/index.tsx b/routes/index.tsx index d304d55..cba2d2a 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -8,6 +8,7 @@ import { Repositories } from "../components/classes/Github.ts"; import Rezensionen from "../components/rezensionen.tsx"; import MyFooter from "../components/my_footer.tsx"; import SmoothScrollBtn from "../islands/smoothscroll_btn.tsx"; +import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.45/deno-dom-wasm.ts"; interface InitialData { wotd: WOTD; @@ -30,22 +31,22 @@ export const handler: Handlers = { async GET(_req, ctx) { let wotd: WOTD = { word: '', link: '' }; - // const url = 'https://www.duden.de' - // const resp = await fetch(url) - // const html_data = await resp.text() - // const doc = new DOMParser().parseFromString(html_data, 'text/html') + const url = 'https://www.duden.de' + const resp = await fetch(url) + const html_data = await resp.text() + const doc = new DOMParser().parseFromString(html_data, 'text/html') - // if (doc !== null) { - // const word = doc.querySelector('#block-wordoftheday a.scene__title-link'); - // if (word !== null) { - // const link = word!.getAttribute('href'); - // const textContent = link?.split('/').reverse()[0] || ''; - // wotd = { - // word: textContent, - // link: url + link, - // }; - // } - // } + if (doc !== null) { + const word = doc.querySelector('#block-numero-wordoftheday a.scene__title-link'); + if (word !== null) { + const link = word!.getAttribute('href'); + const textContent = link?.split('/').reverse()[0] || ''; + wotd = { + word: textContent, + link: url + link, + }; + } + } if (Date.now() - lastFetch > 1000 * 60 * 5) { const repositories = await fetch(