Skip to content

Commit

Permalink
feat: add query interface and export customize points for scripts (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Aug 11, 2024
1 parent 5cc1c42 commit 8142b3a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
8 changes: 4 additions & 4 deletions projects/hexo-renderer-typst/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const path = require('path');
const fs = require('fs');

const Compiler = require('./lib/compiler.cjs');
const compiler = new Compiler(hexo);
export const compiler = new Compiler(hexo);

const Renderer = require('./lib/renderer.cjs');
const renderer = new Renderer(hexo, compiler);
export const renderer = new Renderer(hexo, compiler);

const Processor = require('./lib/processor.cjs');
const processor = new Processor(hexo, compiler);
export const processor = new Processor(hexo, compiler);

const Watcher = require('./lib/watcher.cjs');
const watcher = new Watcher(hexo, compiler);
export const watcher = new Watcher(hexo, compiler);

function render(data, options) {
return renderer.render(data, options);
Expand Down
30 changes: 24 additions & 6 deletions projects/hexo-renderer-typst/lib/compiler.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class Compiler {
const fonts = path.resolve(this.baseDir, 'fonts');
const assetsFonts = path.resolve(this.baseDir, 'assets/fonts');
const assetFonts = path.resolve(this.baseDir, 'asset/fonts');
console.log('[typst] using fonts in', path.resolve(this.baseDir, '{fonts,assets/fonts,asset/fonts}'));
console.log(
'[typst] using fonts in',
path.resolve(this.baseDir, '{fonts,assets/fonts,asset/fonts}'),
);
const compileArgs = {
workspace: this.baseDir,
fontArgs: [
{ fontPaths: [fonts, assetsFonts, assetFonts] }
],
fontArgs: [{ fontPaths: [fonts, assetsFonts, assetFonts] }],
// todo: move this to session after we fixed the bug
inputs: { 'x-target': 'web' },
};
Expand All @@ -23,15 +24,32 @@ class Compiler {

title(path) {
return this.base.compile({
mainFilePath: path,
mainFilePath: path,
}).result.title;
}

vector(path) {
try {
return this.dyn.vector({
mainFilePath: path,
});
});
} catch (e) {
console.log(e);
throw e;
}
}

query(path, selector, field = undefined) {
try {
return this.base.query(
{
mainFilePath: path,
},
{
selector,
field,
},
);
} catch (e) {
console.log(e);
throw e;
Expand Down

0 comments on commit 8142b3a

Please sign in to comment.