This commit is contained in:
SheetJS 2023-06-02 04:11:35 -04:00
parent 54a61c94bb
commit 768683e0fc
3 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,11 @@
// https://v3.nuxtjs.org/api/configuration/nuxt.config
import SheetJSModule from './sheetmodule'
export default defineNuxtConfig({
modules: ['@nuxt/content']
// @ts-ignore
telemetry: false,
modules: [
SheetJSModule,
'@nuxt/content'
],
content: {}
})

15
sheetformer.ts Normal file
View File

@ -0,0 +1,15 @@
// @ts-ignore
import { defineTransformer } from "@nuxt/content/transformers/utils";
import { read, utils } from "xlsx";
import { readFileSync } from "node:fs";
import { resolve } from 'node:path';
export default defineTransformer({
name: 'sheetformer',
extensions: ['.xlsx'],
parse (_id: string, rawContent: string) {
const wb = read(readFileSync(resolve("./content/" + _id.slice(8))));
const body = wb.SheetNames.map(name => ({ name, data: utils.sheet_to_json(wb.Sheets[name])}));
return { _id, body };
}
});

14
sheetmodule.ts Normal file
View File

@ -0,0 +1,14 @@
import { resolve } from 'path'
import { defineNuxtModule } from '@nuxt/kit'
export default defineNuxtModule({
setup (_options, nuxt) {
nuxt.options.nitro.externals = nuxt.options.nitro.externals || {}
nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || []
nuxt.options.nitro.externals.inline.push(resolve('./sheetmodule'))
// @ts-ignore
nuxt.hook('content:context', (contentContext) => {
contentContext.transformers.push(resolve('./sheetformer.ts'))
})
}
})