Skip to content

Commit

Permalink
✨ feat(article): html lang and prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
summerscar committed Dec 19, 2024
1 parent 27ab89d commit bc59a17
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions app/(home)/article/[slug]/_components/movie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ const ArticleRender = memo(
<p
className="text-lg leading-relaxed m-0"
style={{ fontFamily: notoKR.style.fontFamily }}
lang="ko"
>
{cue.text}
</p>
Expand Down
1 change: 1 addition & 0 deletions app/(home)/article/[slug]/_components/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Text = ({ content }: { content: string }) => {
return (
<SelectToSearch showAdd prompt="sentence">
<RenderMDTextServer
lang="ko"
text={resolvedContent}
className={clsx(notoKR.className, "pt-2")}
/>
Expand Down
22 changes: 13 additions & 9 deletions app/(home)/article/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getArticleRevalidateKey,
} from "@/actions/user-dict-utils";
import { RenderMDTextServer } from "@/components/render-md-server";
import { SelectToSearch } from "@/hooks/use-select-to-search";
import type { SubtitleCues, SubtitleSeries } from "@/types/article";
import { notoKR } from "@/utils/fonts";
import { getBaseURL } from "@/utils/get-base-url";
Expand Down Expand Up @@ -103,15 +104,18 @@ const SlugPage = async ({
</div>
)}
<div className="flex-1 flex flex-col">
<div
className="text-4xl font-bold mb-4 leading-tight"
style={{
fontFamily: notoKR.style.fontFamily,
viewTransitionName: `article-title-${article.id}`,
}}
// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
dangerouslySetInnerHTML={{ __html: article.title }}
/>
<SelectToSearch showAdd prompt="sentence">
<div
className="text-4xl font-bold mb-4 leading-tight"
style={{
fontFamily: notoKR.style.fontFamily,
viewTransitionName: `article-title-${article.id}`,
}}
// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
dangerouslySetInnerHTML={{ __html: article.title }}
lang="ko"
/>
</SelectToSearch>
<div
className="text-base text-base-content/70 leading-relaxed flex-grow"
style={{
Expand Down
4 changes: 3 additions & 1 deletion app/(home)/article/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ArticlePage = async () => {
return (
<div className="container px-4 py-8 mx-auto">
<div className="mx-auto grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 max-w-[1024px]">
{sortedArticles.map(async (article) => (
{sortedArticles.map((article, index) => (
<div
key={article.id}
className="card shadow-sm hover:shadow-lg hover:scale-105 transition-all duration-300 !rounded-xl backdrop-blur-lg bg-white/10"
Expand All @@ -31,6 +31,7 @@ const ArticlePage = async () => {
key={article.id}
href={`/article/${article.id}`}
className="block w-full"
prefetch={article.type === "TEXT" && index < 6}
>
<img
src={article.poster || "/icon"}
Expand All @@ -49,6 +50,7 @@ const ArticlePage = async () => {
style={{ viewTransitionName: `article-title-${article.id}` }}
// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
dangerouslySetInnerHTML={{ __html: article.title }}
lang="ko"
/>
<div
style={{
Expand Down
13 changes: 5 additions & 8 deletions app/components/header/_component/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type SearchResult = {

const Search = () => {
const tHeader = useTranslations("Header");
const [isInputFocused, setIsInputFocused] = useState(false);
const [query, setQuery] = useState("");
const [results, setResults] = useState<SearchResult[]>([]);
const [searchIndex, setSearchIndex] =
Expand Down Expand Up @@ -107,7 +106,7 @@ const Search = () => {
};

return (
<div className="relative w-5/6 sm:w-28 sm:focus-within:w-64 transition-[width] [transition-duration:300ms]">
<div className="group relative w-5/6 sm:w-28 sm:has-[:focus]:w-64 transition-[width] [transition-duration:300ms]">
<div className="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
<svg
aria-hidden="true"
Expand All @@ -132,22 +131,20 @@ const Search = () => {
type="search"
className="input input-sm w-full pl-10 bg-white/30 peer"
placeholder={tHeader("search")}
onFocus={() => setIsInputFocused(true)}
// TODO: animation lib
onBlur={() => setTimeout(() => setIsInputFocused(false), 150)}
/>
<ul
className={clsx(
isInputFocused ? "block" : "hidden",
"peer-focus:opacity-100 transition-opacity opacity-0 absolute z-10 w-full bg-base-100 bg-transparent backdrop-blur-lg shadow-2xl rounded-lg max-h-[70dvh] sm:max-h-[50dvh] overflow-auto",
"group-has-[:focus]:opacity-100 group-has-[:focus]:pointer-events-auto pointer-events-none opacity-0 transition-opacity",
"absolute z-10 w-full bg-base-100 bg-transparent backdrop-blur-lg shadow-2xl rounded-lg max-h-[70dvh] sm:max-h-[50dvh] overflow-auto",
)}
>
{results.map((res) => (
<li
key={`${res.type}-${res.id}`}
className="hover:bg-slate-400/40 rounded-md p-2"
className="hover:bg-slate-400/40 rounded-md p-2 focus-within:bg-slate-400/40"
>
<Link href={res.url}>
<Link href={res.url} className="focus:outline-none">
<div className="text-sm font-bold truncate">
{[tHeader(res.level), ...res.relativeReadablePath].join(" > ")}
</div>
Expand Down
10 changes: 8 additions & 2 deletions app/components/render-md-server.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { components } from "@/components/markdown-render";
import clsx from "clsx";
import { compileMDX } from "next-mdx-remote/rsc";
import type { ComponentProps } from "react";

const RenderMDTextServer = async ({
text,
className,
}: { text: string; className?: string }) => {
...props
}: { text: string } & ComponentProps<"div">) => {
const { content } = await compileMDX({
source: text,
components: { ...components },
});
return <div className={clsx("markdown-body", className)}>{content}</div>;
return (
<div className={clsx("markdown-body", className)} {...props}>
{content}
</div>
);
};

export { RenderMDTextServer };
2 changes: 1 addition & 1 deletion app/styles/_markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
}

iframe {
@apply !w-[-webkit-fill-available] !h-auto !aspect-video;
@apply !w-[-webkit-fill-available] !h-auto !aspect-video rounded-lg overflow-hidden;
}
}

0 comments on commit bc59a17

Please sign in to comment.