Skip to content

Commit

Permalink
refa: load NJK by webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Myllaume committed Oct 12, 2024
1 parent c3c1b9f commit e60f46b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/models/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import path from 'node:path';
import nunjucks from 'nunjucks';
import lang from './lang.js';
import { fileURLToPath } from 'url';
import reportTemplate from '../../static/template/report.njk';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -38,7 +39,7 @@ class Report {
minute: 'numeric',
second: 'numeric',
});
return templateEngine.render('static/template/report.njk', {
return templateEngine.renderString(reportTemplate, {
lang: lang.flag,
date,
projectTitle,
Expand Down
3 changes: 2 additions & 1 deletion core/models/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import langPck from './lang.js';
import { fileURLToPath } from 'url';
import convertWikilinks from '../utils/convertWikilinks.js';
import convertQuotes from '../utils/convertQuotes.js';
import cosmoscopeTemplate from '../../static/template/cosmoscope.njk';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -248,7 +249,7 @@ class Template {
this.custom_css = fs.readFileSync(cssCustomPath, 'utf-8');
}

this.html = templateEngine.render('static/template/cosmoscope.njk', {
this.html = templateEngine.renderString(cosmoscopeTemplate, {
publishMode: this.params.has('publish') === true,
devMode: this.params.has('dev') === true,
canSaveRecords: this.config.canSaveRecords(),
Expand Down
4 changes: 4 additions & 0 deletions webpack-back.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default {
test: /\.ya?ml$/,
use: 'yaml-loader',
},
{
test: /\.njk$/,
type: 'asset/source',
},
],
},
plugins: [
Expand Down

0 comments on commit e60f46b

Please sign in to comment.