-
-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9efb4e1
commit 76ecfb3
Showing
9 changed files
with
293 additions
and
0 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
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,9 @@ | ||
--- | ||
description: JavaScript, a programming language! | ||
--- | ||
|
||
# JavaScript | ||
|
||
JavaScript (/ˈdʒɑːvəskrɪpt/), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2023, 98.7% of websites use JavaScript on the client side for webpage behavior, often incorporating third-party libraries. All major web browsers have a dedicated JavaScript engine to execute the code on users' devices. | ||
|
||
For more information, see [Wikipedia](https://en.wikipedia.org/wiki/JavaScript). |
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,9 @@ | ||
--- | ||
description: PHP, a programming language! | ||
--- | ||
|
||
# PHP | ||
|
||
PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. PHP was originally an abbreviation of Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor. | ||
|
||
For more information, see [Wikipedia](https://en.wikipedia.org/wiki/PHP). |
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,13 @@ | ||
export default defineNuxtConfig({ | ||
extends: ['../shared'], | ||
|
||
content: { | ||
search: { | ||
mode: 'full-text' | ||
} | ||
}, | ||
|
||
typescript: { | ||
includeWorkspace: true | ||
} | ||
}) |
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,15 @@ | ||
<script lang="ts" setup> | ||
const search = ref('') | ||
const result = await useSearch(search) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1>Search</h1> | ||
<p>Search page</p> | ||
|
||
<input v-model="search"> | ||
|
||
<pre>{{ result }} </pre> | ||
</div> | ||
</template> |
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,31 @@ | ||
import { useFuse } from '@vueuse/integrations/useFuse' | ||
import { useRuntimeConfig, useLazyFetch } from '#imports' | ||
|
||
export const useSearch = async (query: string) => { | ||
const baseAPI = useRuntimeConfig().public.content.api.baseURL | ||
|
||
// TODO: find a way to avoid fetching every time all the content | ||
const { data } = await useLazyFetch(`${baseAPI}/search`) | ||
|
||
// TODO: add a way to configure the search (using options from search?) | ||
const { results } = useFuse(query, | ||
data, | ||
{ | ||
fuseOptions: { | ||
keys: [ | ||
'title', | ||
'description', | ||
'keywords', | ||
'body' | ||
], | ||
ignoreLocation: true, | ||
threshold: 0, | ||
includeMatches: true, | ||
includeScore: true | ||
}, | ||
matchAllWhenSearchEmpty: true | ||
} | ||
) | ||
|
||
return results | ||
} |
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,47 @@ | ||
import { defineEventHandler } from 'h3' | ||
import { serverQueryContent } from '../storage' | ||
import { useRuntimeConfig } from '#imports' | ||
|
||
export default defineEventHandler(async (event) => { | ||
const { search } = useRuntimeConfig().public.content | ||
const isFullTextMode = search?.mode === 'full-text' | ||
|
||
const files = await serverQueryContent(event).find() | ||
|
||
const docs = await Promise.all( | ||
files | ||
.filter((file) => { | ||
return file?._extension === 'md' && | ||
file?._draft === false && file?._empty === false | ||
}) | ||
.map( | ||
async ({ _id: id, _path: path, _dir: dir, title = '', description = '', body = undefined, ...rest }) => { | ||
Check failure on line 18 in src/runtime/server/api/search.ts GitHub Actions / ci
|
||
// TODO: add configuration to choose which fields to index | ||
return { | ||
id, | ||
path, | ||
dir, | ||
title, | ||
description, | ||
keywords: body?.toc?.links.map(link => link?.text), | ||
body: isFullTextMode ? extractTextFromAst(body) : '' | ||
} | ||
} | ||
) | ||
) | ||
|
||
return docs | ||
}) | ||
|
||
function extractTextFromAst (node) { | ||
let text = '' | ||
if (node.type === 'text') { | ||
text += node.value | ||
} | ||
if (node.children) { | ||
for (const child of node.children) { | ||
text += ' ' + extractTextFromAst(child) | ||
} | ||
} | ||
return text | ||
} |