mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
34 lines
774 B
TypeScript
34 lines
774 B
TypeScript
import { Asset, Bundler } from '../../bundler';
|
|
import { Observable } from '../../observable';
|
|
import { createEjs } from '../ejs';
|
|
import { latexToPdf } from './utils';
|
|
|
|
type LatexOptions = {
|
|
path: string;
|
|
bundler: Bundler;
|
|
template: ReturnType<typeof createEjs>;
|
|
data: Observable<any>;
|
|
};
|
|
const createLatex = ({ template, data, path, bundler }: LatexOptions) => {
|
|
const pdf = Observable.combine({
|
|
template,
|
|
data,
|
|
})
|
|
.pipe(async ({ template, data }) => template(data))
|
|
.pipe(async (latex) => {
|
|
const pdf = await latexToPdf(latex);
|
|
|
|
const asset: Asset = {
|
|
content: pdf,
|
|
};
|
|
return asset;
|
|
});
|
|
const url = bundler.register(`${path}.pdf`, pdf);
|
|
return {
|
|
url,
|
|
item: pdf,
|
|
};
|
|
};
|
|
|
|
export { createLatex };
|