Skip to content

Commit

Permalink
chore: use biome to format code (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Dec 7, 2023
1 parent d8743fa commit 9d89b9e
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 23 deletions.
21 changes: 21 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"formatter": {
"lineWidth": 120,
"indentStyle": "space"
},
"files": {
"include": ["plugin-vitepress"],
"maxSize": 1000000000
},
"javascript": {
"formatter": {
"semicolons": "asNeeded",
"trailingComma": "none",
"quoteStyle":"single"
}
},
"linter": {
"enabled": false
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"build:plugin-match-highlight": "cd packages/plugin-match-highlight && npm run build",
"build:plugin-parsedoc": "cd packages/plugin-parsedoc && npm run build",
"format": "prettier -w packages",
"format:biome": "biome format --write ./packages",
"lint": "turbo lint",
"test": "turbo test",
"test:orama": "cd packages/orama && npm test",
Expand All @@ -29,6 +30,7 @@
"publish-packages": "node scripts/release.mjs"
},
"devDependencies": {
"@biomejs/biome": "1.4.1",
"@swc/cli": "^0.1.59",
"@swc/core": "^1.3.27",
"@types/node": "^18.11.18",
Expand Down
46 changes: 23 additions & 23 deletions packages/plugin-vitepress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const md = new MarkdownIt({
html: true
})

async function createOramaContentLoader (paths: string[], root: string) {
async function createOramaContentLoader(paths: string[], root: string) {
const contents = paths
.map(file => ({
.map((file) => ({
path: file.replace(root, '').replace('.md', ''),
html: md.render(readFileSync(file, 'utf-8'), '')
}))
Expand All @@ -47,38 +47,38 @@ async function createOramaContentLoader (paths: string[], root: string) {
return persist(db, 'json', 'browser')
}

function parseHTMLContent({ html, path }: { html: string, path: string }): Array<ParserResult> {
const dom = new JSDOM(html);
const document = dom.window.document;
function parseHTMLContent({ html, path }: { html: string; path: string }): Array<ParserResult> {
const dom = new JSDOM(html)
const document = dom.window.document

const sections: Array<ParserResult> = [];
const sections: Array<ParserResult> = []

const headers = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
headers.forEach(header => {
const sectionTitle = header.textContent!.trim();
const headerTag = header.tagName.toLowerCase();
let sectionContent = '';
const headers = document.querySelectorAll('h1, h2, h3, h4, h5, h6')
headers.forEach((header) => {
const sectionTitle = header.textContent!.trim()
const headerTag = header.tagName.toLowerCase()
let sectionContent = ''

let sibling = header.nextElementSibling;
let sibling = header.nextElementSibling
while (sibling && !['H1', 'H2', 'H3', 'H4', 'H5', 'H6'].includes(sibling.tagName)) {
sectionContent += sibling.textContent!.trim() + '\n';
sibling = sibling.nextElementSibling;
sectionContent += sibling.textContent!.trim() + '\n'
sibling = sibling.nextElementSibling
}

sections.push({
title: sectionTitle,
header: headerTag,
content: sectionContent,
path
});
});
})
})

return sections;
return sections
}

function formatForOrama(data: Array<ParserResult>): Array<OramaSchema> {
try {
const firstH1Header = data.find(section => section.header === 'h1')
const firstH1Header = data.find((section) => section.header === 'h1')

return data.map((res) => ({
title: res.title,
Expand All @@ -95,7 +95,7 @@ function formatForOrama(data: Array<ParserResult>): Array<OramaSchema> {

export function OramaPlugin(): Plugin {
let resolveConfig: any
const virtualModuleId = "virtual:search-data";
const virtualModuleId = 'virtual:search-data'
const resolvedVirtualModuleId = `\0${virtualModuleId}`

return {
Expand Down Expand Up @@ -132,19 +132,19 @@ export function OramaPlugin(): Plugin {
config: () => ({
resolve: {
alias: {
'./VPNavBarSearch.vue': new URL('./Search.vue', import.meta.url).pathname,
},
'./VPNavBarSearch.vue': new URL('./Search.vue', import.meta.url).pathname
}
}
}),

async resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
return resolvedVirtualModuleId
}
},

async load(this, id) {
if (id !== resolvedVirtualModuleId) return;
if (id !== resolvedVirtualModuleId) return

const root = resolveConfig.vitepress.root
const pages = resolveConfig.vitepress.pages.map((page: string) => `${root}/${page}`)
Expand Down
71 changes: 71 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d89b9e

Please sign in to comment.