Skip to content

Commit e2a5d61

Browse files
authored
Added pagefind filter for language searching (#262)
1 parent 22a01ed commit e2a5d61

36 files changed

+46
-5
lines changed

packages/astro-theme/components/search/Pagefind.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
export let productId: string | undefined;
66
export let placeholder: string;
7+
export let locale: string;
78
89
let pagefind: Pagefind;
910
let results: PagefindResult[] = [];
@@ -33,7 +34,7 @@
3334
const query = (event.target as HTMLInputElement).value;
3435
3536
const response = await pagefind.debouncedSearch(query, {
36-
filters: { productId },
37+
filters: { productId, language: locale },
3738
baseUrl: import.meta.env.BASE_URL,
3839
});
3940
if (response === null) {

packages/astro-theme/components/search/Search.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface Props {
3434
client:visible
3535
productId={Astro.props.filterProductId}
3636
placeholder={t("Type to search...", Astro.currentLocale)}
37+
locale={Astro.currentLocale}
3738
>
3839
<div
3940
slot="no-results"

packages/astro-theme/content.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { defineCollection, z } from "astro:content";
22

33
const productTags = z.array(z.enum(["Cheerp", "CheerpJ", "CheerpX"]));
4+
const languages = z.enum(["en", "ja"]);
45

56
export type ProductTag = z.infer<typeof productTags>[0];
7+
export type LanguageContent = z.infer<typeof languages>;
68

79
export function defineCommonCollections() {
810
return {
@@ -14,6 +16,7 @@ export function defineCommonCollections() {
1416
shortTitle: z.string().optional(), // Used for nav only
1517
fullWidthLayout: z.boolean().default(false),
1618
draft: z.boolean().default(false),
19+
language: languages.default("en"),
1720
}),
1821
}),
1922

packages/astro-theme/layouts/DocsArticle.astro

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ import WasThisHelpful from "../components/WasThisHelpful.astro";
1515
import Callout from "../components/Callout.astro";
1616
import BentoGrid from "../components/patterns/BentoGrid.astro";
1717
import { Markdown } from "@astropub/md";
18+
import type { LanguageContent } from "../content";
1819
1920
interface Props {
2021
id?: string | undefined;
2122
title: string;
2223
description?: string | undefined;
2324
headings?: Heading[] | undefined;
2425
fullWidthLayout: boolean;
26+
language: LanguageContent;
2527
}
2628
27-
const { id, title, description, headings, fullWidthLayout } = Astro.props;
29+
const { id, title, description, headings, fullWidthLayout, language } =
30+
Astro.props;
2831
2932
const nav = await getRootNav();
3033
const product = productFromUrl(Astro.url);
@@ -61,6 +64,7 @@ function getEditHref(id: string): string {
6164
) : (
6265
<docs-article class="max-w-[92rem] w-full mx-auto flex justify-between">
6366
<div
67+
{...(language && { "data-pagefind-filter": `language:${language}` })}
6468
data-sidebar-wrapper
6569
class="hidden lg:block shadow-xl lg:shadow-none z-50 lg:z-30"
6670
>
@@ -83,9 +87,9 @@ function getEditHref(id: string): string {
8387

8488
<main
8589
data-pagefind-body
86-
data-pagefind-filter={
87-
product ? `productId:${product.id}` : undefined
88-
}
90+
{...(product && {
91+
"data-pagefind-filter": `productId:${product.id}`,
92+
})}
8993
class="prose prose-stone dark:prose-invert p-6 md:px-8 lg:pt-0 pb-10 w-full max-w-3xl xl:max-w-[49rem]"
9094
>
9195
{title === product?.name ? (

packages/astro-theme/pages/docs/[...slug].astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const rendered = await collectionEntry?.render();
3737
id={navEntry.id}
3838
headings={rendered?.headings}
3939
fullWidthLayout={collectionEntry?.data.fullWidthLayout ?? false}
40+
language={collectionEntry?.data?.language}
4041
>
4142
{rendered && <rendered.Content />}
4243
{

sites/cheerpj/src/content/docs/ja/00-overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: CheerpJ
33
shortTitle: 概要
44
description: 現代のウェブブラウザ向けJava仮想マシン
5+
language: ja
56
---
67

78
import LinkButton from "@leaningtech/astro-theme/components/LinkButton.astro";

sites/cheerpj/src/content/docs/ja/10-getting-started/00-Java-app.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Javaアプリケーションの実行
33
description: デスクトップアプリをウェブアプリに変換する
4+
language: ja
45
---
56

67
CheerpJは、ほとんど変更を加えずにブラウザでJavaアプリケーションを実行できます。このページでは、CheerpJを使用して最初のJavaアプリケーションをブラウザで実行する方法を説明します。

sites/cheerpj/src/content/docs/ja/10-getting-started/01-Java-applet.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Javaアプレットの実行
33
description: 最新のブラウザでJavaアプレットを実行する
4+
language: ja
45
---
56

67
import LinkButton from "@leaningtech/astro-theme/components/LinkButton.astro";

sites/cheerpj/src/content/docs/ja/10-getting-started/02-Java-library.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Javaライブラリの実行
33
description: JavaScriptでJavaクラスを使用する
4+
language: ja
45
---
56

67
## 1. ページにCheerpJを含める

sites/cheerpj/src/content/docs/ja/10-getting-started/03-JNLP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: JNLPの実行
33
description: ブラウザでJWS/JNLPアプリケーションを実行する
4+
language: ja
45
---
56

67
このクイックスタートチュートリアルでは、ブラウザでCheerpJを使用してJNLPアプリ(Java Web Startアプリケーションとしても知られています)を実行する手順を説明します。

0 commit comments

Comments
 (0)