-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the extremely fast flexsearch to the project and is now in going to be beta tested in the tutorials page. - Some visual tweaks to fix some issues with tutorials - Tutorials now list authors and coauthors
- Loading branch information
Showing
11 changed files
with
101 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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 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 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,23 @@ | ||
import FlexSearch from "flexsearch" | ||
import type { Tutorial } from "./types/collection" | ||
import { tutorialsPromise } from "./server/utils.server" | ||
|
||
let tutorialsIndex: FlexSearch.Index | ||
let tutorials: Tutorial[] | ||
|
||
export function createTutorialsIndex(data: Tutorial[]) { | ||
tutorialsIndex = new FlexSearch.Index({ tokenize: "forward" }) | ||
|
||
data.forEach((tutorial, i) => { | ||
const item = `${tutorial.title} ${tutorial.description} ${tutorial.content}` | ||
tutorialsIndex.add(i, item) | ||
}) | ||
|
||
tutorials = data | ||
} | ||
|
||
export function searchTutorialsIndex(searchTerm: string) { | ||
const match = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") //escape special regex characters | ||
const results = tutorialsIndex.search(match) | ||
return results.map((index) => tutorials[index as number]) | ||
} |
This file contains 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 |
---|---|---|
@@ -1,35 +1,9 @@ | ||
import { getUsername } from "$lib/server/supabase.server" | ||
import type { Tutorial } from "$lib/types/collection" | ||
import { encodeSEO } from "$lib/utils" | ||
import { getFullTutorials, tutorialsPromise } from "$lib/server/utils.server" | ||
import { json } from "@sveltejs/kit" | ||
|
||
async function getPosts() { | ||
let tutorials: Tutorial[] = [] | ||
|
||
const paths = import.meta.glob("/src/wasp-info/tutorials/*.md", { eager: true }) | ||
|
||
for (const path in paths) { | ||
const file = paths[path] | ||
const order = path.split("/").at(-1)?.replace(".md", "") | ||
|
||
if (file && typeof file === "object" && "metadata" in file && order) { | ||
const metadata = file.metadata as Omit<Tutorial, "slug"> | ||
const username = await getUsername(metadata.author) | ||
if (!username) continue | ||
|
||
const url = encodeSEO(metadata.title + " by " + username) | ||
|
||
const tutorial = { ...metadata, username, order: parseInt(order), url } satisfies Tutorial | ||
tutorial.published && tutorials.push(tutorial) | ||
} | ||
} | ||
|
||
tutorials = tutorials.sort((first, second) => first.order - second.order) | ||
|
||
return tutorials | ||
} | ||
export const prerender = true | ||
|
||
export async function GET() { | ||
const tutorials = await getPosts() | ||
const tutorials = await getFullTutorials() | ||
return json(tutorials) | ||
} |
This file contains 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 |
---|---|---|
@@ -1,31 +1,8 @@ | ||
import { getUsername } from "$lib/server/supabase.server" | ||
import type { Tutorial } from "$lib/types/collection" | ||
import { encodeSEO } from "$lib/utils" | ||
import { getTutorial } from "$lib/server/utils.server" | ||
import { error, json } from "@sveltejs/kit" | ||
|
||
async function getPosts(slug: string) { | ||
const paths = import.meta.glob("/src/wasp-info/tutorials/*.md", { eager: true }) | ||
|
||
for (const path in paths) { | ||
const file = paths[path] | ||
|
||
const order = path.split("/").at(-1)?.replace(".md", "") | ||
if (file && typeof file === "object" && "metadata" in file && order) { | ||
const metadata = file.metadata as Omit<Tutorial, "slug"> | ||
const username = await getUsername(metadata.author) | ||
if (!username) continue | ||
|
||
const url = encodeSEO(metadata.title + " by " + username) | ||
|
||
if (slug === order || slug === url) | ||
return { ...metadata, order: parseInt(order), url } satisfies Tutorial | ||
} | ||
} | ||
|
||
error(404, "Couldn't find " + slug) | ||
} | ||
|
||
export async function GET({ params: { slug } }) { | ||
const tutorial = await getPosts(slug) | ||
const tutorial = await getTutorial(slug) | ||
if (!tutorial) error(404, "Can't find " + slug) | ||
return json(tutorial) | ||
} |
This file contains 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 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 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 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