Skip to content

web search done right

Update to Astro 2 (#71)

Oliver Bøvingf70d307c3a85
diff --git a/frontend/package.json b/frontend/package.json
index 3314412d..e17bf031 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -11,20 +11,20 @@
"prettier": "prettier -w . --cache"
},
"dependencies": {
- "@alpinejs/persist": "^3.10.5",
+ "@alpinejs/persist": "^3.11.1",
"@types/alpinejs": "^3.7.1",
- "alpinejs": "^3.10.5",
- "astro": "^1.7.2",
+ "alpinejs": "^3.11.1",
+ "astro": "^2.0.2",
"astro-icon": "^0.8.0"
},
"devDependencies": {
- "@astrojs/mdx": "^0.13.0",
- "@astrojs/tailwind": "^2.1.3",
+ "@astrojs/mdx": "^0.15.1",
+ "@astrojs/tailwind": "^3.0.0",
"@faker-js/faker": "^7.6.0",
- "@fontsource/montserrat": "^4.5.13",
- "@tailwindcss/typography": "^0.5.8",
- "prettier": "^2.8.1",
- "prettier-plugin-astro": "^0.7.0",
- "prettier-plugin-tailwindcss": "^0.2.1"
+ "@fontsource/montserrat": "^4.5.14",
+ "@tailwindcss/typography": "^0.5.9",
+ "prettier": "^2.8.3",
+ "prettier-plugin-astro": "^0.8.0",
+ "prettier-plugin-tailwindcss": "^0.2.2"
}
}
diff --git a/frontend/src/components/CalculatorWidget.astro b/frontend/src/components/CalculatorWidget.astro
index be5ab4a3..054f7963 100644
--- a/frontend/src/components/CalculatorWidget.astro
+++ b/frontend/src/components/CalculatorWidget.astro
@@ -2,15 +2,15 @@
import { askama } from "../askama";
export interface Props {
- calculation: string;
+ calculation: string;
}
---
-<div class="border rounded-xl p-5 flex flex-col items-end">
- <div class="text-xs text-gray-500 flex w-fit">
- {askama`calculation.input`} =
- </div>
- <div class="font-bold text-3xl flex w-fit">
- {askama`calculation.result`}
- </div>
-</div>
\ No newline at end of file
+<div class="flex flex-col items-end rounded-xl border p-5">
+ <div class="flex w-fit text-xs text-gray-500">
+ {askama`calculation.input`} =
+ </div>
+ <div class="flex w-fit text-3xl font-bold">
+ {askama`calculation.result`}
+ </div>
+</div>
diff --git a/frontend/src/components/DirectAnswer.astro b/frontend/src/components/DirectAnswer.astro
index ed8a22db..bc0548b0 100644
--- a/frontend/src/components/DirectAnswer.astro
+++ b/frontend/src/components/DirectAnswer.astro
@@ -2,52 +2,52 @@
import { askama } from "../askama";
export interface Props {
- direct_answer: string;
+ direct_answer: string;
}
---
-{askama.if_("let Some(direct_answer) = direct_answer", (
+
+{
+ askama.if_(
+ "let Some(direct_answer) = direct_answer",
<div class="answer-container border-b">
- <div class="answer">
- {askama`direct_answer.answer`}
- </div>
- <div class="answer-snippet">
- {askama`direct_answer.snippet|safe`}
- </div>
- <div class="flex flex-col">
- <a class="answer-url-link p-0 m-0" href={askama`direct_answer.url`}>
- {askama`direct_answer.pretty_url`}
- </a>
- <div class="answer-title">
- <a class="answer-title-link" href={askama`direct_answer.url`}>
- {askama`direct_answer.title`}
- </a>
- </div>
+ <div class="answer">{askama`direct_answer.answer`}</div>
+ <div class="answer-snippet">{askama`direct_answer.snippet|safe`}</div>
+ <div class="flex flex-col">
+ <a class="answer-url-link m-0 p-0" href={askama`direct_answer.url`}>
+ {askama`direct_answer.pretty_url`}
+ </a>
+ <div class="answer-title">
+ <a class="answer-title-link" href={askama`direct_answer.url`}>
+ {askama`direct_answer.title`}
+ </a>
</div>
+ </div>
</div>
-))}
+ )
+}
<style>
- .asnwer-container {
- @apply flex flex-col;
- }
- .answer {
- @apply text-xl font-medium mb-3;
- }
-
- .answer-snippet {
- @apply text-sm mb-5;
- }
+ .asnwer-container {
+ @apply flex flex-col;
+ }
+ .answer {
+ @apply mb-3 text-xl font-medium;
+ }
+
+ .answer-snippet {
+ @apply mb-5 text-sm;
+ }
- .answer-snippet > b {
- font-weight: 700;
- }
+ .answer-snippet > b {
+ font-weight: 700;
+ }
- .answer-title-link {
- @apply text-blue-800 visited:text-purple-800 inline-block truncate text-xl font-medium;
- max-width: calc(100% - 30px);
- }
- .answer-url-link {
- @apply inline-block truncate text-sm text-gray-800 hover:no-underline;
- max-width: calc(100% - 30px);
- }
+ .answer-title-link {
+ @apply inline-block truncate text-xl font-medium text-blue-800 visited:text-purple-800;
+ max-width: calc(100% - 30px);
+ }
+ .answer-url-link {
+ @apply inline-block truncate text-sm text-gray-800 hover:no-underline;
+ max-width: calc(100% - 30px);
+ }
</style>
diff --git a/frontend/src/components/DiscussionItem.astro b/frontend/src/components/DiscussionItem.astro
index 8612c63d..cab23955 100644
--- a/frontend/src/components/DiscussionItem.astro
+++ b/frontend/src/components/DiscussionItem.astro
@@ -3,40 +3,45 @@ import { askama } from "../askama";
import Hero from "./Hero.astro";
export interface Props {
- discussion: string;
+ discussion: string;
}
---
+
<div class="discussion overflow-hidden">
- <div>
- <a class="text-sm hover:no-underline" href="{{ discussion.url }} ">
- {askama`discussion.domain`}
- </a>
- </div>
- <div class="flex">
- <a
- class="discussion-title truncate text-md font-medium"
- title="{{ discussion.title }}"
- href="{{ discussion.url }}"
- >
- {askama`discussion.title $ {{lorem.sentence}}`}
- </a>
- <div class="toggle-discussion-snippet"><Hero class="w-4 hover:cursor-pointer" icon="chevron-down" /></div>
- </div>
- <div class="discussion-snippet text-snippet hidden">
- {askama.match("discussion.snippet", {
- "Snippet::Normal { date, text }": (
- <div>
- {askama.if_("let Some(date) = date", () => (
- <span class="text-gray-500">{askama`date $ 2. May 2022`}</span>
- ))}
- <span class="[&:nth-child(2)]:before:content-['—']">
- {askama`text|safe $ {{lorem.lines}}`}
- </span>
- </div>
- ),
- "_": (<></>)
- })}
+ <div>
+ <a class="text-sm hover:no-underline" href="{{ discussion.url }} ">
+ {askama`discussion.domain`}
+ </a>
+ </div>
+ <div class="flex">
+ <a
+ class="discussion-title text-md truncate font-medium"
+ title="{{ discussion.title }}"
+ href="{{ discussion.url }}"
+ >
+ {askama`discussion.title $ {{lorem.sentence}}`}
+ </a>
+ <div class="toggle-discussion-snippet">
+ <Hero class="w-4 hover:cursor-pointer" icon="chevron-down" />
</div>
+ </div>
+ <div class="discussion-snippet hidden text-snippet">
+ {
+ askama.match("discussion.snippet", {
+ "Snippet::Normal { date, text }": (
+ <div>
+ {askama.if_("let Some(date) = date", () => (
+ <span class="text-gray-500">{askama`date $ 2. May 2022`}</span>
+ ))}
+ <span class="[&:nth-child(2)]:before:content-['—']">
+ {askama`text|safe $ {{lorem.lines}}`}
+ </span>
+ </div>
+ ),
+ _: null,
+ })
+ }
+ </div>
</div>
<style>
@@ -64,28 +69,33 @@ export interface Props {
</style>
<script>
- const snippetBtns = document.getElementsByClassName("toggle-discussion-snippet");
- const snippets = document.getElementsByClassName("discussion-snippet");
- const titles = document.getElementsByClassName("discussion-title");
+ const snippetBtns = document.getElementsByClassName(
+ "toggle-discussion-snippet"
+ );
+ const snippets = document.getElementsByClassName("discussion-snippet");
+ const titles = document.getElementsByClassName("discussion-title");
- for (const btn of snippetBtns) {
- btn.addEventListener("click", (e) => {
- if (e.currentTarget instanceof HTMLElement) {
- const index = Array.prototype.indexOf.call(snippetBtns, e.currentTarget);
+ for (const btn of snippetBtns) {
+ btn.addEventListener("click", (e) => {
+ if (e.currentTarget instanceof HTMLElement) {
+ const index = Array.prototype.indexOf.call(
+ snippetBtns,
+ e.currentTarget
+ );
- let snippet = snippets[index];
- let title = titles[index];
+ let snippet = snippets[index];
+ let title = titles[index];
- if (snippet.classList.contains("hidden")) {
- snippet.classList.remove("hidden");
- e.currentTarget.classList.add("active");
- title.classList.add("active");
- } else {
- snippet.classList.add("hidden")
- e.currentTarget.classList.remove("active");
- title.classList.remove("active");
- }
- }
- });
- }
-</script>
\ No newline at end of file
+ if (snippet.classList.contains("hidden")) {
+ snippet.classList.remove("hidden");
+ e.currentTarget.classList.add("active");
+ title.classList.add("active");
+ } else {
+ snippet.classList.add("hidden");
+ e.currentTarget.classList.remove("active");
+ title.classList.remove("active");
+ }
+ }
+ });
+ }
+</script>
diff --git a/frontend/src/components/Discussions.astro b/frontend/src/components/Discussions.astro
index 67b97ff7..2203e22b 100644
--- a/frontend/src/components/Discussions.astro
+++ b/frontend/src/components/Discussions.astro
@@ -4,51 +4,54 @@ import Hero from "./Hero.astro";
import DiscussionItem from "./DiscussionItem.astro";
export interface Props {
- discussions: string;
+ discussions: string;
}
---
{
-askama.if_("let Some(discussions) = discussions", () => (
-<div class="discussions relative overflow-hidden flex flex-col space-y-1.5" id="discussions">
- <div class="text-lg space-x-1 flex mb" id="discussions-header">
+ askama.if_("let Some(discussions) = discussions", () => (
+ <div
+ class="discussions relative flex flex-col space-y-1.5 overflow-hidden"
+ id="discussions"
+ >
+ <div class="mb flex space-x-1 text-lg" id="discussions-header">
<Hero class="w-4" icon="chat-alt-2" />
<span>Discussions</span>
- </div>
- <div class="discussion-list flex flex-col">
- {
- askama.for_("discussion in discussions.iter().take(4)", () => (
- <DiscussionItem discussion="discussion" />
- ))
- }
+ </div>
+ <div class="discussion-list flex flex-col">
+ {askama.for_("discussion in discussions.iter().take(4)", () => (
+ <DiscussionItem discussion="discussion" />
+ ))}
<div id="discussion-more" class="hidden">
- {
- askama.for_("discussion in discussions.iter().skip(4)", () => (
- <DiscussionItem discussion="discussion" />
- ))
- }
+ {askama.for_("discussion in discussions.iter().skip(4)", () => (
+ <DiscussionItem discussion="discussion" />
+ ))}
</div>
- <div id="discussion-more-btn" class="hover:cursor-pointer hover:bg-neutral-100 w-fit px-2 py-1 mt-3 border rounded-full">Show more</div>
+ <div
+ id="discussion-more-btn"
+ class="mt-3 w-fit rounded-full border px-2 py-1 hover:cursor-pointer hover:bg-neutral-100"
+ >
+ Show more
+ </div>
+ </div>
</div>
-</div>
-))
+ ))
}
<script>
- const discussionMore = document.getElementById("discussion-more")!;
- const discussionMoreBtn = document.getElementById("discussion-more-btn")!;
-
- let moreIsShown = false;
- discussionMoreBtn.addEventListener("click", () => {
- moreIsShown = !moreIsShown;
+ const discussionMore = document.getElementById("discussion-more")!;
+ const discussionMoreBtn = document.getElementById("discussion-more-btn")!;
- if (moreIsShown) {
- discussionMore.classList.remove("hidden");
- discussionMoreBtn.innerHTML = "Show less";
- } else {
- discussionMore.classList.add("hidden");
- discussionMoreBtn.innerHTML = "Show more";
- }
- })
+ let moreIsShown = false;
+ discussionMoreBtn.addEventListener("click", () => {
+ moreIsShown = !moreIsShown;
-</script>
\ No newline at end of file
+ if (moreIsShown) {
+ discussionMore.classList.remove("hidden");
+ discussionMoreBtn.innerHTML = "Show less";
+ } else {
+ discussionMore.classList.add("hidden");
+ discussionMoreBtn.innerHTML = "Show more";
+ }
+ });
+</script>
diff --git a/frontend/src/components/Widget.astro b/frontend/src/components/Widget.astro
index 2251bac7..f4a01f3e 100644
--- a/frontend/src/components/Widget.astro
+++ b/frontend/src/components/Widget.astro
@@ -3,20 +3,19 @@ import { askama } from "../askama";
import CalculatorWidget from "./CalculatorWidget.astro";
export interface Props {
- widget: string;
+ widget: string;
}
---
{
-askama.if_("let Some(widget) = widget", (
+ askama.if_(
+ "let Some(widget) = widget",
<div>
- {
- askama.match("widget", {
- "Widget::Calculator(calculation)": (
- <CalculatorWidget calculation="calculation" />
- )
- })
- }
+ {askama.match("widget", {
+ "Widget::Calculator(calculation)": (
+ <CalculatorWidget calculation="calculation" />
+ ),
+ })}
</div>
-))
-}
\ No newline at end of file
+ )
+}
diff --git a/frontend/src/pages/search.astro b/frontend/src/pages/search.astro
index a28bcf8f..45424b04 100644
--- a/frontend/src/pages/search.astro
+++ b/frontend/src/pages/search.astro
@@ -86,44 +86,42 @@ import { askama } from "../askama";
{
askama.for_("item in search_result", () => (
<>
- {
- askama.if_("loop.index == 3", () => (
+ {askama.if_("loop.index == 3", () => (
<Discussions discussions="discussions" />
- ))
- }
- <div class="flex w-full">
- <div class="flex min-w-0 grow flex-col space-y-1">
- <div class="flex min-w-0">
- <div class="flex min-w-0 grow flex-col space-y-1">
- <div class="flex items-center text-sm">
+ ))}
+ <div class="flex w-full">
+ <div class="flex min-w-0 grow flex-col space-y-1">
+ <div class="flex min-w-0">
+ <div class="flex min-w-0 grow flex-col space-y-1">
+ <div class="flex items-center text-sm">
+ <a
+ class="url truncate text-gray-800 hover:no-underline"
+ href="{{ item.url }}"
+ >
+ {askama`item.pretty_url $ {{internet.url}}`}
+ </a>
+ </div>
<a
- class="url truncate text-gray-800 hover:no-underline"
+ class="title-link truncate text-xl font-medium"
+ title="{{ item.title }}"
href="{{ item.url }}"
>
- {askama`item.pretty_url $ {{internet.url}}`}
+ {askama`item.title $ {{lorem.sentence}}`}
</a>
</div>
- <a
- class="title-link truncate text-xl font-medium"
- title="{{ item.title }}"
- href="{{ item.url }}"
+ <div
+ class="adjust-btn hidden min-w-fit items-center justify-center md:flex"
+ data-site="{{ item.site }}"
>
- {askama`item.title $ {{lorem.sentence}}`}
- </a>
+ <Hero class="w-6" icon="adjustments" />
+ </div>
</div>
- <div
- class="adjust-btn hidden min-w-fit items-center justify-center md:flex"
- data-site="{{ item.site }}"
- >
- <Hero class="w-6" icon="adjustments" />
+ <div class="text-sm text-snippet">
+ <Snippet snippet={askama`item.snippet`} />
</div>
</div>
- <div class="text-sm text-snippet">
- <Snippet snippet={askama`item.snippet`} />
- </div>
</div>
- </div>
- </>
+ </>
))
}
@@ -177,7 +175,7 @@ import { askama } from "../askama";
@apply text-blue-800 visited:text-purple-800;
max-width: calc(100% - 30px);
}
-
+
.url {
max-width: calc(100% - 100px);
}
@@ -199,7 +197,7 @@ import { askama } from "../askama";
.text-snippet {
font-weight: 400;
}
- .text-snippet>b {
+ .text-snippet > b {
font-weight: 700;
}
</style>