-
Notifications
You must be signed in to change notification settings - Fork 2
Move search api to Worker, and search indexes to R2 #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3de0174
WIP: lightweight search (at some point...)
kamilkisiela 6c5e740
wip
kamilkisiela 0eb8d5d
fixes
kamilkisiela f8953d8
asd
kamilkisiela 6d0188f
Create README.md
kamilkisiela d65aa6a
xD
kamilkisiela 868bf1c
caching
kamilkisiela d5a2454
Update wrangler.toml
kamilkisiela 46f105a
xD
kamilkisiela edf6bf7
Update website.yml
kamilkisiela d9b6516
Update cloudflare-entry.ts
kamilkisiela df05f66
prewarm
kamilkisiela baf7c68
Update cloudflare-entry.ts
kamilkisiela d6310aa
Update cloudflare-entry.ts
kamilkisiela e584ffe
Update __root.tsx
kamilkisiela 2942a07
Update cloudflare-entry.ts
kamilkisiela b9c4fb0
Update index.ts
kamilkisiela bad4306
no need to cache
kamilkisiela df455e3
no DO
kamilkisiela 6f085c6
no prefetch
kamilkisiela ee9f1ec
Update __root.tsx
kamilkisiela 9282c7b
Update __root.tsx
kamilkisiela 07bc2ac
Update main.yml
kamilkisiela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import type { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure"; | ||
| import type { AdvancedIndex } from "fumadocs-core/search/server"; | ||
|
|
||
| import { CHANGELOG_PAGE_URL } from "@/lib/deployment-changelog"; | ||
| import { pathToSlug } from "@/lib/path-to-slug"; | ||
| import { getSource } from "@/lib/source"; | ||
| import { structure } from "fumadocs-core/mdx-plugins/remark-structure"; | ||
| import { findPath } from "fumadocs-core/page-tree"; | ||
|
|
||
| function getDocsBreadcrumbs( | ||
| source: Awaited<ReturnType<typeof getSource>>, | ||
| pageUrl: string, | ||
| ): string[] | undefined { | ||
| const pageTree = source.getPageTree(); | ||
| const path = findPath( | ||
| pageTree.children, | ||
| (node) => node.type === "page" && node.url === pageUrl, | ||
| ); | ||
| if (!path) return undefined; | ||
| path.pop(); | ||
| const breadcrumbs: string[] = []; | ||
| if (typeof pageTree.name === "string" && pageTree.name.length > 0) { | ||
| breadcrumbs.push(pageTree.name); | ||
| } | ||
| for (const segment of path) { | ||
| if (typeof segment.name === "string" && segment.name.length > 0) { | ||
| breadcrumbs.push(segment.name); | ||
| } | ||
| } | ||
| return breadcrumbs; | ||
| } | ||
|
|
||
| type DataWithStructuredData = { | ||
| structuredData: StructuredData; | ||
| }; | ||
|
|
||
| type DataWithLoader = { | ||
| load(): Promise<DataWithStructuredData>; | ||
| }; | ||
|
|
||
| async function resolveStructuredData(data: unknown): Promise<StructuredData> { | ||
| if ( | ||
| typeof data === "object" && | ||
| data !== null && | ||
| "structuredData" in data && | ||
| "load" in data === false | ||
| ) { | ||
| return (data as DataWithStructuredData).structuredData; | ||
| } | ||
|
|
||
| if ( | ||
| typeof data === "object" && | ||
| data !== null && | ||
| "load" in data && | ||
| typeof (data as DataWithLoader).load === "function" | ||
| ) { | ||
| const loaded = await (data as DataWithLoader).load(); | ||
| return loaded.structuredData; | ||
| } | ||
|
|
||
| throw new Error("Cannot resolve structuredData from page"); | ||
| } | ||
|
|
||
| async function getChangelogStructuredData(): Promise<StructuredData> { | ||
| try { | ||
| const snapshotModule = | ||
| (await import("virtual:deployment-changelog-snapshot")) as { | ||
| deploymentChangelogSnapshot?: string; | ||
| }; | ||
|
|
||
| if (!snapshotModule.deploymentChangelogSnapshot) { | ||
| return { contents: [], headings: [] }; | ||
| } | ||
|
|
||
| return structure(snapshotModule.deploymentChangelogSnapshot); | ||
| } catch { | ||
| return { contents: [], headings: [] }; | ||
| } | ||
| } | ||
|
|
||
| export async function buildIndexes(): Promise<AdvancedIndex[]> { | ||
| const source = await getSource(); | ||
| const { blog, caseStudies, productUpdates } = | ||
| await import("fumadocs-mdx:collections/server"); | ||
|
|
||
| const changelogStructuredData = getChangelogStructuredData(); | ||
|
|
||
| const docsIndexes = await Promise.all( | ||
| source.getPages().map(async (page) => ({ | ||
| breadcrumbs: getDocsBreadcrumbs(source, page.url), | ||
| description: page.data.description, | ||
| id: page.url, | ||
| structuredData: | ||
| page.url === CHANGELOG_PAGE_URL | ||
| ? await changelogStructuredData | ||
| : await resolveStructuredData(page.data), | ||
| title: page.data.title ?? page.url, | ||
| url: page.url, | ||
| })), | ||
| ); | ||
|
|
||
| const caseStudyIndexes = await Promise.all( | ||
| caseStudies.map(async (entry) => { | ||
| const { structuredData } = await entry.load(); | ||
| const slug = pathToSlug(entry.info.path); | ||
| return { | ||
| breadcrumbs: ["Case Studies"], | ||
| description: entry.excerpt, | ||
| id: `/case-studies/${slug}`, | ||
| structuredData, | ||
| title: entry.title, | ||
| url: `/case-studies/${slug}`, | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| const productUpdateIndexes = await Promise.all( | ||
| productUpdates.map(async (entry) => { | ||
| const { structuredData } = await entry.load(); | ||
| const slug = pathToSlug(entry.info.path); | ||
| return { | ||
| breadcrumbs: ["Product Updates"], | ||
| description: entry.description, | ||
| id: `/product-updates/${slug}`, | ||
| structuredData, | ||
| title: entry.title ?? slug, | ||
| url: `/product-updates/${slug}`, | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| const blogIndexes = await Promise.all( | ||
| blog.map(async (entry) => { | ||
| const { structuredData } = await entry.load(); | ||
| const slug = entry.info.path | ||
| .replace(/\.mdx?$/, "") | ||
| .replace(/\/index$/, ""); | ||
| return { | ||
| breadcrumbs: ["Blog"], | ||
| description: entry.description, | ||
| id: `/blog/${slug}`, | ||
| structuredData, | ||
| title: entry.title ?? slug, | ||
| url: `/blog/${slug}`, | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| return [ | ||
| ...docsIndexes, | ||
| ...caseStudyIndexes, | ||
| ...productUpdateIndexes, | ||
| ...blogIndexes, | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ type MetaTag = { | |
| }; | ||
|
|
||
| type LinkTag = { | ||
| as?: string; | ||
| href: string; | ||
| rel: string; | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default was so low that when I typed "router" it ended end with
ro,routandrouterhttp calls, first two were not even cancelled... :D