Remix + Pagefind で全文検索

2.5K Views

June 18, 24

スライド概要

[Remixドキュメント日本語版](https://remix-docs-ja.techtalk.jp)に無料の全文検索機能を入れた話。

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Remix + Pagefind Remix Docs Japanese with free full-text search functionality. Remix "ワインと鍋" Meetup Press Space for next page

2.

coji A web developer based on Tokyo, Japan. Love the things that are very useful and simple to use, made by a small group of people Remix Conform DuckDB Turso Also love tech talks. I decided to name my own company TechTalk inc.

3.

Remix Docs Japanese A website I maintained to help my Japanese co-workers learn and understand the "Remix way". https://github.com/coji/remix-docs-ja Tech Stacks Remix v2.9.2 (single fetch) Fly.io + Cloudflare Cache Markdown based Translated using Gemini 1.5 Flash

4.

Full-text Search Functionality

5.

Pagefind Provides search functionality for websites with minimal bandwidth and no infrastructure. https://pagefind.app Open source library written in Rust Multilingual and Japanese support out of the box Provides a NodeJS indexing API and browser-based search API, along with a CLI and default UI

6.

How Full-text search works

7.
[beta]
Indexing
When building the app, also perform index building simultaneously.
const buildIndex = async () => {
const { index } = await pagefind.createIndex({})
const docs = await glob('docs/**/*.md')
for (const filename of docs) {
const { dir, name } = path.parse(filename)
const pathname = path.join('/', path.basename(dir), name)
const doc = await getDoc(pathname)
await index.addCustomRecord({
content: doc.html,
meta: { title: doc.attributes.title.toString() },
language: 'ja',
url: pathname
})
}
await index.writeFiles({ outputPath: 'public/pagefind' })
}
await buildIndex()

8.

Indexing (cont.) pagefind.js must be removed from the bundle by specifying external in rollupOptions. vite.config.ts export default defineConfig({ plugins: [ remix({ future: { v3_fetcherPersist: true, v3_relativeSplatPath: true, v3_throwAbortReason: true, unstable_singleFetch: true, }, }), tsconfigPaths(), ], build: { rollupOptions: { external: ['/pagefind/pagefind.js?url'] } }, })

9.
[beta]
Search
clientLoader: Execute searches solely on the browser side. It also works in SPA mode.
Form
<fetcher.Form action="/resources/search">
<Input id="query" name="q" placeholder="Search..." />
<Button size="sm">Search</Button>
</fetcher.Form>

clientLoader
export const clientLoader = async ({ request }: ClientLoaderFunctionArgs) => {
const url = new URL(request.url)
const pagefind = (await import(
'/pagefind/pagefind.js?url'
)) as unknown as Pagefind
await pagefind.init()
const ret = await pagefind.search(url.searchParams.get('q'))
const results = await Promise.all(ret.results.map((result) => result.data()))
return { results }
}

10.

Conclusion By combining Remix and Pagefind, you can build a website with full-text search functionality that is incredibly simple and low-cost. Pagefind is a free, open-source search library that supports Japanese out of the box No server-side infrastructure is required, and search processing can be completed entirely in the browser, significantly reducing operational costs By leveraging Remix’s clientLoader, you can seamlessly implement client-side search It’s an ideal solution for adding full-text search to Markdown-based documentation I recommend to try building a user-friendly and powerful search-enabled website using Remix and Pagefind!

11.

Thank You

12.

One more thing

13.

One more thing Remix 2年前から使ってるけど、当時はそんな案件(クライアント)はまったくなかった。 どっかで Remix の仕事あったらいいのにな〜と思っていた。そういう人は今もいるはず。 プロダクション利用も徐々に増えてきたけど、まだ少数。 そういう企業で Remix に慣れてるエンジニアのニーズはあるようだ。 近い将来、既存 react-router アプリの v7 へのマイグレーションニーズが出てきそう。 Remix エンジニア採用したい人と、Remix 仕事したい人のマッチングをできるといいな。 そうだ: Remixドキュメント日本語版に Remix を使う仕事の募集情報載ってるといいかも? Web 2.0 の頃にあった Job Board 的な。日本国内限定だけど。 採用情報へのリンク、載せたい方いらっしゃいますか? 大変になってきたら無料では無理かもだけど、そこまで盛り上がる気はちょっとしないかな。 。? 興味ある方いらっしゃる前提で: あとで相談させてください。 XのDMなど ついでに Remix を企業・プロダクションで使ってる方を Meetup にお誘いしたい。 会場提供もしてもらえるといいな!

14.

Thank You (本当)