lazy load html parser

fix license
This commit is contained in:
hzrd149 2023-11-13 13:03:12 -06:00
parent d758df1b8e
commit 79f45ca5b9
2 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2023 Talha Buğra Bulut
Copyright (c) 2023 hzrd149
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,6 @@
import { useAsync } from "react-use";
import extractMetaTags from "../lib/open-graph-scraper/extract";
import { fetchWithCorsFallback } from "../helpers/cors";
import { OgObjectInteral } from "../lib/open-graph-scraper/types";
import type { OgObjectInteral } from "../lib/open-graph-scraper/types";
const pageExtensions = [".html", ".php", "htm"];
@ -9,6 +8,8 @@ const openGraphDataCache = new Map<string, OgObjectInteral>();
export default function useOpenGraphData(url: URL) {
return useAsync(async () => {
const { default: extractMetaTags } = await import("../lib/open-graph-scraper/extract");
if (openGraphDataCache.has(url.toString())) return openGraphDataCache.get(url.toString());
const ext = url.pathname.match(/\.[\w+d]+$/)?.[0];