Skip to content

Commit

Permalink
🚑 dynamic import jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Mar 10, 2024
1 parent bc04e2e commit b421a66
Show file tree
Hide file tree
Showing 7 changed files with 8,744 additions and 2,635 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
npm install -f esbuild
- name: Package the extension
run: cd extensions/vscode && npx vsce package --yarn --target ${{ env.target }}
run: cd extensions/vscode && npx vsce package --target ${{ env.target }}

# 5. Upload the .vsix as an artifact
- uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
npm install -f esbuild
- name: Package the extension
run: cd extensions/vscode && npx vsce package --yarn --pre-release --target ${{ env.target }}
run: cd extensions/vscode && npx vsce package --pre-release --target ${{ env.target }}

# 5. Upload the .vsix as an artifact
- uses: actions/upload-artifact@v2
Expand Down
9 changes: 6 additions & 3 deletions core/indexing/docs/article.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Readability } from "@mozilla/readability";
import { JSDOM } from "jsdom";
import { Chunk } from "../..";
import { MAX_CHUNK_SIZE } from "../../llm/constants";
import { cleanFragment, cleanHeader } from "../chunk/markdown";
Expand Down Expand Up @@ -93,7 +92,10 @@ export function chunkArticle(articleResult: Article): Chunk[] {
return chunks;
}

function extractTitlesAndBodies(html: string): ArticleComponent[] {
async function extractTitlesAndBodies(
html: string,
): Promise<ArticleComponent[]> {
const { JSDOM } = await import("jsdom");
const dom = new JSDOM(html);
const document = dom.window.document;

Expand All @@ -120,6 +122,7 @@ export async function stringToArticle(
subpath: string,
): Promise<Article | undefined> {
try {
const { JSDOM } = await import("jsdom");
const dom = new JSDOM(htmlContent);
let reader = new Readability(dom.window.document);
let article = reader.parse();
Expand All @@ -128,7 +131,7 @@ export async function stringToArticle(
return undefined;
}

let article_components = extractTitlesAndBodies(article.content);
let article_components = await extractTitlesAndBodies(article.content);
return {
url,
subpath,
Expand Down
Loading

0 comments on commit b421a66

Please sign in to comment.