From d0f75f27c3dc81999abcdc7761b761d677ad8e12 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Wed, 16 Oct 2024 18:33:27 -0400 Subject: [PATCH] use webpack asset loaders --- docz/data/cli.js | 7 +++---- docz/data/desktop.js | 7 +++---- docz/data/engines.js | 7 +++---- docz/data/mobile.js | 7 +++---- docz/docusaurus.config.js | 1 + docz/package.json | 1 + docz/src/plugins/sheetjs-docusaurus/index.js | 20 +++++++++++++++++++ .../plugins/sheetjs-docusaurus/package.json | 8 ++++++++ .../sheetjs-docusaurus/sheetjs-loader.js | 9 +++++++++ 9 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 docz/src/plugins/sheetjs-docusaurus/index.js create mode 100644 docz/src/plugins/sheetjs-docusaurus/package.json create mode 100644 docz/src/plugins/sheetjs-docusaurus/sheetjs-loader.js diff --git a/docz/data/cli.js b/docz/data/cli.js index 21620e8..cb2282e 100644 --- a/docz/data/cli.js +++ b/docz/data/cli.js @@ -1,4 +1,3 @@ -import { read, utils } from 'xlsx'; import url from './cli.xls'; import React, { useEffect, useState } from 'react'; @@ -6,9 +5,9 @@ const FrameworkData = () => { const [fw, setFW] = useState(""); useEffect(() => { (async() => { - const wb = read(await (await fetch(url)).arrayBuffer(), { dense: true }); - setFW(utils.sheet_to_html(wb.Sheets["Frameworks"])); + const html = await (await fetch(url)).json(); + setFW(html["Frameworks"]); })(); }, []); - return (
); + return (

); }; export default FrameworkData; diff --git a/docz/data/desktop.js b/docz/data/desktop.js index 519b476..aab198b 100644 --- a/docz/data/desktop.js +++ b/docz/data/desktop.js @@ -1,4 +1,3 @@ -import { read, utils } from 'xlsx'; import url from './desktop.xls'; import React, { useEffect, useState } from 'react'; @@ -6,9 +5,9 @@ const FrameworkData = () => { const [fw, setFW] = useState(""); useEffect(() => { (async() => { - const wb = read(await (await fetch(url)).arrayBuffer(), { dense: true }); - setFW(utils.sheet_to_html(wb.Sheets["Frameworks"])); + const html = await (await fetch(url)).json(); + setFW(html["Frameworks"]); })(); }, []); - return (

); + return (

); }; export default FrameworkData; \ No newline at end of file diff --git a/docz/data/engines.js b/docz/data/engines.js index 7290e52..1a156be 100644 --- a/docz/data/engines.js +++ b/docz/data/engines.js @@ -1,4 +1,3 @@ -import { read, utils } from 'xlsx'; import url from './engines.xls'; import React, { useEffect, useState } from 'react'; @@ -7,9 +6,9 @@ const EngineData = () => { const [binding, setBinding] = useState(""); useEffect(() => { (async() => { - const wb = read(await (await fetch(url)).arrayBuffer(), { dense: true }); - setEngines(utils.sheet_to_html(wb.Sheets["Engines"])); - setBinding(utils.sheet_to_html(wb.Sheets["Bindings"])); + const html = await (await fetch(url)).json(); + setEngines(html["Engines"]); + setBinding(html["Bindings"]); })(); }, []); return ( <>

The following engines have been tested in their native languages:

diff --git a/docz/data/mobile.js b/docz/data/mobile.js index 7c129b0..e2e9a5b 100644 --- a/docz/data/mobile.js +++ b/docz/data/mobile.js @@ -1,4 +1,3 @@ -import { read, utils } from 'xlsx'; import url from './mobile.xls'; import React, { useEffect, useState } from 'react'; @@ -6,9 +5,9 @@ const FrameworkData = () => { const [fw, setFW] = useState(""); useEffect(() => { (async() => { - const wb = read(await (await fetch(url)).arrayBuffer(), { dense: true }); - setFW(utils.sheet_to_html(wb.Sheets["Frameworks"])); + const html = await (await fetch(url)).json(); + setFW(html["Frameworks"]); })(); }, []); - return (
); + return (

); }; export default FrameworkData; diff --git a/docz/docusaurus.config.js b/docz/docusaurus.config.js index 2c3ae08..a1514c1 100644 --- a/docz/docusaurus.config.js +++ b/docz/docusaurus.config.js @@ -208,6 +208,7 @@ const config = { }, ], plugins: [ + require.resolve("sheetjs-docusaurus"), require.resolve("@cmfcmf/docusaurus-search-local"), [ '@docusaurus/plugin-client-redirects', { redirects: [ diff --git a/docz/package.json b/docz/package.json index 15dc4b8..ceac66e 100644 --- a/docz/package.json +++ b/docz/package.json @@ -33,6 +33,7 @@ "react-dom": "18.2.0", "rehype-katex": "7.0.0", "remark-math": "6.0.0", + "sheetjs-docusaurus": "file:src/plugins/sheetjs-docusaurus", "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz" }, "devDependencies": { diff --git a/docz/src/plugins/sheetjs-docusaurus/index.js b/docz/src/plugins/sheetjs-docusaurus/index.js new file mode 100644 index 0000000..3d20b41 --- /dev/null +++ b/docz/src/plugins/sheetjs-docusaurus/index.js @@ -0,0 +1,20 @@ +/** @type {import('@docusaurus/types').PluginModule} */ +export default function SheetJSDocusaurus(context, opts) { + /** @type {import('@docusaurus/types').Plugin} */ + const plugin = { + name: "sheetjs-docusaurus", + configureWebpack(config, isServer, utils, content) { + return { + module: { + rules: [ + { + test: /\.xls/, + use: [ { loader: __dirname + '/sheetjs-loader' } ] + } + ] + } + } + } + }; + return plugin; +} \ No newline at end of file diff --git a/docz/src/plugins/sheetjs-docusaurus/package.json b/docz/src/plugins/sheetjs-docusaurus/package.json new file mode 100644 index 0000000..b4d9389 --- /dev/null +++ b/docz/src/plugins/sheetjs-docusaurus/package.json @@ -0,0 +1,8 @@ +{ + "name": "sheetjs-docusaurus", + "version": "0.0.0", + "private": true, + "dependencies": { + "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz" + } +} \ No newline at end of file diff --git a/docz/src/plugins/sheetjs-docusaurus/sheetjs-loader.js b/docz/src/plugins/sheetjs-docusaurus/sheetjs-loader.js new file mode 100644 index 0000000..652a2a8 --- /dev/null +++ b/docz/src/plugins/sheetjs-docusaurus/sheetjs-loader.js @@ -0,0 +1,9 @@ +const XLSX = require("xlsx"); + +function loader(content) { + const wb = XLSX.read(content); + const entries = wb.SheetNames.map(n => [n, XLSX.utils.sheet_to_html(wb.Sheets[n])]); + return JSON.stringify(Object.fromEntries(entries)); +} +loader.raw = true; +module.exports = loader; \ No newline at end of file