Skip to content

Commit

Permalink
add wotd
Browse files Browse the repository at this point in the history
  • Loading branch information
yurtemre7 committed May 28, 2024
1 parent 9ab58a6 commit 8a236d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/word_of_day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function WordOfTheDay({ word, link }: WOTD) {
<div className="flex-col items-center justify-center text-white">

<div className="text-5xl m-2 font-serif"> <a className="hover:underline" href={word_data.link}>{word_data.word}</a></div>
<div className="text-xl">is the <a className="hover:underline" href="https://www.duden.de">Duden</a>'s German word of the day.</div>
<div className="text-xl">is the <a className="underline bold" href="https://www.duden.de">Duden</a>'s German word of the day.</div>
</div>
);
}
Expand Down
31 changes: 16 additions & 15 deletions routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,22 +31,22 @@ export const handler: Handlers<InitialData> = {
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(
Expand Down

0 comments on commit 8a236d6

Please sign in to comment.