Skip to content

Commit

Permalink
feat: adding search api
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoSM committed Oct 14, 2023
1 parent fb8af5f commit 3b0016a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 23 deletions.
3 changes: 1 addition & 2 deletions apps/app/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ export default defineNuxtConfig({
},
},
routeRules: {
"/sign-in": { ssr: false },
"/": { prerender: true },
"/profile": { ssr: true },
},
nitro: {
preset: "cloudflare",
baseURL: process.env.NODE_ENV === "development" ? "/" : baseURL,
prerender: {
crawlLinks: true,
routes: ["/api/search.json"],
},
runtimeConfig: {
app: {
Expand Down
3 changes: 3 additions & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"splitpanes": "^3.1.5",
"tailwind-config": "workspace:*",
"universal-cookie": "^4.0.4"
},
"resolutions": {
"h3": "^1.8.2"
}
}
60 changes: 40 additions & 20 deletions apps/app/pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,47 @@ const sessionStore = useSessionStore();
const taskModalStore = useTaskModalStore();
const coursesStore = useCoursesStore();
const enrollmentModalStore = useEnrollmentModalStore();
const { params } = useRoute();
const { params, path } = useRoute();
const router = useRouter();
const loading = ref(true);
const { data } = await useAsyncData(`course${params.slug[0]}`, async () => {
const [course, lesson, surround] = await Promise.all([
queryContent(`/${params.slug[0]}`).findOne(),
queryContent(
`/${params.slug[0]}/${params.slug[1]}/${params.slug[2]}`
).findOne(),
queryContent()
.where({
_type: "markdown",
_id: { $contains: `github:${params.slug[0]}` },
})
.findSurround(`/${params.slug[0]}/${params.slug[1]}/${params.slug[2]}`),
]);
return { data: { course, lesson, surround } };
const { data: course } = await useAsyncData(`course-${path}`, () =>
queryContent(`/${params.slug[0]}`).findOne()
);
if (!course.value) {
throw createError({ statusCode: 404, statusMessage: "Page not found" });
}
const { data: lesson } = await useAsyncData(`lesson-${path}`, () =>
queryContent(path).findOne()
);
if (!lesson.value) {
throw createError({ statusCode: 404, statusMessage: "Page not found" });
}
const { data: surround } = await useAsyncData(`lesson-${path}-surround`, () => {
return queryContent()
.where({
_type: "markdown",
_id: { $contains: `github:${params.slug[0]}` },
})
.findSurround(`/${params.slug[0]}/${params.slug[1]}/${params.slug[2]}`);
});
useSeoMeta({
title: lesson.value.title,
ogTitle: lesson.value.title,
description: lesson.value.description,
ogDescription: lesson.value.description,
});
const previousLesson = data.value?.data.surround[0];
const nextLesson = data.value?.data.surround[1];
const currentLesson = data.value?.data.lesson;
const previousLesson = surround.value ? surround.value[0] : null;
const nextLesson = surround.value ? surround.value[1] : null;
const currentLesson = lesson.value;
const currentCourse = data.value?.data.course._dir;
const currentCourse = course.value._dir;
const hasTask = computed(() => {
return ["Content", "Image"].includes(currentLesson?.submissionContent);
Expand Down Expand Up @@ -114,7 +130,11 @@ onMounted(async () => {
</div>
</div>
<div class="mx-auto max-w-[816px] px-6 sm:px-8 pb-10">
<ContentDoc id="nuxt_content" />
<ContentRenderer
v-if="currentLesson.body"
:value="currentLesson"
id="nuxt_content"
/>

<nuxt-link
v-if="previousLesson"
Expand Down
7 changes: 7 additions & 0 deletions apps/app/server/api/search.json.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { serverQueryContent } from "#content/server";

export default eventHandler((event) => {
return serverQueryContent(event)
.where({ _type: "markdown", navigation: { $ne: false } })
.find();
});
6 changes: 5 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ compatibility_date = "2022-09-10"
account_id = "d8803c6a6253e9267bf1000ca69db18d"

[site]
bucket = "apps/app/.output/public"
bucket = "apps/app/.output/public"

[env.dev]
bucket = "apps/app/.output/public"
route = "*dev.menthor.io/app*"

0 comments on commit 3b0016a

Please sign in to comment.