feat: added latex generation

This commit is contained in:
Morten Olsen
2022-03-29 23:01:49 +02:00
parent 90fdaeb406
commit d1d77ed915
68 changed files with 1506 additions and 290 deletions

View File

@@ -0,0 +1,35 @@
const withLatex = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
const {isServer, dev} = options;
let outputPath = '';
if (isServer && dev) {
outputPath = "../";
} else if (isServer) {
outputPath = "../../";
}
config.module.rules.push({
test: /\.tex.yml$/,
use: [{
loader: 'file-loader',
options: {
publicPath: `${nextConfig.assetPrefix || nextConfig.basePath || ''}/_next/static/images/`,
outputPath: `${outputPath}static/images/`,
name: "[name]-[hash].pdf",
esModule: nextConfig.esModule || false,
},
}, {
loader: require.resolve('./webpack.js'),
}],
});
if (typeof nextConfig.webpack === "function") {
return nextConfig.webpack(config, options);
}
return config;
},
});
}
module.exports = withLatex;

View File

@@ -0,0 +1,31 @@
require('reflect-metadata');
require('@babel/register')({
extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".ts"],
});
const latex = require("node-latex")
var Readable = require('stream').Readable
const { generateLatex } = require('../../../src/latex');
module.exports = function (source) {
var callback = this.async();
const location = this.resourcePath;
generateLatex(source, location)
.then((result) => {
const chunks = [];
const input = new Readable();
input.push(result);
input.push(null);
const latexStream = latex(input);
latexStream.on('data', (chunk) => {
chunks.push(Buffer.from(chunk));
})
latexStream.on('finish', () => {
const result = Buffer.concat(chunks);
callback(null, result);
})
latexStream.on('error', (err) => {
callback(err);
})
})
.catch(callback);
}